updated from Atlas
This commit is contained in:
@@ -3,19 +3,20 @@
|
||||
# selecting best promotion from static list of functions
|
||||
|
||||
"""
|
||||
>>> from strategy import Customer, LineItem
|
||||
>>> joe = Customer('John Doe', 0)
|
||||
>>> ann = Customer('Ann Smith', 1100)
|
||||
>>> cart = [LineItem('banana', 4, .5),
|
||||
... LineItem('apple', 10, 1.5),
|
||||
... LineItem('watermelon', 5, 5.0)]
|
||||
>>> banana_cart = [LineItem('banana', 30, .5),
|
||||
... LineItem('apple', 10, 1.5)]
|
||||
>>> big_cart = [LineItem(str(item_code), 1, 1.0)
|
||||
>>> cart = [LineItem('banana', 4, Decimal('.5')),
|
||||
... LineItem('apple', 10, Decimal('1.5')),
|
||||
... LineItem('watermelon', 5, Decimal(5))]
|
||||
>>> banana_cart = [LineItem('banana', 30, Decimal('.5')),
|
||||
... LineItem('apple', 10, Decimal('1.5'))]
|
||||
>>> long_cart = [LineItem(str(item_code), 1, Decimal(1))
|
||||
... for item_code in range(10)]
|
||||
|
||||
# tag::STRATEGY_BEST_TESTS[]
|
||||
|
||||
>>> Order(joe, big_cart, best_promo) # <1>
|
||||
>>> Order(joe, long_cart, best_promo) # <1>
|
||||
<Order total: 10.00 due: 9.30>
|
||||
>>> Order(joe, banana_cart, best_promo) # <2>
|
||||
<Order total: 30.00 due: 28.50>
|
||||
@@ -25,7 +26,9 @@
|
||||
# end::STRATEGY_BEST_TESTS[]
|
||||
"""
|
||||
|
||||
from strategy import Customer, LineItem, Order
|
||||
from decimal import Decimal
|
||||
|
||||
from strategy import Order
|
||||
from strategy import fidelity_promo, bulk_item_promo, large_order_promo
|
||||
|
||||
# tag::STRATEGY_BEST[]
|
||||
@@ -33,9 +36,8 @@ from strategy import fidelity_promo, bulk_item_promo, large_order_promo
|
||||
promos = [fidelity_promo, bulk_item_promo, large_order_promo] # <1>
|
||||
|
||||
|
||||
def best_promo(order) -> float: # <2>
|
||||
"""Select best discount available
|
||||
"""
|
||||
def best_promo(order: Order) -> Decimal: # <2>
|
||||
"""Compute the best discount available"""
|
||||
return max(promo(order) for promo in promos) # <3>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user