From 8ac0df0c4235e665e75d1ac3e79a8f4f62e413f8 Mon Sep 17 00:00:00 2001 From: Tarcaye Date: Fri, 14 Apr 2023 11:51:00 +0200 Subject: [PATCH 1/2] [Python] Add promotion to basket --- python/test/basket_informations_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/basket_informations_test.py b/python/test/basket_informations_test.py index a823a84..e577cb2 100644 --- a/python/test/basket_informations_test.py +++ b/python/test/basket_informations_test.py @@ -10,5 +10,5 @@ def test_a_basket_should_cost_0_when_empty(self): self.assertEqual(self.basket.get_basket_price(False), 0) def test_1000_otherwise(self): - self.basket.add_product_to_basket("product", 1000) + self.basket.add_product_to_basket("product", 1000, False) self.assertEqual(self.basket.get_basket_price(False), 1000) \ No newline at end of file From d7f0d6fa893888f29e8b7e536484d56dfc1c6497 Mon Sep 17 00:00:00 2001 From: Thomas Carpaye Date: Fri, 14 Apr 2023 12:23:07 +0200 Subject: [PATCH 2/2] [Python] Add promotion to basket --- python/src/basket_informations.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/python/src/basket_informations.py b/python/src/basket_informations.py index bbcaebf..5d9f94a 100644 --- a/python/src/basket_informations.py +++ b/python/src/basket_informations.py @@ -2,13 +2,21 @@ class BasketInformations: # The product of the basket map = {} - def add_product_to_basket(self, product, price): - BasketInformations.map[product] = price + # The fact that the basket has promo code + code_de_promotion = False + + def add_product_to_basket(self, product, price, is_promo_code): + if is_promo_code: + BasketInformations.code_de_promotion = True + else: + BasketInformations.map[product] = price def get_basket_price(self, in_cents): v = 0 for s in BasketInformations.map.values(): v += s + if BasketInformations.code_de_promotion: + v -= 100 return v * 100 if in_cents else Long(v) def reset_basket(self):