def test_does_ball_hit_wall_5(self): """ Base case: 2 walls, one hits. """ lines = set([Line(6, 9, 9, 2), Line(2, 0, 9, 6)]) ball = Ball(2, 1, 1) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_3(self): """ Corner case: normal ball just hits a wall. """ lines = set([Line(3, 3, 3, 0)]) ball = Ball(0, 1.5, 3) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_4(self): """ Base case: 2 walls, no hit. """ lines = set([Line(6, 9, 9, 2), Line(2, 0, 9, 6)]) ball = Ball(11, 12, 1) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == False)
def test_does_ball_hit_wall_9(self): """ Corner case: Does not hit but would do so if the line were longer v3. """ lines = set([Line(1, 5, 1, 4)]) ball = Ball(1, 0, 1) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == False)
def test_does_ball_hit_wall_2(self): """ Base case: normal ball does not hit a wall. """ lines = set([Line(0, 3, 3, 0)]) ball = Ball(0, 0, 1) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == False)
def test_does_ball_hit_wall_1(self): """ Base case: normal ball hits normal wall. """ lines = set([Line(0, 3, 3, 0)]) ball = Ball(0, 0, 2.5) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_6(self): """ Corner case: endpoints of line are far away. """ lines = set([Line(0, 0, 10, 10)]) ball = Ball(5, 5, 1) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_12(self): """ Corner case: Hits, both points of line right of ball center. """ lines = set([Line(100, 200, 100, 0)]) ball = Ball(99, 100, 3) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_13(self): """ Corner case: coordinates line points all smaller than ball coordinate values (of respective dims). """ lines = set([Line(3, 0, 0, 3)]) ball = Ball(3, 3, 5.5) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == True)
def test_does_ball_hit_wall_14(self): """ Corner case: Does not hit but would do so if the line were longer v5: One point bigger y and one point smaller y than ball. """ lines = set([Line(0, 99.9, 95, 100.1)]) ball = Ball(100, 100, 4) layout = MazeLayout(lines, START_DUMMY, END_DUMMY, SIZE_DUMMY) assert (layout.does_ball_hit_wall(ball) == False)
def test_moving_wall_detection_5(self): """ Base case: does not hit wall with center of ball. """ start = np.array([3, 3]) end = np.array([100, 100]) walls = set([Line(0, 10, 1, 10)]) layout = MazeLayout(walls, start, end, self.size) self.model.reset(layout) self.model.set_acceleration(0, 1) self.assertTrue(self.model.make_timestep()) # position becomes (3, 4) self.model.set_acceleration(0, 0) self.assertTrue(self.model.make_timestep()) # position becomes (3, 5) self.assertTrue(self.model.make_timestep()) # position becomes (3, 6) self.assertTrue(self.model.make_timestep()) # position becomes (3, 7) self.assertTrue(self.model.make_timestep()) # position becomes (3, 8) self.assertTrue(self.model.make_timestep()) # position becomes (3, 9) self.assertFalse( self.model.make_timestep()) # position becomes (3, 10) # Next one still hits at start of timestep! self.assertFalse( self.model.make_timestep()) # position becomes (3, 11) self.assertTrue(self.model.make_timestep())
def setUp(self): self.size = Size(10000, 10000) self.ball_rad = 1 self.start = np.array([50, 50]) self.layout = MazeLayout(set([]), self.start, np.array([99, 99]), self.size) self.model = Model(self.size, self.ball_rad) self.model.reset(self.layout)
def test_check_valid_lines_1(self): """ Base case: Lines fit in size. """ lines = set([Line(0, 3, 3, 0), Line(0, 9, 0, 9), Line(1, 2, 3, 4)]) size = Size(10, 10) # Fails if error is raised. layout = MazeLayout(lines, START_DUMMY, END_DUMMY, size)
def test_collision_boundary_1(self): """ Sanity check: No wall hit. """ layout = MazeLayout(set([]), np.array([2, 2]), np.array([9, 9]), self.size) self.model.reset(layout) assert (self.model.does_ball_hit_wall() == False)
def test_collision_wall_1(self): """ Sanity check: No wall hit, minimal distance. """ wall1 = Line(4, 0, 4, 99) wall2 = Line(0, 4, 99, 4) layout = MazeLayout(set([wall1, wall2]), np.array([2, 2]), np.array([99, 99]), self.size) self.model.reset(layout) assert (self.model.does_ball_hit_wall() == False)
def test_collision_wall_5(self): """ Base case: hit below, without movement. """ wall = Line(0, 4, 99, 4) layout = MazeLayout(set([wall]), np.array([2, 3]), np.array([99, 99]), self.size) self.model.reset(layout) # With pos (2, 3) and with rad=1 the ball will be touching the wall. assert (self.model.does_ball_hit_wall() == True)
def test_collision_boundary_7(self): """ Corner case (literally): diagonal movement (hit two at same time). """ layout = MazeLayout(set([]), np.array([2, 2]), np.array([9, 9]), self.size) self.model.reset(layout) self.model.set_acceleration(-1, -1) # New pos ball becomes (1, 1), and with rad=1 it will touch the border. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_collision_boundary_6(self): """ Corner case: completely off room boundary. """ layout = MazeLayout(set([]), np.array([8, 8]), np.array([9, 9]), Size(10, 10)) self.model.reset(layout) self.model.set_acceleration(100, 100) # Will instantaneously fly from screen. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_collision_boundary_5(self): """ Base case: bottom boundary. """ layout = MazeLayout(set([]), np.array([8, 8]), np.array([9, 9]), Size(10, 10)) self.model.reset(layout) self.model.set_acceleration(0, 1) # New pos ball becomes (8, 9), and with rad=1 it will touch the border. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_collision_boundary_3(self): """ Base case: top boundary. """ layout = MazeLayout(set([]), np.array([2, 2]), np.array([9, 9]), self.size) self.model.reset(layout) self.model.set_acceleration(0, -1) # New pos ball becomes (2, 1), and with rad=1 it will touch the border. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_collision_end_1(self): """ Sanity check: not at end """ layout = MazeLayout(set([]), np.array([2, 2]), np.array([99, 99]), self.size) self.model.reset(layout) self.model.set_acceleration(1, 1) # New pos ball becomes (3, 3), still far from (99, 99). self.model.make_timestep() assert (self.model.is_ball_at_finish() == False)
def test_collision_wall_3(self): """ Base case: hit below. """ wall = Line(0, 4, 99, 4) layout = MazeLayout(set([wall]), np.array([2, 2]), np.array([99, 99]), self.size) self.model.reset(layout) self.model.set_acceleration(0, 1) # New pos ball becomes (2, 3), and with rad=1 it will touch the wall. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_moving_wall_detection_3(self): """ Base case: does collide heads-on. """ start = np.array([5, 5]) end = np.array([100, 100]) walls = set([Line(10, 0, 10, 10)]) layout = MazeLayout(walls, start, end, self.size) self.model.reset(layout) self.model.set_acceleration(5, 0) self.assertFalse( self.model.make_timestep()) # position becomes (10, 5)
def test_collision_wall_4(self): """ Corner case: hit two walls at once. """ wall1 = Line(4, 0, 4, 99) wall2 = Line(0, 4, 99, 4) layout = MazeLayout(set([wall1, wall2]), np.array([2, 2]), np.array([99, 99]), self.size) self.model.reset(layout) self.model.set_acceleration(1, 1) # New pos ball becomes (3, 3), and with rad=1 it will touch the walls. self.model.make_timestep() assert (self.model.does_ball_hit_wall() == True)
def test_moving_wall_detection_4(self): """ Corner case: does collide heads-on, but sufficient high speed to end up beyond the wall in one step. """ start = np.array([5, 5]) end = np.array([100, 100]) walls = set([Line(10, 0, 10, 10)]) layout = MazeLayout(walls, start, end, self.size) self.model.reset(layout) self.model.set_acceleration(10, 0) self.assertFalse( self.model.make_timestep()) # position becomes (15, 5) self.assertTrue(self.model.make_timestep()) # far from wall now.
def test_collision_end_2(self): """ Base case: ball reaches end """ layout = MazeLayout(set([]), np.array([2, 2]), np.array([7, 2]), self.size) self.model.reset(layout) self.model.set_acceleration(2, 0) # New pos ball becomes (4, 2), not hit end yet. self.model.make_timestep() assert (self.model.is_ball_at_finish() == False) self.model.set_acceleration(0, 0) # New pos ball becomes (6, 2), with rad=1 does hit it. self.model.make_timestep() assert (self.model.is_ball_at_finish() == True)
def test_check_valid_lines_5(self): """ Base case: Lines do not fit in size -- y too big. """ lines = set([ Line(0, 3, 3, 0), Line(0, 9, 0, 11), Line(5, 5, 3, 9), Line(1, 2, 3, 4) ]) size = Size(10, 10) try: layout = MazeLayout(lines, START_DUMMY, END_DUMMY, size) self.fail() except ValueError: pass
def test_moving_wall_detection_1(self): """ Sanity check: no walls to collide with. """ start = np.array([5, 5]) end = np.array([100, 100]) walls = set([]) layout = MazeLayout(walls, start, end, self.size) self.model.reset(layout) self.model.set_acceleration(1, 1) self.assertTrue(self.model.make_timestep()) # position becomes (6, 6) self.model.set_acceleration(0, 0) for x in range(self.size.x - self.ball_rad - 1 - 6): self.assertTrue(self.model.make_timestep()) # Should have reached end of rectangle now. self.assertFalse(self.model.make_timestep())
def test_moving_wall_detection_2(self): """ Base case: does not collide with a wall. """ start = np.array([5, 5]) end = np.array([100, 100]) walls = set([Line(0, 0, 1, 1009), Line(100, 1000, 101, 1002)]) layout = MazeLayout(walls, start, end, self.size) self.model.reset(layout) self.model.set_acceleration(1, 1) self.assertTrue(self.model.make_timestep()) # position becomes (6, 6) self.model.set_acceleration(0, 0) for _ in range(self.size.x - self.ball_rad - 1 - 6): self.assertTrue(self.model.make_timestep()) # Should have reached end of rectangle now. self.assertFalse(self.model.make_timestep())