-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_checkout.py
50 lines (36 loc) · 1.73 KB
/
test_checkout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest
from index import checkout
def test_empty_basket_returns_0():
assert checkout('') == 0
single_items = [['A', 50], ['B', 30], ['C', 20], ['D', 15]]
@pytest.mark.parametrize('item_price', single_items)
def test_single_item_returns_price(item_price):
item, price = item_price
assert checkout(item) == price
multiple_items = [['ABCDA', 165], ['CBA', 100], ['DABCC', 135]]
@pytest.mark.parametrize('items_total', multiple_items)
def test_multiple_items_returns_total_price(items_total):
items, total = items_total
assert checkout(items) == total
single_a_discount_items = [['AAA', 130], ['ABACAD', 195], ['AAAA', 180]]
@pytest.mark.parametrize('items_total', single_a_discount_items)
def test_returns_total_price_with_one_a_discount(items_total):
items, total = items_total
assert checkout(items) == total
multiple_a_discount_items = [['AAAAAA', 260], ['ABAACAAAD', 325], ['AAAAAAAA', 360]]
@pytest.mark.parametrize('items_total', multiple_a_discount_items)
def test_returns_total_price_with_multiple_a_discounts(items_total):
items, total = items_total
assert checkout(items) == total
single_b_discount_items = [['BB', 45], ['BBB', 75], ['ABABCBD', 210]]
@pytest.mark.parametrize('items_total', single_b_discount_items)
def test_returns_total_price_with_one_b_discount(items_total):
items, total = items_total
assert checkout(items) == total
multiple_b_discount_items = [['BBBB', 90], ['BBBBBBB', 180], ['ABACBBDDBB', 270]]
@pytest.mark.parametrize('items_total', single_b_discount_items)
def test_returns_total_price_with_multiple_b_discounts(items_total):
items, total = items_total
assert checkout(items) == total
def test_returns_total_price_when_both_a_and_b_discounts_apply():
assert checkout('AAABB') == 175