-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ps3.py
512 lines (475 loc) · 27 KB
/
test_ps3.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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# Test suite for Problem Set 3 (Simulating Robots)
# Fall 2018
import sys
import threading
import traceback
import unittest
import random
import ps3
def xyrange(x_upper_bound, y_upper_bound):
""" Returns the cartesian product of range(x_upper_bound) and range(y_upper_bound).
Useful for iterating over the tuple coordinates of a room
"""
for x in range(x_upper_bound):
for y in range(y_upper_bound):
yield (x, y) # these are the room tile xy tuples
class ps3_P1A(unittest.TestCase):
"""test the iRoom base class"""
def test_room_dirt_dirty(self):
"""
Can fail either because get_dirt_amount is working incorrectly
OR the student is initializing the dirt amount incorrectly
"""
width, height, dirt_amount = (3, 4, 1)
room = ps3.iRoom(width, height, dirt_amount)
for x, y in xyrange(width, height):
self.assertEqual(room.get_dirt_amount(x, y),dirt_amount,
"Tile {} was not initialized with correct dirt amount".format((x, y))
)
def test_room_dirt_clean(self):
"""
Can fail either because get_dirt_amount is working incorrectly
OR the student is initializing the dirt amount incorrectly
"""
width, height, dirt_amount = (3, 4, 0)
room = ps3.iRoom(width, height, dirt_amount)
for x, y in xyrange(width, height):
self.assertEqual(room.get_dirt_amount(x, y),dirt_amount,
"Tile {} was not initialized with correct dirt amount".format((x, y))
)
def test_is_tile_cleaned_dirty(self):
""" Test is_tile_cleaned"""
width, height, dirt_amount = (3, 4, 1)
room = ps3.iRoom(width, height, dirt_amount)
# Check all squares are unclean at start, given initial dirt > 1
for x, y in xyrange(width, height):
self.assertFalse(room.is_tile_cleaned(x, y),
"Unclean tile {} was returned as clean".format((x, y))
)
def test_is_tile_cleaned_clean(self):
""" Test is_tile_cleaned"""
width, height, dirt_amount = (3, 4, 0)
room = ps3.iRoom(width, height, dirt_amount)
# Check all squares are unclean at start, given initial dirt > 1
for x, y in xyrange(width, height):
self.assertTrue(room.is_tile_cleaned(x, y),
"Unclean tile {} was returned as clean".format((x, y))
)
def test_clean_tile_at_position_PosToZero(self):
""" Test if clean_tile_at_position removes all dirt"""
width, height, dirt_amount = (3, 4, 1)
room = ps3.iRoom(width, height, dirt_amount)
# Clean the tiles and confirm they are marked as clean
for x, y in xyrange(width, height):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), dirt_amount)
# using random.random in case there is any issue with specific parts of a tile
for x, y in xyrange(width, height):
self.assertTrue(room.is_tile_cleaned(x, y),
"Clean tile {} was not marked clean".format((x, y))
)
def test_clean_tile_at_position_PosToPos(self):
""" Test if clean_tile_at_position removes all dirt"""
width, height, dirt_amount = (3, 4, 2)
room = ps3.iRoom(width, height, dirt_amount)
# Clean the tiles and confirm they are marked as clean
for x, y in xyrange(width, height):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), dirt_amount - 1)
# using random.random in case there is any issue with specific parts of a tile
for x, y in xyrange(width, height):
self.assertFalse(room.is_tile_cleaned(x, y),
"Unclean tile {} was marked clean".format((x, y))
)
def test_clean_tile_at_position_ZeroToZero(self):
""" Test if clean_tile_at_position removes all dirt"""
width, height, dirt_amount = (3, 4, 0)
room = ps3.iRoom(width, height, dirt_amount)
# Clean the tiles and confirm they are marked as clean
for x, y in xyrange(width, height):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
# using random.random in case there is any issue with specific parts of a tile
for x, y in xyrange(width, height):
self.assertTrue(room.is_tile_cleaned(x, y),
"Clean tile {} was marked clean, no negative dirt allowed".format((x, y))
)
def test_get_num_cleaned_tiles_FullIn1(self):
"Test get_num_cleaned_tiles for cleaning subset of room completely with 1 call"
width, height, dirt_amount = (3, 4, 1)
room = ps3.iRoom(width, height, dirt_amount)
cleaned_tiles = 0
# Clean some tiles
for x, y in xyrange(width-1, height-1):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
cleaned_tiles += 1
num_cleaned = room.get_num_cleaned_tiles()
self.assertEqual(num_cleaned, cleaned_tiles,
"Number of clean tiles is incorrect: expected {}, got {}".format(cleaned_tiles, num_cleaned)
)
def test_get_num_cleaned_tiles_Partial(self):
"Test get_num_cleaned_tiles for cleaning subset of room incompletely"
width, height, dirt_amount = (3, 4, 2)
room = ps3.iRoom(width, height, dirt_amount)
cleaned_tiles = 0
# Clean some tiles
for x, y in xyrange(width-1, height-1):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
num_cleaned = room.get_num_cleaned_tiles()
self.assertEqual(num_cleaned, cleaned_tiles,
"Number of clean tiles is incorrect: expected {}, got {}".format(cleaned_tiles, num_cleaned)
)
def test_get_num_cleaned_tiles_FullIn2(self):
"""Test get_num_cleaned_tiles for cleaning subset of room in two calls"""
width, height, dirt_amount = (3, 4, 2)
room = ps3.iRoom(width, height, dirt_amount)
cleaned_tiles = 0
# Clean some tiles
for x, y in xyrange(width-1, height-1):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
cleaned_tiles += 1
num_cleaned = room.get_num_cleaned_tiles()
self.assertEqual(num_cleaned, cleaned_tiles,
"Number of clean tiles is incorrect: expected {}, got {}".format(cleaned_tiles, num_cleaned)
)
def test_get_num_cleaned_tiles_OverClean(self):
"Test cleaning already clean tiles does not increment counter"
width, height, dirt_amount = (3, 4, 2)
room = ps3.iRoom(width, height, dirt_amount)
# clean all of the tiles in the room
for x, y in xyrange(width, height):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), dirt_amount)
for x, y in xyrange(width, height):
room.clean_tile_at_position(ps3.Position(x + random.random(), y + random.random()), 1)
num_cleaned = room.get_num_cleaned_tiles()
self.assertEqual(num_cleaned, width * height,
"Number of clean tiles is incorrect: re-cleaning cleaned tiles must not increase number of cleaned tiles"
)
def test_is_position_in_room(self):
"Test is_position_in_room"
width, height, dirt_amount = (3, 4, 2)
room = ps3.iRoom(width, height, dirt_amount)
sols = [True, False,True,False,False,False,False,False,False,False,True,False,True,False,False,False,False,False,False,False,False,False,False,False,False]
count = 0
for x in [0.0, -0.1, width - 0.1, width, width + 0.1]:
for y in [0.0, -0.1, height - 0.1, height, height + 0.1]:
pos = ps3.Position(x, y)
self.assertEqual(sols[count],room.is_position_in_room(pos),
"position {},{} is incorrect: expected {}, got {}".format(x, y, sols[count], room.is_position_in_room(pos)))
count += 1
def test_get_random_position(self):
"""Test get_random_position
checks for distribution of positions and validity of positions
"""
width, height, dirt_amount = (5, 10, 1)
room = ps3.iRoom(width, height, dirt_amount)
freq_buckets = {}
for i in range(50000):
pos = room.get_random_position()
# confirm from test that this is a valid position
self.assertTrue(room.is_position_in_room(pos))
try:
x, y = pos.get_x(), pos.get_y()
except AttributeError:
self.fail("get_random_position returned {} which is not a Position".format(pos))
self.assertTrue(0 <= x < width and 0 <= y < height,
"get_random_position returned {} which is not in [0, {}), [0, {})".format(pos,width,height))
x0, y0 = int(x), int(y)
freq_buckets[(x0, y0)] = freq_buckets.get((x0, y0), 0) + 1
for t in xyrange(width, height):
num_in_bucket = freq_buckets.get(t, 0)
self.assertTrue(
# This is a 99.7% confidence interval for a uniform
# distribution. Fail if the total of any bucket falls outside
# this range.
865 < num_in_bucket < 1150,
"The distribution of positions from get_random_position "
"looks incorrect (it should be uniform)")
def test_get_num_tiles(self):
""" test get_num_tiles method"""
widths = [10, 8, 4, 4, 2, 4, 1, 6, 7, 5, 3]
heights = [6, 8, 9, 3, 5, 6, 2, 1, 3, 1, 7]
sols = [60, 64, 36,12,10,24,2,6,21,5, 21]
for i in range(11):
# width, height, dirt_amount = (random.randint(1,10), random.randint(1,10), 1)
width, height, dirt_amount = (widths[i], heights[i], 1)
room_num_tiles = ps3.iRoom(width, height, dirt_amount).get_num_tiles()
sol_room_tiles = sols[i]
self.assertEqual(room_num_tiles, sol_room_tiles,
"student code number of room tiles = {}, not equal to solution code num tiles {}".format(room_num_tiles, sol_room_tiles)
)
class ps3_P1B(unittest.TestCase):
"""test the Robot abstract base class"""
def test_unimplemented_methods(self):
"""Test if student implemented methods in Robot abstract class that should not be implemented"""
room = ps3.iRoom(2,2,1)
robot = ps3.Robot(room,1,1)
self.assertRaises(NotImplementedError, robot.update_pos_and_clean)
def test_getset_robot_direction(self):
"""Test get_robot_direction and set_robot_direction"""
# instantiate iRoom from solutions for testing
width, height, dirt_amount = (3, 4, 2)
solution_room = ps3.iRoom(width, height, dirt_amount)
robots = [ps3.Robot(solution_room, 1.0, 1) for i in range(5)]
directions = [1, 333, 105, 75, 74.3]
for dir_index, robot in enumerate(robots):
robot.set_robot_direction(directions[dir_index])
for dir_index, robot in enumerate(robots):
robot_dir = robot.get_robot_direction()
self.assertEqual(robot_dir, directions[dir_index],
"Robot direction set or retrieved incorrectly: expected {}, got {}".format(directions[dir_index], robot_dir)
)
class ps3_P3(unittest.TestCase):
"""This tests iRoom and Simple robot in various ways"""
def createRoomAndRobots(self, num_robots):
r = ps3.iRoom(5, 7, 1)
robots = [ps3.SimpleRobot(r, 1.0, 1) for i in range(num_robots)]
return r, robots
def test_BoundaryConditions(self):
"Test strict inequalities in random positions for the iRoom and SimpleRobot"
for m in range(7000):
r, robots = self.createRoomAndRobots(4)
for r in robots:
p = r.get_robot_position()
d = r.get_robot_direction()
try:
x, y = p.get_x(), p.get_y()
except AttributeError:
self.fail("get_robot_position returned %r which is not a Position" % (p,))
self.assertTrue(x < 5 and y < 7,
"Robot position was set to %r, "
"which is not in [0, 5), [0, 7)" %
((p.get_x(), p.get_y()),))
self.assertTrue(0 <= d < 360,
"Robot direction was set to %r, "
"which is not in [0, 360)" % (d,))
def testRobot(self):
"Test SimpleRobot"
pos_buckets = {}
dir_buckets = {}
skip_pos_distribution_test = False
for m in range(7000):
r, robots = self.createRoomAndRobots(4)
for r in robots:
p = r.get_robot_position()
d = r.get_robot_direction()
try:
x, y = p.get_x(), p.get_y()
except AttributeError:
self.fail("get_robot_position returned %r which is not a Position" % (p,))
self.assertTrue(0 <= x <= 5 and 0 <= y <= 7,
"Robot position was set to %r, "
"which is not in [0, 5), [0, 7)" %
((p.get_x(), p.get_y()),))
self.assertTrue(0 <= d <= 360,
"Robot direction was set to %r, "
"which is not in [0, 360)" % (d,))
x0, y0 = int(p.get_x()), int(p.get_y())
pos_buckets[(x0, y0)] = pos_buckets.get((x0, y0), 0) + 1
dir_buckets[int(d / 10)] = dir_buckets.get(int(d / 10), 0) + 1
# Test that positions are correctly distributed
if not skip_pos_distribution_test:
for t in xyrange(5, 7):
num_in_bucket = pos_buckets.get(t, 0)
self.assertTrue(
685 < num_in_bucket < 915,
"The distribution of positions on new Robot objects "
"looks incorrect (it should be uniform)")
# Test that directions are correctly distributed
for t in range(36):
num_in_bucket = dir_buckets.get(t, 0)
self.assertTrue(
658 < num_in_bucket < 898,
"The distribution of positions from get_random_position "
"looks incorrect (it should be uniform)")
def test_update_pos_and_cleanSimpleRobot(self):
"Test SimpleRobot.update_pos_and_clean"
r = ps3.iRoom(3, 5, 1)
robot = ps3.SimpleRobot(r, 1.0, 1)
robot.set_robot_position(ps3.Position(1.5, 2.5))
robot.set_robot_direction(90)
robot.update_pos_and_clean()
self.assertEqual(robot.get_robot_direction(), 90,
"Robot direction is updated incorrectly by update_pos_and_clean: expected %r, got %r" %
(90, robot.get_robot_direction()))
# check if robot position is valid
robotPos = robot.get_robot_position()
correctPos = ps3.Position(2.5, 2.5)
self.assertTrue(robotPos.get_x() == correctPos.get_x() and robotPos.get_y() == correctPos.get_y(),
"Robot position is updated incorrectly by update_pos_and_clean: expected %r, got %r" %
(ps3.Position(2.5, 2.5), robot.get_robot_position()))
self.assertTrue(2>=r.get_num_cleaned_tiles() >= 1,
"update_pos_and_clean should have marked one or two tiles as clean")
self.assertTrue(r.is_tile_cleaned(1, 2) or r.is_tile_cleaned(2, 2),
"update_pos_and_clean should have marked either (1, 2) or (2, 2) as clean")
# Simulate a lot of time passing...
for i in range(20):
robot.update_pos_and_clean()
self.assertTrue(r.is_position_in_room(robot.get_robot_position()),
"Robot position %r is not in room!" % (robot.get_robot_position(),))
self.assertNotEqual(robot.get_robot_direction(), 90,
"Robot direction should have been changed in update_pos_and_clean")
self.assertTrue(r.get_num_cleaned_tiles() >= 1,
"update_pos_and_clean should have marked another tile as clean")
"""The SIMULATION_TIME_LIMIT, SimulationThread class and SimulationTester class
are all designed to help test various simulations for problems 4 and 5
Right now there is no testing for the FurnishedRoom simulation, because the
furniture is set up randomly. In future psets it may make sense to manually
empirically establish reasonable simulation bounds for specified furniture
setups. If the student has implemented the FurnishedRoom methods correctly
and passes the tests for SimpleRobot and iRoom, there should not be any
additional issue.
"""
SIMULATION_TIME_LIMIT = 75.0
class SimulationThread(threading.Thread):
def __init__(self, *args):
threading.Thread.__init__(self)
self.result = None
self.exception_info = None
self.args = args
def run(self):
try:
self.result = ps3.run_simulation(*self.args)
except Exception:
self.exception_info = sys.exc_info()
def getResult(self):
return self.result
def getExceptionInfo(self):
return self.exception_info
class SimulationTester(unittest.TestCase):
def run_simulation(self, bounds, parameters):
"""
Tests ps3.run_simulation. The number of time-steps
ps3.run_simulation takes must fall between any of
the (LOWER, UPPER) bound tuples inside bounds.
ps3.run_simulation must also finish within a timelimit
to be considered passing. Threads are used to time
a simulation.
bounds: tuple of (lower, upper) bounds on the number of
steps a simulation should take.
parameters: parameters to be passed into ps3.run_simulation
"""
thr = SimulationThread(*parameters)
# Set daemon flag, so we can quit the test even if simulation threads
# are still running
thr.setDaemon(True)
thr.start()
# Allow SIMULATION_TIME_LIMIT seconds for test to finish
thr.join(SIMULATION_TIME_LIMIT)
if thr.isAlive():
self.fail("Simulation took too long (more than %d seconds)" %
SIMULATION_TIME_LIMIT)
elif thr.getExceptionInfo():
self.fail("Exception occurred in simulation thread:\n\n%s" %
"".join(traceback.format_exception(*thr.getExceptionInfo())))
else:
actual = thr.getResult()
intervals_str = " or ".join([("[%.1f, %.1f]" % b) for b in bounds])
self.assertTrue(
any([LB < actual < UB for LB, UB in bounds]),
"Simulation output was outside of 99.7%% confidence interval!\n"
"Robots: %d; Speed: %.1f; Capacity: %d; Dimensions: %dx%d; "
"Dirt Amount: %d; Coverage: %.2f; Trials: %d; Robot type: %r\n"
"Actual output: %r; acceptable intervals: %s"
% (parameters + (actual, intervals_str)))
class ps3_P5_Simple(SimulationTester):
"""test the simulation time cleaning the iRoom with a SimpleRobot"""
def testSimulation1(self):
"Test cleaning 100% of a 5x5 room"
try:
self.run_simulation(((142, 174),), (1, 1.0, 1, 5, 5, 1, 1.0, 100, ps3.SimpleRobot))
except:
print ("Unexpected error:", sys.exc_info()[1])
raise
def testSimulation2(self):
"Test cleaning 75% of a 10x10 room (Simple Robot)"
self.run_simulation(((183, 198),), (1, 1.0, 1, 10, 10, 1, 0.75, 100, ps3.SimpleRobot))
def testSimulation3(self):
"Test cleaning 90% of a 10x10 room (Simple Robot)"
self.run_simulation(((298, 327),), (1, 1.0, 1, 10, 10, 1, 0.9, 100, ps3.SimpleRobot))
def testSimulation4(self):
"Test multiple robots (95% of a 20x20 room with 5 robots (Simple Robot))"
self.run_simulation(((289, 303),), (5, 1.0, 1, 20, 20, 1, 0.95, 100, ps3.SimpleRobot))
def testSimulation5(self):
"Test different speeds (90% of a 5x20 room with a robot of speed 0.2 (Simple Robot))"
self.run_simulation(((1095, 1228),), (1, 0.2, 1, 5, 20, 1, 0.9, 100, ps3.SimpleRobot))
def testSimulation6(self):
"Test multiple robots and different speeds (90% of a 10x10 room with 3 robots of speed 0.5 (Simple Robot))"
self.run_simulation(((155, 180),), (3, 0.5, 1, 10, 10, 1, 0.9, 100, ps3.SimpleRobot))
# new tests below here
def testSimulation7(self):
"Test cleaning 100% of a 5x5 room (Simple Robot, 5 dirt/tile, capcity = 3)"
self.run_simulation(((206, 266),(180, 240)), (1, 1.0, 3, 5, 5, 5, 1.0, 100, ps3.SimpleRobot))
def testSimulation8(self):
"Test cleaning 100% of a 5x5 room (Simple Robot, 6 dirt/tile, capacity = 3)"
self.run_simulation(((206, 266),(180, 240)), (1, 1.0, 3, 5, 5, 6, 1.0, 100, ps3.SimpleRobot))
def testSimulation9(self):
"""Test different speeds (90% of a 3x10 room with a robot of speed 0.2 (Simple Robot)),
capacity = 2, 6 dirt/tile"""
self.run_simulation(((387, 447),(384, 444)), (1, 0.2, 2, 3, 10, 6, 0.9, 100, ps3.SimpleRobot))
def testSimulation10(self):
"Test multiple robots (95% of a 10x10 room with 5 robots (Simple Robot)) capacity = 2, 6 dirt/tile"
self.run_simulation(((137, 198),(130, 190)), (5, 1.0, 2, 10, 10, 6, 0.95, 100, ps3.SimpleRobot))
def testSimulation11(self):
"""Test multiple robots and different speeds (90% of a 5x5 room with 3 robots of speed 0.5
(Simple Robot)), capacity = 2, 6 dirt/tile"""
self.run_simulation(((48, 108), (45, 104)), (3, 0.5, 2, 5, 5, 6, 0.9, 100, ps3.SimpleRobot))
class ps3_P5_OnSale(SimulationTester):
"""test the simulation time cleaning the iRoom with a OnSaleRobot"""
def testSimulation1(self):
"Test cleaning 100% of a 5x5 room with OnSaleRobot"
x = ps3.run_simulation(1, 1.0, 1, 5, 5, 1, 1.0, 100, ps3.OnSaleRobot)
self.assertTrue(237 <= x <= 295, "Simulation output was outside of 99.7% confidence interval!\n")
def testSimulation2(self):
"Test cleaning 75% of a 10x10 room with OnSaleRobot"
x = ps3.run_simulation(1, 1.0, 1, 10, 10, 1, 0.75, 100, ps3.OnSaleRobot)
self.assertTrue(217 <= x <=245, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n") #todo - look into this
def testSimulation3(self):
"Test cleaning 90% of a 10x10 room with OnSaleRobot"
x = ps3.run_simulation(1, 1.0, 1, 10, 10, 1, 0.9, 100, ps3.OnSaleRobot)
self.assertTrue(399 <= x <= 442, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation4(self):
"Test cleaning 100% of a 5x5 room with 2 OnSaleRobots"
x = ps3.run_simulation(2, 1.0, 2, 5, 5, 5, 1.0, 100, ps3.OnSaleRobot)
self.assertTrue(182 <= x <= 218, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation5(self):
"Test cleaning 75% of a 10x10 room with 4 OnSaleRobots"
x = ps3.run_simulation(4, 1.0, 3, 10, 10, 5, 0.75, 100, ps3.OnSaleRobot)
self.assertTrue(98 <= x <= 104, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation6(self):
"Test cleaning 90% of a 10x10 room with 5 OnSaleRobots"
x = ps3.run_simulation(5, 1.0, 3, 10, 10, 10, 0.9, 100, ps3.OnSaleRobot)
self.assertTrue(201 <= x <= 215, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
class ps3_P5_Breathtaking(SimulationTester):
"""test the simulation time cleaning the iRoom with a OnSaleRobot"""
def testSimulation1(self):
"Test cleaning 100% of a 5x5 room with BreathtakingRobot"
x = ps3.run_simulation(1, 1.0, 1, 5, 5, 1, 1.0, 100, ps3.BreathtakingRobot)
self.assertTrue(100 <= x <= 175, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation2(self):
"Test cleaning 75% of a 10x10 room with BreathtakingRobot"
x = ps3.run_simulation(1, 1.0, 1, 10, 10, 1, 0.75, 100, ps3.BreathtakingRobot)
self.assertTrue(105 <= x <=125, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation3(self):
"Test cleaning 90% of a 10x10 room with BreathtakingRobot"
x = ps3.run_simulation(1, 1.0, 1, 10, 10, 1, 0.9, 100, ps3.BreathtakingRobot)
self.assertTrue(170 <= x <=210, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation4(self):
"Test cleaning 100% of a 5x5 room with BreathtakingRobot"
x = ps3.run_simulation(2, 1.0, 2, 5, 5, 5, 1.0, 100, ps3.BreathtakingRobot)
self.assertTrue(95 <= x <=125, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation5(self):
"Test cleaning 75% of a 10x10 room with BreathtakingRobot"
x = ps3.run_simulation(4, 1.0, 3, 10, 10, 5, 0.75, 100, ps3.BreathtakingRobot)
self.assertTrue(50 <= x <=57, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
def testSimulation6(self):
"Test cleaning 90% of a 10x10 room with BreathtakingRobot"
x = ps3.run_simulation(5, 1.0, 3, 10, 10, 10, 0.9, 100, ps3.BreathtakingRobot)
self.assertTrue(100 <= x <=110, "Simulation output was outside of 99.7% confidence interval! Took " + str(x) + " steps\n")
if __name__ == "__main__":
suite = unittest.TestSuite()
# suite.addTest(unittest.makeSuite(ps3_P1A))
# suite.addTest(unittest.makeSuite(ps3_P1B))
# suite.addTest(unittest.makeSuite(ps3_P3))
# suite.addTest(unittest.makeSuite(ps3_P5_Simple))
# suite.addTest(unittest.makeSuite(ps3_P5_OnSale))
suite.addTest(unittest.makeSuite(ps3_P5_Breathtaking))
unittest.TextTestRunner(verbosity=3).run(suite)