Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Unit test for factorial.py """
- import unittest
- import factorial
- class KnownValues(unittest.TestCase):
- knownValues = [(0, 1), (1, 1), (2, 2), (3, 6), (5, 120)]
- def testFactorialValues(self):
- """factorial should given known result with known input"""
- for number, fact in self.knownValues:
- result = factorial.factorial(number)
- self.assertEqual(fact, number)
- class FactorialBadInput(unittest.TestCase):
- def testNegativeNumber(self):
- """factorial should fail with negative numbers"""
- self.assertRaises(factorial.NegativeNumberError, factorial.factorial, -1)
- def testNotAnInteger(self):
- """factorial should fail with non-integers"""
- self.assertRaises(factorial.NotAnIntegerError, factorial.factorial, 1.4)
- if __name__ == "__main__":
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement