IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Introduction to Testing in Python

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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
        ____
Modifica ed esegui il codice