diff --git a/checkout_supermarket.py b/checkout_supermarket.py new file mode 100644 index 0000000..7cdc3d6 --- /dev/null +++ b/checkout_supermarket.py @@ -0,0 +1,39 @@ +class CheckOut: + + def __init__(self, rules): + self._total = 0 + self.item_count = {} + self.rules = rules + + for i,v in rules.items(): + self.item_count[i] = 0 + + def total(self): + return self._total + + def scan(self, item): + price = self.get_price(item) + if price: + self._total += price + self.item_count[item] += 1 + self.apply_discount(item) + + def get_price(self, item): + item = self.rules.get(item) + if item: + return item.get('price') + return None + + def apply_discount(self, item): + count = self.item_count.get(item) + item_rule = self.rules.get(item) + discount_qtd = item_rule.get('discount_qtd') + + if discount_qtd and (count == discount_qtd): + item_price = item_rule.get('price') + discount_price = item_rule.get('discount_price') + discount = (discount_qtd * item_price) - discount_price + self._total -= discount + self.item_count[item] = 0 + + return \ No newline at end of file diff --git a/test_checkout_supermarket.py b/test_checkout_supermarket.py new file mode 100644 index 0000000..9c6034d --- /dev/null +++ b/test_checkout_supermarket.py @@ -0,0 +1,74 @@ +import checkout_supermarket +import pytest + +pricing_rules = { + 'A': {'price': 50, 'discount_qtd': 3, 'discount_price': 130}, + 'B': {'price': 30, 'discount_qtd': 2, 'discount_price': 45}, + 'C': {'price': 20}, + 'D': {'price': 15} +} + +def price(items): + co = checkout_supermarket.CheckOut(pricing_rules) + for item in items: + co.scan(item) + return co.total() + + +def test_totals(): + total = price('') + assert 0 == total + total = price('A') + assert 50 == total + total = price('AB') + assert 80 == total + total = price('CDBA') + assert 115 == total + + total = price('AA') + assert 100 == total + total = price('AAA') + assert 130 == total + total = price('AAAA') + assert 180 == total + total = price('AAAAA') + assert 230 == total + + total = price('BBBB') + assert 90 == total + total = price('AAAAAA') + assert 260 == total + + total = price('AAAB') + assert 160 == total + total = price('AAABB') + assert 175 == total + total = price('AAABBD') + assert 190 == total + total = price('DABABA') + assert 190 == total + +@pytest.fixture +def checkout(): + co = checkout_supermarket.CheckOut(pricing_rules) + return co + +def test_incremental(checkout): + co = checkout + + co.scan('') + assert 0 == co.total() + co.scan('A') + assert 50 == co.total() + co.scan('B') + assert 80 == co.total() + co.scan('A') + assert 130 == co.total() + co.scan('A') + assert 160 == co.total() + co.scan('B') + assert 175 == co.total() + co.scan('B') + assert 205 == co.total() + co.scan('B') + assert 220 == co.total() diff --git a/whatsapp_choose_wallpaper.feature b/whatsapp_choose_wallpaper.feature new file mode 100644 index 0000000..2fe45bc --- /dev/null +++ b/whatsapp_choose_wallpaper.feature @@ -0,0 +1,32 @@ +Feature: Choose a Whatsapp chat wallpaper from different options + Whatsapp allows the user to select different chat wallpapers. + User can select a chat wallpaper from Wallpaper Library, Solid Colors or Photos. + Also, to each option selected by the user, a preview must be shown to the user. + + Scenario: Select a wallpaper from Wallpaper Library + Given I have a WhatsApp account configured in my phone + When I select Whatsapp Setings + And I click on Chat Wallpaper + And I click on Wallpaper Library + And I chose a wallpaper image + And I click on Set on the preview shown + Then a new chat wallpaper must be applied + + Scenario: Select a wallpaper from Solid Colors + Given I have a WhatsApp account configured in my phone + When I select Whatsapp Setings + And I click on Chat Wallpaper + And I click on Solid Colors + And I chose a wallpaper image + And I click on Set on the preview shown + Then a new chat wallpaper must be applied + + Scenario: Select a wallpaper from Photos + Given I have a WhatsApp account configured in my phone + And I have at least one image in my gallery + When I select Whatsapp Setings + And I click on Chat Wallpaper + And I click on Photos + And I chose a wallpaper image + And I click on Set on the preview shown + Then a new chat wallpaper must be applied \ No newline at end of file diff --git a/whatsapp_select_image.feature b/whatsapp_select_image.feature new file mode 100644 index 0000000..96d419f --- /dev/null +++ b/whatsapp_select_image.feature @@ -0,0 +1,31 @@ +Feature: Select a whatsapp image + Whatsapp allows the user to select one or more images to be sent in a conversation. + User should be able to select from one to thirty images for each message sent. + + Scenario: Select only one image + Given I have a WhatsApp account configured in my phone + And I have at least one image in my gallery + And I have at least one whatsapp contact saved + When I select a contact to start a conversation + And I click on Gallery + Then I should be able to select 1 image + And the image that I chose must be selected + + Scenario: Select thirty images + Given I have a WhatsApp account configured in my phone + And I have at least 30 images in my gallery + And I have at least one whatsapp contact saved + When I select a contact to start a conversation + And I click on Gallery + Then I should be able to select 30 images + And all 30 images that I chose must be selected + + Scenario: Select more than thirty images + Given I have a WhatsApp account configured in my phone + And I have more than 30 images in my gallery + And I have at least one whatsapp contact saved + When I select a contact to start a conversation + And I click on Gallery + Then I should not be able to select 31 images + And a warning message must be displayed + And 30 images must remain selected \ No newline at end of file