Introduction
Testing every possible input for a software program can take too much time and effort. We need a smart way to pick test cases that still catch most errors without checking everything.
Imagine you want to taste different flavors of ice cream, but there are hundreds of flavors. Instead of trying every single one, you group similar flavors like all chocolate types together and taste just one from each group to get a good idea.
┌─────────────────────────────┐ │ All possible inputs │ ├─────────────┬───────────────┤ │ Valid Inputs│ Invalid Inputs│ ├─────┬───────┴─────┬─────────┤ │Class│ Class 2 │ Class 3 │ │ 1 │ │ │ └─────┴─────────────┴─────────┘ ↓ ↓ Test case 1 Test case 2
def is_valid_age(age: int) -> bool: return 0 <= age <= 120 # Equivalence classes: # Class 1: Valid ages (0 to 120) # Class 2: Invalid ages (less than 0) # Class 3: Invalid ages (greater than 120) # Test cases from each class print(is_valid_age(25)) # Expected: True (valid) print(is_valid_age(-5)) # Expected: False (invalid) print(is_valid_age(130)) # Expected: False (invalid)