Factorial with unittest
In this exercise, you will start using unittest to create basic tests for the factorial function. Since the library uses an object-oriented approach, the functions will be implemented as methods of a unittest.TestCase class. The unittest package has already been imported.
Deze oefening maakt deel uit van de cursus
Introduction to Testing in Python
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
def func_factorial(number):
if number < 0:
raise ValueError('Factorial is not defined for negative values')
factorial = 1
while number > 1:
factorial = factorial * number
number = number - 1
return factorial
class TestFactorial(unittest.TestCase):
def test_positives(self):
# Add the test for testing positives here
____