ch08, 09, 10: example files
This commit is contained in:
63
10-dp-1class-func/strategy_test.py
Normal file
63
10-dp-1class-func/strategy_test.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from typing import List
|
||||
|
||||
import pytest # type: ignore
|
||||
|
||||
from strategy import Customer, LineItem, Order
|
||||
from strategy import fidelity_promo, bulk_item_promo, large_order_promo
|
||||
|
||||
|
||||
@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() -> List[LineItem]:
|
||||
return [
|
||||
LineItem('banana', 4, 0.5),
|
||||
LineItem('apple', 10, 1.5),
|
||||
LineItem('watermellon', 5, 5.0),
|
||||
]
|
||||
|
||||
|
||||
def test_fidelity_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
|
||||
order = Order(customer_fidelity_0, cart_plain, fidelity_promo)
|
||||
assert order.total() == 42.0
|
||||
assert order.due() == 42.0
|
||||
|
||||
|
||||
def test_fidelity_promo_with_discount(customer_fidelity_1100, cart_plain) -> None:
|
||||
order = Order(customer_fidelity_1100, cart_plain, fidelity_promo)
|
||||
assert order.total() == 42.0
|
||||
assert order.due() == 39.9
|
||||
|
||||
|
||||
def test_bulk_item_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
|
||||
order = Order(customer_fidelity_0, cart_plain, bulk_item_promo)
|
||||
assert order.total() == 42.0
|
||||
assert order.due() == 42.0
|
||||
|
||||
|
||||
def test_bulk_item_promo_with_discount(customer_fidelity_0) -> None:
|
||||
cart = [LineItem('banana', 30, 0.5), LineItem('apple', 10, 1.5)]
|
||||
order = Order(customer_fidelity_0, cart, bulk_item_promo)
|
||||
assert order.total() == 30.0
|
||||
assert order.due() == 28.5
|
||||
|
||||
|
||||
def test_large_order_promo_no_discount(customer_fidelity_0, cart_plain) -> None:
|
||||
order = Order(customer_fidelity_0, cart_plain, large_order_promo)
|
||||
assert order.total() == 42.0
|
||||
assert order.due() == 42.0
|
||||
|
||||
|
||||
def test_large_order_promo_with_discount(customer_fidelity_0) -> None:
|
||||
cart = [LineItem(str(item_code), 1, 1.0) for item_code in range(10)]
|
||||
order = Order(customer_fidelity_0, cart, large_order_promo)
|
||||
assert order.total() == 10.0
|
||||
assert order.due() == 9.3
|
||||
Reference in New Issue
Block a user