-
Notifications
You must be signed in to change notification settings - Fork 0
/
soda.testtxt
481 lines (428 loc) · 18 KB
/
soda.testtxt
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
The first part of testing is incorrect usage testing. To do this, we check the behaviour of the program
on various invalid usages, like too many parameters or invalid values:
linux028:~/cs343/a6/CS343_A6> make
make: Nothing to be done for `all'.
linux028:~/cs343/a6/CS343_A6> ./soda 1 2 3
Usage: ./soda [ config-file [ random-seed (> 0) ] ]
linux028:~/cs343/a6/CS343_A6> ./soda UNEXISTING_CONFIG_FILE
Error: could not open input file "UNEXISTING_CONFIG_FILE"
linux028:~/cs343/a6/CS343_A6> ./soda soda.config -1
Usage: ./soda [ config-file [ random-seed (> 0) ] ]
linux028:~/cs343/a6/CS343_A6> ./soda soda.config SHOULD_BE_INT
Usage: ./soda [ config-file [ random-seed (> 0) ] ]
linux028:~/cs343/a6/CS343_A6> ./soda foo bar
Usage: ./soda [ config-file [ random-seed (> 0) ] ]
We correctly handle invalid inputs - we checked that our behaviour mirrors the reference solution.
---------------------------------------------------------------------
Some of the testing comes from assertions placed in the code that will force the
program to quit when encountering abnormal conditions.
Additionally we can check that no deadlocks or other problems arise. We've made
a script that will allow us to check some possible input combinations. For each
combination of input parameters, we generate an appropriate config file and run
our program with it. If deadlock happens, the script will stop in the middle
without printing the FINISHED message. If an assertion fails, the failure
message will get printed to console. Here's the result of running the tests:
linux028:~/cs343/a6/CS343_A6> cat testscript.sh
#!/bin/bash -e
# Example input file:
#
# SodaCost 2 # Manufacturer Suggested Retail Price (MSRP) per bottle
# NumStudents 2 # number of students to create
# MaxPurchases 8 # maximum number of bottles a student purchases
# NumVendingMachines 3 # number of vending machines
# MaxStockPerFlavour 5 # maximum number of bottles of each flavour in a vending machine
# MaxShippedPerFlavour 3 # maximum number of bottles of each flavour generated by the bottling
# # plant per production run
# TimeBetweenShipments 3 # length of time between shipment pickup
# ParentalDelay 2 # length of time between new deposits of funds
# NumCouriers 1 # maximum number of couriers in the pool
`touch testfile.config`
for SodaCost in `seq 1 6`;
do
for NumStudents in `seq 1 5`;
do
for MaxPurchases in `seq 1 4`;
do
for NumVendingMachines in `seq 1 3`;
do
for MaxStockPerFlavour in `seq 1 2`;
do
for MaxShippedPerFlavour in `seq 1 2`;
do
for TimeBetweenShipments in `seq 4 4`;
do
for ParentalDelay in `seq 1 1`;
do
for NumCouriers in `seq 1 2`;
do
for seed in `seq 1 3`;
do
`echo "SodaCost $SodaCost
NumStudents $NumStudents
MaxPurchases $MaxPurchases
NumVendingMachines $NumVendingMachines
MaxStockPerFlavour $MaxStockPerFlavour
MaxShippedPerFlavour $MaxShippedPerFlavour
TimeBetweenShipments $TimeBetweenShipments
ParentalDelay $ParentalDelay
NumCouriers $NumCouriers
" > testfile.config`
echo "Running soda testfile.config $seed"
`./soda testfile.config $seed >/dev/null`
done
done
done
done
done
done
done
done
done
done
echo "VERIFICATION FINISHED."
linux028:~/cs343/a6/CS343_A6> make
make: Nothing to be done for `all'.
linux028:~/cs343/a6/CS343_A6> sh testscript.sh
Running soda testfile.config 1
Running soda testfile.config 2
Running soda testfile.config 3
Running soda testfile.config 1
Running soda testfile.config 2
// MORE OUTPUT
Running soda testfile.config 1
Running soda testfile.config 2
Running soda testfile.config 3
VERIFICATION FINISHED.
So we see that the script successfully finished execution. Thus, no deadlocks happened throughout the execution,
as well as no assertions were triggered.
---------------------------------------------------------------------
The last part of testing comes from inspection of interesting cases. Here are some interesting cases that we are
going to inspect.
1) Let's run the solution on the sample configs with the seed value of 77:
linux028:~/cs343/a6/CS343_A6> ./soda soda.config 77
Parent WATOff Names Truck Plant Stud0 Stud1 Mach0 Mach1 Mach2 Cour0
******* ******* ******* ******* ******* ******* ******* ******* ******* ******* *******
S S2
S S R0 S S S2,3 S2,6 S2 S2 S
D1,1 W R1 G4
D0,3 R2 t0,5
D1,3 C0,5 N0,0 V0
D0,1 C1,5 N1,1 V1
D1,3
D1,3 P4 P
d0,4 r
D0,1 U0,16 R T0,5
D0,0
d1,0 r
D0,3 C0,5 U1,20 G7 L R
D1,0
d2,0 r
U2,20 t1,5
D1,2 W N1,2 D2,0 V2 R T1,5
D1,3 N1,0 V0 B2,0 t0,5
W N1,1 B3
D1,3 N1,2 V1
D1,1 N1,0 V2
D1,2 N1,1 V0
D0,3 P7 P V1
d0,7 r
D1,3 N1,2 U0,10 V2 R T0,5
D0,0
d1,0 r
D1,3 W N1,0 U1,20 G5 B3 V0 B2,1 R
D1,0
d2,0 r
D0,3 U2,20 B1 B2,0 R
D0,2 N0,1 D2,0 V1
D0,2 N0,2 V2
D0,1 N0,0 V0
D0,3 N0,1 P5 P V1
d0,5 r
D0,3 N0,2 U0,9 V2 R
D0,2
d1,2 r
D1,3 N0,0 U1,18 G7 V0 R
D1,0
d2,0 r
D0,2 U2,20 B1 B2,0 t1,7
D1,2 T1,7 N1,1 D2,0 V1 R T1,7
D1,1 W N0,1 P7 P V1
d0,7 r
D1,2 N0,2 U0,6 V2 R
D0,3
d1,3 r
D1,1 N0,0 U1,15 G7 V0 R
D1,0
d2,0 r
D0,2 N1,2 U2,20 V2 t0,7
D1,1 T0,7 N1,0 D2,0 B6 V0 B2,0 R T0,7
... ... ... ... ... F ... ... ... ... ...
D0,1 W N1,1 V1
D0,1 N1,2 P7 P V2
d0,7 r
D0,2 N1,0 U0,3 V0 R
D0,3
d1,3 r
D1,1 U1,13 G7 B6 B2,2 R
D1,1
d2,1 r
D1,3 U2,19 R
D0,2 D2,0 P
P7
d0,7 r
D0,3 U0,1 R
D0,4
d1,4 r
D1,3 U1,10 G7 B4 B2,3 R
D1,1
d2,1 r
D0,3 U2,18 B2 B2,2 R
D0,3 D2,0
D1,3 P7 P
d0,7 r
D1,3 U0,1 R
D0,5
d1,5 r
D1,1 U1,6 G7 R
D1,1
d2,1 r
D0,2 U2,17 B0 B2,3
... ... ... ... ... ... F ... ... ... ...
D0,3 D2,0 R
F ... ... ... ... ... ... ... ... ... ...
... F ... ... ... ... ... ... ... ... ...
P7 P
d0,7 r
... ... ... ... ... ... ... ... ... ... F
D0,5 R
d1,5 r
U1,6 G6 R
D1,5
d2,5 r
U2,13 R
D2,1
... ... ... F ... ... ... ... ... ... ...
... ... ... ... F ... ... ... ... ... ...
... ... ... ... ... ... ... F ... ... ...
... ... ... ... ... ... ... ... F ... ...
... ... ... ... ... ... ... ... ... F ...
... ... F ... ... ... ... ... ... ... ...
***********************
As you can see, there are no anomalies: students are repeatedly checking different vending
machines and terminate as soon as they are done (reference solution does the same),
truck keeps delivering soda, parent keeps providing money and so on.
2) Abnormally expensive soda. soda.config has the same values as in sample, with the exception of SodaCost, which
is now 100. Since funds can only be increased by 5$, this means that students will need a while to get the needed
funds. Here's a shortened output:
Parent WATOff Names Truck Plant Stud0 Stud1 Mach0 Mach1 Mach2 Cour0
******* ******* ******* ******* ******* ******* ******* ******* ******* ******* *******
S S100
S S R0 S S S0,4 S0,8 S100 S100 S
D1,1 W R1 G3
D0,2 R2 t0,5
D1,1 C0,5 N0,0 V0
D1,2 C1,5 N1,1 V1
D1,2
D1,2
D1,3
D0,1 P3 P
d0,3 r
D0,2 U0,17 R T0,5
D0,0
d1,0 r
D0,1 U1,20 t1,5
N0,1 D1,0 G10 V1 R T1,5
d2,0 r
D1,1 W N0,2 U2,20 V2 R
D0,3 W N1,2 D2,0 V2
D1,3 N0,0 P10 P V0
D0,2 N0,1 d0,10 V1 r
D1,3 N1,0 U0,7 V0 R
D0,0
d1,0 r
D0,3 N0,2 U1,20 G5 V2 R
D1,0
D1,3 N0,0 d2,0 V0 r
D0,1 T1,105 U2,20 R t1,105
// MORE OUTPUT
d1,7 G9 r
D1,7 R
d2,7 r
D2,7 R
... ... ... F ... ... ... ... ... ... ...
... ... ... ... F ... ... ... ... ... ...
... ... ... ... ... ... ... F ... ... ...
... ... ... ... ... ... ... ... F ... ...
... ... ... ... ... ... ... ... ... F ...
... ... F ... ... ... ... ... ... ... ...
***********************
What is worth noticing is that reference solution printed 1565 lines for this case, while our solution printed
1632. This means that overall efficiency was quite similar for them. In addition to that, it can be noticed that
the overall structure of prints is quite similar as well. Hence we can claim that our solution performs as expected
on this testcase.
3) Lots of students. soda.config is the same as in sample, with the exception that the student count is 10 in the
first sub-test and 50 in the second sub-test. Both executions terminated successfully. Likewise, the counts were
398 vs 295 and 1692 vs 1791 (OurSolution vs ReferenceSolution). The counts are quite close to each other, which
again advocates for the correctness of our solution.
4) Next interesting case is when vending machines can only contain one bottle per flavour, and truck can only
ship one bottle per flavour. In addition to that, we set large TimeBetweenShipments and ParentalDelay values.
Here's a complete list:
SodaCost 5 # Manufacturer Suggested Retail Price (MSRP) per bottle
NumStudents 3 # number of students to create
MaxPurchases 8 # maximum number of bottles a student purchases
NumVendingMachines 3 # number of vending machines
MaxStockPerFlavour 1 # maximum number of bottles of each flavour in a vending machine
MaxShippedPerFlavour 1 # maximum number of bottles of each flavour generated by the bottling
# plant per production run
TimeBetweenShipments 20 # length of time between shipment pickup
ParentalDelay 20 # length of time between new deposits of funds
NumCouriers 1 # maximum number of couriers in the pool
The execution result is:
Parent WATOff Names Truck Plant Stud0 Stud1 Stud2 Mach0 Mach1 Mach2 Cour0
******* ******* ******* ******* ******* ******* ******* ******* ******* ******* ******* *******
S S5
S S R0 S S S0,4 S1,3 S1,1 S5 S5 S
W R1
R2 t0,5
C0,5 N0,0 V0
C1,5 N1,1 V1
D1,1 C2,5 N2,2 G4 V2
P4 P
d0,4 r
D0,0 R
d1,0 r
U1,4 R
D1,0
d2,0 r
U2,4 R
// MORE OUTPUT
d0,3 r
D0,3 R
d1,3 r
D1,3 R
d2,3 r
D2,3 G3 R
... ... ... F ... ... ... ... ... ... ... ...
... ... ... ... F ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... F ... ... ...
... ... ... ... ... ... ... ... ... F ... ...
... ... ... ... ... ... ... ... ... ... F ...
... ... F ... ... ... ... ... ... ... ... ...
***********************
The length of the result is 479 lines, while the sample solution prints 499 lines. Again, the results are very
close. Again, no anomalies were detected.
5) Now, let's use the test values from the sample configs, with the exception that MaxStockPerFlavour is 100 and
MaxShippedPerFlavour is 1. Considering that students are only making <= 8 purchases, every delivery should be
unsuccessful.
Parent WATOff Names Truck Plant Stud0 Stud1 Mach0 Mach1 Mach2 Cour0
******* ******* ******* ******* ******* ******* ******* ******* ******* ******* *******
S S2
S S R0 S S S0,3 S3,3 S2 S2 S
D1,3 W R1 G2
D0,1 R2 t0,5
D1,3 C0,5 N0,0 V0
D1,1 C1,5 N1,1 P2 P V1
d0,2 r
D1,1 U0,398 R
D0,0
d1,0 r
D0,1 U1,400 G1 R
D1,0
d2,0 r
D0,2 U2,400 R
D1,3 D2,0
D0,2 P1 P
d0,1 r
D1,3 U0,397 R T0,5
// MORE OUTPUT
... ... ... ... ... ... ... ... F ... ...
... ... ... ... ... ... ... ... ... F ...
... ... F ... ... ... ... ... ... ... ...
***********************
Execution finished successfully without any anomalies. Furthermore, you can see that each delivery
that truck makes is unsuccessful as expected.
6) Next, let's check what happens when there is only one vending machine (other parameters are the same
as in sample).
Parent WATOff Names Truck Plant Stud0 Stud1 Mach0 Cour0
******* ******* ******* ******* ******* ******* ******* ******* *******
S S2
S S R0 S S S2,1 S2,3 S
D1,1 W N0,0 G7 V0
D1,2 C0,5 t0,5
D0,1 C1,5 N1,0 V0
D0,1 P7 P
d0,7 r
D1,1 U0,13 R
D0,1 D0,0 G4
P4 P
d0,4 r
D0,2 U0,9 R T0,5
D1,2 D0,0 t1,5
G3 B3 B2,3 T1,5
... ... ... ... ... F ... ... ...
D0,2 W P3 P
d0,3 r
D0,1 W U0,7 R
D1,3 D0,0 G5 B3 B2,4
D1,1 P5 P
d0,5 r
D0,1 U0,4 R
D1,3 D0,1 G1
D1,2
D1,3 B1 B2,4
D0,3
D1,3 P1 P
d0,1 r
D1,1 U0,4 R
D1,1 D0,0 G6
D0,3 t1,7
D1,2 T1,7 L T1,7
D1,3 C1,5 t1,5
D1,2 W P6 P B2,3 T1,5
d0,6 r
U0,1 B3
... ... ... ... ... ... F ... ...
D0,3 W D0,2 R
D1,3 G6
F ... ... ... ... ... ... ... ...
... F ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... F
... ... ... F ... ... ... ... ...
... ... ... ... F ... ... ... ...
... ... ... ... ... ... ... F ...
... ... F ... ... ... ... ... ...
***********************
Students didn't end up buying too many bottles, so the execution was short. No anomalies.
7) Lastly, let's check a testcase with more than one courier. Here are the input values:
SodaCost 7 # Manufacturer Suggested Retail Price (MSRP) per bottle
NumStudents 2 # number of students to create
MaxPurchases 3 # maximum number of bottles a student purchases
NumVendingMachines 3 # number of vending machines
MaxStockPerFlavour 6 # maximum number of bottles of each flavour in a vending machine
MaxShippedPerFlavour 7 # maximum number of bottles of each flavour generated by the bottling
# plant per production run
TimeBetweenShipments 9 # length of time between shipment pickup
ParentalDelay 5 # length of time between new deposits of funds
NumCouriers 4 # maximum number of couriers in the pool
Result:
Parent WATOff Names Truck Plant Stud0 Stud1 Mach0 Mach1 Mach2 Cour0 Cour1 Cour2 Cour3
******* ******* ******* ******* ******* ******* ******* ******* ******* ******* ******* ******* ******* *******
S S7
S S R0 S S S0,2 S0,3 S7 S7 S S S S
W R1
D1,2 R2 t0,5
C0,5 N0,0 V0
C1,5 N1,1 G6 V1 t1,5
D0,3 W P6 P
d0,6 r
W U0,18 R
// MORE OUTPUT
... ... ... F ... ... ... ... ... ... ... ... ... ...
... ... ... ... F ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... F ... ... ... ... ... ...
... ... ... ... ... ... ... ... F ... ... ... ... ...
... ... ... ... ... ... ... ... ... F ... ... ... ...
... ... F ... ... ... ... ... ... ... ... ... ... ...
***********************
Execution finished with no errors, no anomalies were detected. All 4 couriers were used at least once; the reference
solution uses each courier at least once as well.