शुरू करेंमुफ़्त में शुरू करें

unittest के साथ फैक्टोरियल

इस अभ्यास में, आप unittest का उपयोग करके factorial फंक्शन के लिए बेसिक टेस्ट लिखना शुरू करेंगे। चूँकि यह लाइब्रेरी object-oriented अप्रोच अपनाती है, इसलिए फंक्शन unittest.TestCase क्लास की methods के रूप में इम्प्लीमेंट किए जाएँगे। unittest पैकेज पहले से इम्पोर्ट किया गया है।

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Testing का परिचय

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

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
        ____
कोड संपादित करें और चलाएँ