Repository navigation
Expand file tree
/
Copy pathtests.py
More file actions
327 lines (261 loc) · 8.41 KB
/
Copy pathtests.py
File metadata and controls
327 lines (261 loc) · 8.41 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# Testcases for the functions:
# Format: <module>.<function>.<testcase number>
# Testcases: normal, boundary, error
# HOW TO USE:
# TEST ONE TESTCASE AT A TIME. COMMENT THE TEST CASE AFTER DONE USING CTRL /
import module1_tables as module1_tables
import module2_crowds as module2_crowds
import module3_queue as module3_queue
import module4_priority as module4_priority
# Original variables from main (overwrite them to test functions):
zones = {
"A": {2: 5, 4: 8, 6: 3, 8: 2},
"B": {2: 4, 4: 6, 6: 2, 8: 1},
"C": {2: 6, 4: 5, 6: 4, 8: 2}
}
max_tables = {
"A": {2: 5, 4: 8, 6: 3, 8: 2},
"B": {2: 4, 4: 6, 6: 2, 8: 1},
"C": {2: 6, 4: 5, 6: 4, 8: 2}
}
queue = {
2: [],
4: [],
6: [],
8: []
}
queue_numbers = {2: 201, 4: 401, 6: 601, 8: 801}
tables_per_table_type = module3_queue.count_table_type(max_tables)
priority_queue = {
2: [],
4: [],
6: [],
8: []
}
########## START OF TESTS ##########
# 1.1 display_tables
# 1.1.1 Normal test case: Display tables with normal values
# module1_tables.display_tables(zones)
# 1.1.2 Boundary test case: Display tables with all zero values
# zones_zero = {
# "A": {2: 0, 4: 0, 6: 0, 8: 0},
# "B": {2: 0, 4: 0, 6: 0, 8: 0},
# "C": {2: 0, 4: 0, 6: 0, 8: 0}
# }
# module1_tables.display_tables(zones_zero)
# 1.1.3 Error test case: Display tables with invalid vacancy values (negative numbers)
# zones_invalid = {
# "A": {2: -5, 4: -8, 6: -3, 8: -2},
# "B": {2: -4, 4: -6, 6: -2, 8: -1},
# "C": {2: -6, 4: -5, 6: -4, 8: -2}
# }
# module1_tables.display_tables(zones_invalid)
# 1.1.4 Error test case: Display tables with invalid vacancy values (non-integer)
# zones_invalid_non_integer = {
# "A": {2: "1337", 4: "1000", 6: "10000", 8: 2},
# "B": {2: 4, 4: "123131", 6: "123456", 8: 1},
# "C": {2: 6, 4: "LOL", 6: "HAHA", 8: 2}
# }
# module1_tables.display_tables(zones_invalid_non_integer)
# 1.2 occupy_table
# 1.2.1 Normal test case: Occupy a table with valid zone and table size
# module1_tables.occupy_table(zones, "A", 4)
# 1.2.2 Boundary test case: Occupy a table with the last available table
# module1_tables.occupy_table(zones, "B", 8)
# 1.2.3 Error test case: Occupy a table with an invalid zone
# module1_tables.occupy_table(zones, "D", 4)
# 1.2.4 Error test case: Occupy a table with an invalid table size
# module1_tables.occupy_table(zones, "A", 10)
# 1.3 unoccupy_table
# 1.3.1 Normal test case: Unoccupy a table with valid zone and table size
# zones = {
# "A": {2: 5, 4: 7, 6: 3, 8: 2},
# "B": {2: 4, 4: 6, 6: 2, 8: 0},
# "C": {2: 6, 4: 5, 6: 4, 8: 2}
# }
# module1_tables.unoccupy_table(zones, max_tables, "A", 4, queue, priority_queue)
# 1.3.2 Boundary test case: Unoccupy a table with the last occupied table
# module1_tables.unoccupy_table(zones, max_tables, "B", 8, queue, priority_queue)
# 1.3.3 Error test case: Unoccupy a table that was already fully vacant
# zones = {
# "A": {2: 5, 4: 8, 6: 3, 8: 2},
# "B": {2: 4, 4: 6, 6: 2, 8: 1},
# "C": {2: 6, 4: 5, 6: 4, 8: 2}
# }
# module1_tables.unoccupy_table(zones, max_tables, "B", 4, queue, priority_queue)
# 1.3.4 Error test case: Unoccupy a table with an invalid table size/zone
# module1_tables.unoccupy_table(zones, max_tables, "A", 10, queue, priority_queue)
# 2.1 crowd_indicator/occupancy_percentage
# 2.1.1 Normal test case: Calculate crowd indicator with normal values
# zones = {
# "A": {2: 5, 4: 7, 6: 3, 8: 2},
# "B": {2: 4, 4: 6, 6: 2, 8: 0},
# "C": {2: 6, 4: 5, 6: 4, 8: 2}
# }
# module2_crowds.crowd_indicator(max_tables, zones)
# 2.1.2 Boundary test case: Calculate crowd indicator with zero occupancy.
# module2_crowds.crowd_indicator(max_tables, zones)
# 2.1.3 Error test case: swap arguments
# zones = {
# "A": {2: 5, 4: 7, 6: 3, 8: 2},
# "B": {2: 4, 4: 6, 6: 2, 8: 0},
# "C": {2: 6, 4: 5, 6: 4, 8: 2}
# }
# module2_crowds.crowd_indicator(zones, max_tables)
# 2.2 crowd_indicator - check the returned value as well
# 2.2.1 Normal test case: returns LOW
# zones = {
# "A": {2: 5, 4: 7, 6: 3, 8: 2},
# "B": {2: 4, 4: 6, 6: 2, 8: 0},
# "C": {2: 6, 4: 5, 6: 4, 8: 2}
# }
# print(f"returned value: {module2_crowds.crowd_indicator(max_tables, zones)}")
# 2.2.2 Normal test case: returns CROWDED
# zones = {
# "A": {2: 5, 4: 1, 6: 1, 8: 1},
# "B": {2: 1, 4: 1, 6: 2, 8: 0},
# "C": {2: 1, 4: 1, 6: 4, 8: 2}
# }
# print(f"returned value: {module2_crowds.crowd_indicator(max_tables, zones)}")
# 2.2.3 Boundary test case: returns FULL
# zones = {
# "A": {2: 0, 4: 0, 6: 0, 8: 0},
# "B": {2: 0, 4: 0, 6: 0, 8: 0},
# "C": {2: 0, 4: 0, 6: 0, 8: 0}
# }
# print(f"returned value: {module2_crowds.crowd_indicator(max_tables, zones)}")
# 3.1 join_queue
# 3.1.1 Normal test case: add a customer to queue[2] when queue is empty and should return the next customer's number
# print(f"returned: {module3_queue.join_queue(queue, 2, queue_numbers[2])}")
# print(queue)
# 3.1.2 Error test case: add a customer to a non-existent queue: e.g. queue[10]
# print(f"returned: {module3_queue.join_queue(queue, 10, queue_numbers[10])}")
# 3.2 call_next_customer
# 3.2.1 Normal test case: both priority q and normal q have people -> priority served first
# queue = {
# 2: [201, 202, 203, 206],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [204, 205],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.call_next_customer(zones, "A", priority_queue, queue, 2)
# 3.2.2 Boundary test case: no queue at all.
# queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.call_next_customer(zones, "A", priority_queue, queue, 2)
# it returned nothing so i could not screenshot any output
# 3.2.3 Error test case: zone or table size invalid
# module3_queue.call_next_customer(zones, "D", priority_queue, queue, 2) # returned nothing
# 3.3 waiting_time
# 3.3.1 normal test case: valid queue and priority queue
# queue = {
# 2: [201, 202, 203, 206],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [204, 205],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.waiting_time(tables_per_table_type, priority_queue, queue, 2)
# expected output: 6 ppl in queue, total of 15 tables for 2, so 12 minutes
# 3.3.2 boundary test case: no queue
# queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.waiting_time(tables_per_table_type, priority_queue, queue, 2)
# 3.3.3 error test case: zero tables in the hawker center i.e. divide by zero
# queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.waiting_time({2: 0, 4: 0, 6: 0, 8: 0}, priority_queue, queue, 2)
# 3.4 Leave queue
# 3.4.1 normal: remove queue number from queue
# queue = {
# 2: [201, 202, 203, 206],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [204, 205],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.leave_queue(queue, priority_queue, 2, 202)
# 3.4.2 error: leave queue that is empty/not found
# queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [],
# 4: [],
# 6: [],
# 8: []
# }
# module3_queue.leave_queue(queue, priority_queue, 2, 202)
# 4.1 join_priority_queue
# 4.1.1 Normal test case: add a customer to priority_queue[2] when priority_queue is empty and should return the next customer's number
# print(f"returned: {module4_priority.join_priority_queue(priority_queue, 2, queue_numbers[2])}")
# print(priority_queue)
# 4.1.2 Error test case: add a customer to a non-existent queue: e.g. priority_queue[10]
# print(f"returned: {module4_priority.join_priority_queue(priority_queue, 10, queue_numbers[10])}")
# i see that an error is that queue_numbers[10] cannot be accessed. then what if i just change to 8 instead???
# print(f"returned: {module4_priority.join_priority_queue(priority_queue, 10, queue_numbers[8])}")
# no. the module itself finds priority_queue[table_size], which is the second argument. so either way you have to put valid table size also.
# 4.2 priority_waiting_time
# 4.2.1 normal: calculate waiting time:
# queue = {
# 2: [201, 202, 203, 206],
# 4: [],
# 6: [],
# 8: []
# }
# priority_queue = {
# 2: [204, 205],
# 4: [],
# 6: [],
# 8: []
# }
# module4_priority.priority_waiting_time(tables_per_table_type, priority_queue, 2)