forked from Berelarsenp/class-5-advanced-collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
206 lines (181 loc) · 4.45 KB
/
tests.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
from data import products_string
from step_0 import simple_add
from step_1 import transform_products_to_list
from step_2 import group_products_by_customer
from step_3 import group_products_by_customer_and_invoice
from step_4 import calculate_total_per_invoices
def test_step_0_warmup():
assert simple_add(10, 5) == 15
assert simple_add(9, -2) == 7
def test_step_1_products_string_to_list():
products_list = transform_products_to_list(products_string)
assert type(products_list) == list
assert len(products_list) == 50
product_1 = products_list[0]
assert product_1 == [
'536365',
'85123A',
'WHITE HANGING HEART T-LIGHT HOLDER',
'6',
'12/1/10 08:26',
'2.55',
'17850',
'United Kingdom']
def test_step_2_group_products_by_customer():
products = group_products_by_customer(products_string)
assert type(products) == dict
assert len(products) == 4 # 4 customers
customer_1 = products['17850']
assert type(customer_1) == list
assert len(customer_1) == 12
customer_1[0] == [
'536365',
'85123A',
'WHITE HANGING HEART T-LIGHT HOLDER',
'6',
'12/1/10 08:26',
'2.55',
'17850',
'United Kingdom']
assert customer_1[1] == [
"536365",
"71053",
"WHITE METAL LANTERN",
"6",
"12/1/10 08:26",
"3.39",
"17850",
"United Kingdom"
]
customer_2 = products['13047']
assert len(customer_2) == 17
assert customer_2[0] == [
"536367",
"84879",
"ASSORTED COLOUR BIRD ORNAMENT",
"32",
"12/1/10 08:34",
"1.69",
"13047",
"United Kingdom"
]
assert customer_2[-1] == [
"536369",
"21756",
"BATH BUILDING BLOCK WORD",
"3",
"12/1/10 08:35",
"5.95",
"13047",
"United Kingdom"
]
def test_step_3_group_by_customer_and_invoice():
products = group_products_by_customer_and_invoice(products_string)
assert type(products) == dict
assert len(products) == 4 # 4 customers
customer_1 = products['17850']
assert type(customer_1) == dict
assert len(customer_1) == 4
# Invoice: 536365
invoice = customer_1['536365']
assert len(invoice) == 7
assert invoice[0] == [
"536365",
"85123A",
"WHITE HANGING HEART T-LIGHT HOLDER",
"6",
"12/1/10 08:26",
"2.55",
"17850",
"United Kingdom"
]
assert invoice[-1] == [
"536365",
"21730",
"GLASS STAR FROSTED T-LIGHT HOLDER",
"6",
"12/1/10 08:26",
"4.25",
"17850",
"United Kingdom"
]
# Invoice: 536366
invoice = customer_1['536366']
assert len(invoice) == 2
assert invoice[0] == [
"536366",
"22633",
"HAND WARMER UNION JACK",
"6",
"12/1/10 08:28",
"1.85",
"17850",
"United Kingdom"
]
assert invoice[1] == [
"536366",
"22632",
"HAND WARMER RED POLKA DOT",
"6",
"12/1/10 08:28",
"1.85",
"17850",
"United Kingdom"
]
# Invoice: 536372
invoice = customer_1['536372']
assert len(invoice) == 2
assert invoice[0] == [
"536372",
"22632",
"HAND WARMER RED POLKA DOT",
"6",
"12/1/10 09:01",
"1.85",
"17850",
"United Kingdom"
]
assert invoice[1] == [
"536372",
"22633",
"HAND WARMER UNION JACK",
"6",
"12/1/10 09:01",
"1.85",
"17850",
"United Kingdom"
]
# Invoice: 536373
invoice = customer_1['536373']
assert len(invoice) == 1
assert invoice[0] == [
"536373",
"85123A",
"WHITE HANGING HEART T-LIGHT HOLDER",
"6",
"12/1/10 09:02",
"2.55",
"17850",
"United Kingdom"
]
def test_step_4_calculate_totals():
products = calculate_total_per_invoices(products_string)
assert products == {
'17850': {
'536365': 139.12,
'536366': 22.20,
'536372': 22.20,
'536373': 15.30,
},
'13047': {
'536367': 278.73,
'536368': 70.05,
'536369': 17.85,
},
'12583': {
'536370': 855.86
},
'13748': {
'536371': 204
}
}