#format python """Example of Recursion and PyUnit and AssertiveProgramming and FunctionalProgramming """ import unittest def fact(aNum): assert aNum >= 1 and type(aNum) == int if aNum == 1: return 1 else: return aNum * fact(aNum-1) factFP = lambda n: n<=1 and 1 or factFP(n-1)*n class FactorialTest(unittest.TestCase): def test1(self): self.assertEquals(1, fact(1)) def test2(self): self.assertEquals(2, fact(2)) self.assertEquals(6, fact(3)) def testNegativeOrFloat(self): self.assertRaises(AssertionError, fact, -2) self.assertRaises(AssertionError, fact, 1.1) def testOtherTypes(self): self.assertRaises(AssertionError, fact, 'a') if __name__=='__main__': unittest.main(argv=('','-v'))