updated from Atlas

This commit is contained in:
Luciano Ramalho
2021-08-07 00:44:01 -03:00
parent cbd13885fc
commit 01e717b60a
96 changed files with 580 additions and 1021 deletions

View File

@@ -1,4 +1,4 @@
from typing import List
from decimal import Decimal
import pytest # type: ignore
@@ -17,47 +17,50 @@ def customer_fidelity_1100() -> Customer:
@pytest.fixture
def cart_plain() -> List[LineItem]:
return [
LineItem('banana', 4, 0.5),
LineItem('apple', 10, 1.5),
LineItem('watermelon', 5, 5.0),
]
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, fidelity_promo)
assert order.total() == 42.0
assert order.due() == 42.0
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, fidelity_promo)
assert order.total() == 42.0
assert order.due() == 39.9
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, bulk_item_promo)
assert order.total() == 42.0
assert order.due() == 42.0
assert order.total() == 42
assert order.due() == 42
def test_bulk_item_promo_with_discount(customer_fidelity_0) -> None:
cart = [LineItem('banana', 30, 0.5), LineItem('apple', 10, 1.5)]
cart = [LineItem('banana', 30, Decimal('0.5')),
LineItem('apple', 10, Decimal('1.5'))]
order = Order(customer_fidelity_0, cart, bulk_item_promo)
assert order.total() == 30.0
assert order.due() == 28.5
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, large_order_promo)
assert order.total() == 42.0
assert order.due() == 42.0
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, 1.0) for item_code in range(10)]
cart = [LineItem(str(item_code), 1, Decimal(1))
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
assert order.total() == 10
assert order.due() == Decimal('9.3')