def test_multibuy_eight_item_buy_5_2_free(self): '''Correct line total for item with 8 quantity (buy 5 get 2 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 5, 2) cartitem = CartItem('apple', 8) self.assertEqual(multibuy_apples.calculate_line_total( cartitem, product_store), Decimal('0.90'))
def test_bogof_one_item_six_quantity(self): '''Correct line total for item with 6 quantity.''' product_store = self._create_product_store() bogof_apples = MultiBuyOffer('apple', 1, 1) cartitem = CartItem('apple', 6) self.assertEqual(bogof_apples.calculate_line_total( cartitem, product_store), Decimal('0.45'))
def test_multibuy_seven_item_buy_2_1_free(self): '''Correct line total for item with 7 quantity (buy 2 get 1 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 2, 1) cartitem = CartItem('apple', 7) self.assertEqual(multibuy_apples.calculate_line_total( cartitem, product_store), Decimal('0.75'))
def test_bogof_one_item_six_quantity(self): '''Correct line total for item with 6 quantity.''' product_store = self._create_product_store() bogof_apples = MultiBuyOffer('apple', 1, 1) cartitem = CartItem('apple', 6) self.assertEqual( round(bogof_apples.calculate_line_total(cartitem, product_store), 2), float('0.45'))
def test_bogof_one_item_two_quantity(self): """ Buy one get one free correct line total for item with 2 quantity. """ product_store = self._create_product_store() bogof_blueberries = MultiBuyOffer("blueberries", 1, 1) basketitem = BasketItem("blueberries", 2) self.assertEqual(bogof_blueberries.calculate_line_total(basketitem, product_store), Decimal("2.00"))
def test_multibuy_one_item_buy_2_1_free(self): """ Buy two get one free correct line total for item with 1 quantity. """ product_store = self._create_product_store() bogof_blueberries = MultiBuyOffer("blueberries", 2, 1) basketitem = BasketItem("blueberries") self.assertEqual(bogof_blueberries.calculate_line_total(basketitem, product_store), Decimal("2.00"))
def test_multibuy_eight_item_buy_5_2_free(self): '''Correct line total for item with 8 quantity (buy 5 get 2 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 5, 2) cartitem = CartItem('apple', 8) self.assertEqual( multibuy_apples.calculate_line_total(cartitem, product_store), Decimal('0.90'))
def test_multibuy_seven_item_buy_2_1_free(self): '''Correct line total for item with 7 quantity (buy 2 get 1 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 2, 1) cartitem = CartItem('apple', 7) self.assertEqual( multibuy_apples.calculate_line_total(cartitem, product_store), Decimal('0.75'))
def test_bogof_one_item_five_quantity(self): '''Correct line total for item with 5 quantity.''' product_store = self._create_product_store() bogof_apples = MultiBuyOffer('apple', 1, 1) cartitem = CartItem('apple', 5) self.assertEqual( bogof_apples.calculate_line_total(cartitem, product_store), Decimal('0.45'))
def test_multibuy_seven_item_buy_5_2_free(self): '''Correct line total for item with 7 quantity (buy 5 get 2 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 5, 2) cartitem = CartItem('apple', 7) self.assertEqual( round( multibuy_apples.calculate_line_total(cartitem, product_store), 2), float('0.75'))
def test_multibuy_six_item_buy_2_1_free(self): '''Correct line total for item with 6 quantity (buy 2 get 1 free).''' product_store = self._create_product_store() multibuy_apples = MultiBuyOffer('apple', 2, 1) cartitem = CartItem('apple', 6) self.assertEqual( round( multibuy_apples.calculate_line_total(cartitem, product_store), 2), float('0.60'))
def test_get_total_with_one_offer(self): '''Cart get_total returns correct value with a bogof offer applied.''' product_store = self._create_product_store() bogof_kitkat = MultiBuyOffer('kitkat', 1, 1) cart = Cart(product_store) cart.add('kitkat', 2) cart.add('apple') self.assertEqual(cart.get_total(offers=[bogof_kitkat]), float('0.85'))
def test_get_total_with_one_offer(self): '''Cart get_total returns correct value with a bogof offer applied.''' product_store = self._create_product_store() bogof_strawberries = MultiBuyOffer('strawberries', 1, 1) cart = Cart(product_store) cart.add('strawberries', 2) cart.add('apple') self.assertEqual(cart.get_total(offers=[bogof_strawberries]), Decimal('2.15'))
def test_get_total_with_one_offer(self): """ Basket get_total returns correct value with a bogof offer applied. """ product_store = self._create_product_store() bogof_blueberries = MultiBuyOffer("blueberries", 1, 1) basket = Basket(product_store) basket.add("blueberries", 2) basket.add("fish") self.assertEqual(basket.get_total(offers=[bogof_blueberries]), Decimal('5.20'))
def test_get_total_with_two_offers_on_same_target(self): '''Cart get_total returns cheapest total when two offers are applicable for the same target.''' product_store = self._create_product_store() bogof_kitkat = MultiBuyOffer('kitkat', 1, 1) kitkat_apple_20_discount = DependentDiscountOffer( 'kitkat', 'apple', float('0.2')) cart = Cart(product_store) cart.add('kitkat', 2) cart.add('apple') self.assertEqual( cart.get_total(offers=[bogof_kitkat, kitkat_apple_20_discount]), float('0.85'))
def test_get_total_with_two_offers_on_same_target(self): '''Cart get_total returns cheapest total when two offers are applicable for the same target.''' product_store = self._create_product_store() bogof_strawberries = MultiBuyOffer('strawberries', 1, 1) strawberries_apple_20_discount = DependentDiscountOffer( 'strawberries', 'apple', Decimal('0.2')) cart = Cart(product_store) cart.add('strawberries', 2) cart.add('apple') self.assertEqual( cart.get_total( offers=[bogof_strawberries, strawberries_apple_20_discount]), Decimal('2.15'))