-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_performance.py
More file actions
53 lines (40 loc) · 1.28 KB
/
test_performance.py
File metadata and controls
53 lines (40 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pytest
from legacy_calculator import calculate_total, process_order
# Sample test data
SAMPLE_ITEMS = [
{"category": "electronics", "price": 1200},
{"category": "clothing", "price": 50},
{"category": "books", "price": 30},
]
def test_calculate_total_basic(benchmark):
"""Implement benchmark test for calculate_total."""
result = benchmark(calculate_total, SAMPLE_ITEMS, "SUMMER", "premium", True)
assert result > 0
def test_process_order_benchmark(benchmark):
"""Benchmark the process_order function."""
order = {
"items": SAMPLE_ITEMS,
"customer": {"type": "premium"},
"discount_code": "SUMMER",
"is_holiday": True,
}
result = benchmark(process_order, order)
assert result is not None
# Add more test cases for edge cases
def test_process_order_none():
assert process_order(None) is None
def test_process_order_empty_items():
order = {
"items": [],
"customer": {"type": "premium"},
"discount_code": "SUMMER",
"is_holiday": False,
}
assert process_order(order) == 0
def test_process_order_missing_customer():
order = {
"items": SAMPLE_ITEMS,
"discount_code": "SUMMER",
"is_holiday": False,
}
assert process_order(order) is None