Objective
Create a Python program that works as a mini test bench: define three functions and automatically check a list of test cases.
Instructions
- Define
is_palindrome(text)(case-insensitive comparison),factorial(n)(raisesValueErrorifnis negative) andgcd(a, b)(Euclid's algorithm). - Read an integer
nand thennlines with the formatfunction arguments... expected, wherefunctionispalindromo,factorialormcd, andexpectedis the expected result written asstr()shows it (for exampleTrueor120). - For each test, show
Test k: OKif the result matches,Test k: FAIL (got X)if it does not, orTest k: ERROR (ExceptionType)if the function raises an exception (with its class name). - Finish with
Passed: p of n.
4
palindromo Ana True
factorial 5 120
mcd 12 18 5
factorial -1 1
Test 1: OK
Test 2: OK
Test 3: FAIL (got 6)
Test 4: ERROR (ValueError)
Passed: 2 of 4
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise