-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_correctness.py
More file actions
33 lines (29 loc) · 1.28 KB
/
test_correctness.py
File metadata and controls
33 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pytest
from legacy_calculator import calculate_total as legacy_calc
from refactored_calculator import calculate_total as refactored_calc
TEST_CASES = [
# (items, discount_code, customer_type, is_holiday)
([{"category": "electronics", "price": 1200}], None, "premium", True),
([{"category": "clothing", "price": 50}], "SUMMER", "regular", False),
([{"category": "books", "price": 30}], "VIP20", "premium", False),
([{"category": "electronics", "price": 800}], None, "regular", False),
([{"category": "books", "price": 100}], None, "premium", False),
(
[
{"category": "electronics", "price": 1200},
{"category": "clothing", "price": 50},
{"category": "books", "price": 30},
],
"SUMMER",
"premium",
True,
),
]
@pytest.mark.parametrize("items,discount,customer,holiday", TEST_CASES)
def test_refactored_matches_legacy(items, discount, customer, holiday):
"""Verify refactored code produces identical results."""
legacy_result = legacy_calc(items, discount, customer, holiday)
refactored_result = refactored_calc(items, discount, customer, holiday)
assert abs(legacy_result - refactored_result) < 0.01, (
f"Results differ: {legacy_result} vs {refactored_result}"
)