-
Notifications
You must be signed in to change notification settings - Fork 959
/
classic_strategy_test.py
65 lines (45 loc) · 2.03 KB
/
classic_strategy_test.py
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
54
55
56
57
58
59
60
61
62
63
64
65
from decimal import Decimal
import pytest # type: ignore
from classic_strategy import Customer, LineItem, Order
from classic_strategy import FidelityPromo, BulkItemPromo, LargeOrderPromo
@pytest.fixture
def customer_fidelity_0() -> Customer:
return Customer('John Doe', 0)
@pytest.fixture
def customer_fidelity_1100() -> Customer:
return Customer('Ann Smith', 1100)
@pytest.fixture
def cart_plain() -> tuple[LineItem, ...]:
return (
LineItem('banana', 4, Decimal('0.5')),
LineItem('apple', 10, Decimal('1.5')),
LineItem('watermelon', 5, Decimal('5.0')),
)
def test_fidelity_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
order = Order(customer_fidelity_0, cart_plain, FidelityPromo())
assert order.total() == 42
assert order.due() == 42
def test_fidelity_promo_with_discount(customer_fidelity_1100, cart_plain) -> None:
order = Order(customer_fidelity_1100, cart_plain, FidelityPromo())
assert order.total() == 42
assert order.due() == Decimal('39.9')
def test_bulk_item_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
order = Order(customer_fidelity_0, cart_plain, BulkItemPromo())
assert order.total() == 42
assert order.due() == 42
def test_bulk_item_promo_with_discount(customer_fidelity_0) -> None:
cart = [LineItem('banana', 30, Decimal('0.5')),
LineItem('apple', 10, Decimal('1.5'))]
order = Order(customer_fidelity_0, cart, BulkItemPromo())
assert order.total() == 30
assert order.due() == Decimal('28.5')
def test_large_order_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
order = Order(customer_fidelity_0, cart_plain, LargeOrderPromo())
assert order.total() == 42
assert order.due() == 42
def test_large_order_promo_with_discount(customer_fidelity_0) -> None:
cart = [LineItem(str(item_code), 1, Decimal(1))
for item_code in range(10)]
order = Order(customer_fidelity_0, cart, LargeOrderPromo())
assert order.total() == 10
assert order.due() == Decimal('9.3')