Test Overview
This test checks a function that calculates discounts based on complex rules. It verifies that the function correctly applies multiple conditions, showing how advanced patterns help manage real-world complexity.
This test checks a function that calculates discounts based on complex rules. It verifies that the function correctly applies multiple conditions, showing how advanced patterns help manage real-world complexity.
import pytest def calculate_discount(price, customer_type, is_holiday): if price <= 0: return 0 if customer_type == 'VIP' and is_holiday: return price * 0.3 elif customer_type == 'VIP': return price * 0.2 elif is_holiday: return price * 0.1 else: return 0 def test_calculate_discount(): # VIP customer on holiday assert calculate_discount(100, 'VIP', True) == 30 # VIP customer not on holiday assert calculate_discount(100, 'VIP', False) == 20 # Regular customer on holiday assert calculate_discount(100, 'Regular', True) == 10 # Regular customer not on holiday assert calculate_discount(100, 'Regular', False) == 0 # Zero price assert calculate_discount(0, 'VIP', True) == 0 # Negative price assert calculate_discount(-50, 'VIP', True) == 0
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Calls calculate_discount(100, 'VIP', True) | Function evaluates conditions for VIP customer on holiday | Return value equals 30 | PASS |
| 3 | Calls calculate_discount(100, 'VIP', False) | Function evaluates conditions for VIP customer not on holiday | Return value equals 20 | PASS |
| 4 | Calls calculate_discount(100, 'Regular', True) | Function evaluates conditions for regular customer on holiday | Return value equals 10 | PASS |
| 5 | Calls calculate_discount(100, 'Regular', False) | Function evaluates conditions for regular customer not on holiday | Return value equals 0 | PASS |
| 6 | Calls calculate_discount(0, 'VIP', True) | Function evaluates zero price case | Return value equals 0 | PASS |
| 7 | Calls calculate_discount(-50, 'VIP', True) | Function evaluates negative price case | Return value equals 0 | PASS |
| 8 | Test ends | All assertions passed | - | PASS |