Created
May 22, 2011 01:51
-
-
Save poochin/985090 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import unittest | |
| class TestCombination(unittest.TestCase): | |
| ''' to check combi function ''' | |
| def setUp(self): | |
| pass | |
| def testcombi(self): | |
| self.assertEqual(combi(2, 0), 1) | |
| self.assertEqual(combi(3, 1), 3) | |
| self.assertEqual(combi(4, 2), 6) | |
| self.assertEqual(combi(5, 3), 10) | |
| self.assertEqual(combi(6, 4), 15) | |
| def combi(n, r): | |
| if n < 0 or r < 0: | |
| return False | |
| if n == 0 or r == 0: | |
| return 1 | |
| if n == r: | |
| return 1 | |
| return ((n - r + 1) * combi(n, r - 1)) / r | |
| def main(): | |
| unittest.main() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment