-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_game_model.py
300 lines (259 loc) · 8.3 KB
/
test_game_model.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
"""
Unit tests for game_model class.
"""
import pytest
import game_model as gmo
def check_check_order_incomplete():
"""
Check that an incomplete order is correctly identified.
Returns:
True if check_order correctly identifies the pizza as being incomplete.
"""
maximum = 4
order = gmo.OrderStatus(maximum)
pizza_status = {
"sauce": 0,
"cheese": 0,
"pepperoni": 0,
"basil": 0,
"mushroom": 0,
}
return not order.check_order(pizza_status)
def check_check_order_complete():
"""
Check that a complete order is correctly identified.
Returns:
True if check_order correctly identifies the pizza as being complete.
"""
maximum = 4
order = gmo.OrderStatus(maximum)
pizza_status = {
"sauce": maximum,
"cheese": maximum,
"pepperoni": maximum,
"basil": maximum,
"mushroom": maximum,
}
return order.check_order(pizza_status)
def check_access_order():
"""
Check that an order can be accessed as a dictionary outside of OrderStatus.
Returns:
True if order.order_dict is a dictionary, False otherwise.
"""
order = gmo.OrderStatus(1)
return isinstance(order.order_dict, dict)
def check_get_total_toppings():
"""
Check that a call to total toppings returns an int greater than 0.
Returns:
True if a call to total toppings returns an int greater than 0, false
otherwise.
"""
order = gmo.OrderStatus(1)
return order.get_total_toppings() != 0
@pytest.mark.parametrize(
"func",
[
check_check_order_incomplete,
check_check_order_complete,
check_access_order,
check_get_total_toppings,
],
)
def test_OrderStatus(func): # pylint: disable=invalid-name
"""
Check that the OrderStatus class in game_model is working as intended
Args:
func: A function that returns a boolean, used to test various
functionality of the OrderStatus class.
"""
assert func()
def check_access_status():
"""
Check that a pizza's toppings can be accessed as a dictionary.
Returns:
True if pizza.status is a dictionary, False otherwise.
"""
pizza = gmo.PizzaStatus()
return isinstance(pizza.status, dict)
def check_add_topping():
"""
Checks that the add_topping function in PizzaStatus is working as intended.
Returns:
True if add toppings correctly increases a specific topping on a pizza
by 1.
"""
pizza = gmo.PizzaStatus()
test_pizza = {
"sauce": 1,
"cheese": 2,
"pepperoni": 0,
"basil": 0,
"mushroom": 1,
}
pizza.add_topping("sauce")
pizza.add_topping("cheese")
pizza.add_topping("cheese")
pizza.add_topping("mushroom")
return test_pizza == pizza.status
def check_clear_pizza():
"""
Checks that the clear_topping function removes every topping from a pizza.
Returns:
True if a call to clear_topping on a PizzaStatus instance results in
__current_toppings being a dictionary with every value equaling zero.
"""
pizza = gmo.PizzaStatus()
pizza.add_topping("sauce")
pizza.add_topping("cheese")
pizza.add_topping("cheese")
pizza.add_topping("mushroom")
pizza.clear_pizza()
count = 0
for num in pizza.status.values():
count += num
return count == 0
def check_update_postion_right_side():
"""
Checks that the update_position function stops pizzas from leaving screen.
Returns:
True if a call to update_position with a big positive x_update value
results in new_pos being a list equal to [328, 150].
"""
pizza = gmo.PizzaStatus()
pizza.update_position(1000)
return pizza.position == [328, 150]
def check_update_postion_left_side():
"""
Checks that the update_position function stops pizzas from leaving screen.
Returns:
True if a call to update_position with a big negative x_update value
results in new_pos being a list equal to [-5, 150].
"""
pizza = gmo.PizzaStatus()
pizza.update_position(-1000)
return pizza.position == [-5, 150]
@pytest.mark.parametrize(
"func",
[
check_access_status,
check_add_topping,
check_update_postion_right_side,
check_update_postion_left_side,
check_clear_pizza,
],
)
def test_PizzaStatus(func): # pylint: disable=invalid-name
"""
Check that the PizzaStatus class in game_model is working as intended.
Args:
func: A function that returns a boolean, used to test various
functionality of the PizzaStatus class.
"""
assert func()
def check_evaluate_perfect_order():
"""
Check that a perfect order leads to a __customer_happiness value of zero.
Returns:
True if a perfectly filled order results in the __customer_happiness
having a value of zero, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
# populates PizzaStatus with toppings to fill out order correctly.
for topping, num in order.order_dict.items():
if num == 1:
pizza.add_topping(topping)
money.evaluate_order(order, pizza)
return money.customer_happiness == 0
def check_evaluate_imperfect_order():
"""
Check an imperfect order leading to a __customer_happiness value of zero.
Returns:
True if a perfectly imperfect order results in the __customer_happiness
having a value of one, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
money.evaluate_order(order, pizza)
return money.customer_happiness == 1.0
def check_get_perfect_tip():
"""
Check that a perfect order's tip equals the number of toppings times 1.5.
Returns:
True if the tip of a perfect order is equal to 1.5 times the number of
toppings that are in the order, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
# populates PizzaStatus with toppings to fill out order correctly.
for topping, num in order.order_dict.items():
if num == 1:
pizza.add_topping(topping)
return money.get_tip(order, pizza) == money.desired_toppings * 1.5
def check_get_imperfect_tip():
"""
Check that a perfect order's tip equals the number of toppings times 1.5.
Returns:
True if the tip for an order that is not filled out whatsoever has a
tip of 0, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
return money.get_tip(order, pizza) == 0
def check_update_money_perfect():
"""
Check that an order with a nonzero tip changes the value of __total_money.
Returns:
True if the value of __total_money is greater than 0 after a call to
get_tip on a completed order, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
# populates PizzaStatus with toppings to fill out order correctly.
for topping, num in order.order_dict.items():
if num == 1:
pizza.add_topping(topping)
money.update_money(order, pizza)
return money.get_money > 0
def check_update_money_imperfect():
"""
Check that order with zero tip does not change the value of __total_money.
Returns:
True if the value of __total_money is 0 after a call to get_tip on an
incomplete order, False otherwise.
"""
money = gmo.Money()
order = gmo.OrderStatus(1)
pizza = gmo.PizzaStatus()
# populates PizzaStatus with toppings to fill out order correctly.
for topping, num in order.order_dict.items():
if num == 1:
pizza.add_topping(topping)
money.update_money(order, pizza)
return money.get_money > 0
@pytest.mark.parametrize(
"func",
[
check_evaluate_perfect_order,
check_evaluate_imperfect_order,
check_get_perfect_tip,
check_get_imperfect_tip,
check_update_money_perfect,
check_update_money_imperfect,
],
)
def test_Money(func): # pylint: disable=invalid-name
"""
Check that the Money class in game_model is working as intended.
Args:
func: A function that returns a boolean, used to test various
functionality of the Money class.
"""
assert func()