Skip to content

Instantly share code, notes, and snippets.

@poochin
Created May 22, 2011 01:51
Show Gist options
  • Select an option

  • Save poochin/985090 to your computer and use it in GitHub Desktop.

Select an option

Save poochin/985090 to your computer and use it in GitHub Desktop.
#!/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