Test Overview
This test simulates a white-box testing scenario where the tester checks the internal logic of a simple function. It verifies that the function behaves correctly for given inputs by examining its code paths.
This test simulates a white-box testing scenario where the tester checks the internal logic of a simple function. It verifies that the function behaves correctly for given inputs by examining its code paths.
import unittest # Function to test: returns True if number is even, else False def is_even(num): if num % 2 == 0: return True else: return False class TestIsEven(unittest.TestCase): def test_even_number(self): self.assertTrue(is_even(4)) def test_odd_number(self): self.assertFalse(is_even(5)) if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, test cases loaded | — | PASS |
| 2 | Calls is_even(4) | Function executes with input 4 | Checks if 4 % 2 == 0, returns True | PASS |
| 3 | Asserts that is_even(4) returns True | Assertion compares returned value True with expected True | assertTrue passes | PASS |
| 4 | Calls is_even(5) | Function executes with input 5 | Checks if 5 % 2 == 0, returns False | PASS |
| 5 | Asserts that is_even(5) returns False | Assertion compares returned value False with expected False | assertFalse passes | PASS |
| 6 | Test ends | All test cases executed successfully | — | PASS |
def is_even(n):
if n % 2 == 0:
return True
else:
return False
# Test case
assert is_even(3) == False
assert is_even(4) == True
What is the result of running this test case?def calculate_discount(price):
if price > 100:
return price * 0.9
else:
return price * 0.95
# Test
assert calculate_discount(100) == 90What is the problem with this test?def classify_number(x):
if x > 0:
if x % 2 == 0:
return 'Positive even'
else:
return 'Positive odd'
elif x < 0:
return 'Negative'
else:
return 'Zero'Which set of test inputs covers all branches?Pass the test and this pattern moves unknown