def test_due_joe_bulk_item_promo(self): """test to verify the return of the method due""" joe = Customer('John Doe', 0) cart = [LineItem('banana', 30, .5), LineItem('apple', 10, 1.5)] order = Order(joe, cart, BulkItemPromo()) self.assertEqual(order.due(), 28.5)
def test_due_joe_fidelity_promo(self): """test to verify the return of the method due""" joe = Customer('John Doe', 0) cart = [LineItem('banana', 4, .5), LineItem('apple', 10, 1.5)] order = Order(joe, cart, FidelityPromo()) self.assertEqual(order.due(), 17.0)
def test_fidelity_promo(): cart = [ LineItem('banana', 4, .5), LineItem('apple', 10, 1.5), LineItem('watermellon', 5, 5.0) ] assert repr(Order(joe, cart, FidelityPromo())) == '<Order total: 42.00 due: 42.00>' assert repr(Order(ann, cart, FidelityPromo())) == '<Order total: 42.00 due: 39.90>'
def test_due_ana_fideliy_promo(self): """test to verify the return of the method due""" ana = Customer('Ana Smith', 1100) cart = [ LineItem('banana', 4, .5), LineItem('apple', 10, 1.5), LineItem('watermellon', 5, 5.0) ] order = Order(ana, cart, FidelityPromo()) self.assertEqual(order.due(), 39.9)
def test_total_ana_bulk_item_promo(self): """test to verify the return of the method total""" ana = Customer('Ana Smith', 1100) cart = [ LineItem('banana', 4, .5), LineItem('apple', 10, 1.5), LineItem('watermellon', 20, 5.0) ] order = Order(ana, cart, BulkItemPromo()) self.assertEqual(order.total(), 117.0)
def test_total_jhon(self): """this test will verify if the method total will return the correct response""" obj = LineItem('banana', 4, .5) response = obj.total() self.assertEqual(response, 2.0)
def test_total_joe_bulk_item_promo_long_order(self): """test to verify the return of the method total""" joe = Customer('John Doe', 0) cart = [LineItem(str(item_code), 1, 1.0) for item_code in range(10)] order = Order(joe, cart, BulkItemPromo()) self.assertEqual(order.total(), 10.0)
def test_total_ana(self): """this test will verify if the method total will return the correct response""" obj = LineItem('apple', 10, 1.5) response = obj.total() self.assertEqual(response, 15.0)
def test_due_joe_large_order_promo_with_long_order(self): """test to verify the return of the method due""" joe = Customer('John Doe', 0) cart = [LineItem(str(item_code), 1, 1.0) for item_code in range(10)] order = Order(joe, cart, LargeOrderPromo()) self.assertEqual(order.due(), 9.3)
"""10% discount for each LineItem with 20 or more units""" discount = 0 for item in order.cart: if item.quantity >= 20: discount += item.total() * .1 return discount def large_order_promo(order): """7% discount for orders with 10 or more distinct items""" distinct_items = {item.product for item in order.cart} if len(distinct_items) >= 10: return order.total() * .07 return 0 joe = Customer('John Doe', 0) ann = Customer('Ann Smith', 1100) cart = [LineItem('banana', 4, .5), LineItem('apple', 10, 1.5), LineItem('watermellon', 5, 5.0)] print(Order(joe, cart, fidelity_promo)) print(Order(ann, cart, fidelity_promo)) banana_cart = [LineItem('banana', 30, .5), LineItem('apple', 10, 1.5)] print(Order(joe, banana_cart, bulk_item_promo)) long_order = [LineItem(str(item_code), 1, 1.0) for item_code in range(10)] print(Order(joe, long_order, large_order_promo)) print(Order(joe, cart, large_order_promo))
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, LargeOrderPromo()) assert order.total() == 10.0 assert order.due() == 9.3
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, BulkItemPromo()) assert order.total() == 30.0 assert order.due() == 28.5
def cart_plain() -> List[LineItem]: return [ LineItem('banana', 4, 0.5), LineItem('apple', 10, 1.5), LineItem('watermelon', 5, 5.0), ]
def test_single_item_order(): cart = [LineItem('banana', 4, .5)] assert repr(Order(joe, cart, FidelityPromo())) == '<Order total: 2.00 due: 2.00>'
def test_large_order_promo(): long_order = [LineItem(str(item_code), 1, 1.0) for item_code in range(10)] assert repr(Order(joe, long_order, LargeOrderPromo())) == '<Order total: 10.00 due: 9.30>'
def test_bulk_item_promo(): banana_cart = [LineItem('banana', 30, .5), LineItem('apple', 10, 1.5)] assert repr(Order(joe, banana_cart, BulkItemPromo())) == '<Order total: 30.00 due: 28.50>'