def test_parameters(self):
        # Create asteroid
        x, y = 15, 25
        asteroid = Asteroid(x, y)

        # Create obstacles
        x_a, y_a = 10, 10
        obstacle = Obstacle(x_a, y_a)

        # Add obstacle to Asteroid
        asteroid.add_obstacle(obstacle)
        assert asteroid.get_obstacle_count() == 1

        # Create robot
        direction = "E"
        robot = Robot(x, y, asteroid, direction)

        # Check robot/asteroid/obstacle creation
        assert robot.x == 15
        assert robot.y == 25
        assert robot.direction == direction
        assert robot.asteroid == asteroid
        robot.set_direction("N")
        assert robot.direction == "N"
        assert obstacle.x == 10
        assert obstacle.y == 10
Пример #2
0
 def setup(self):
     self.x, self.y = 10, 15
     self.asteroid = Asteroid(self.x, self.y)
     self.obstacle = Obstacle(self.x_obstacle, self.y_obstacle,
                              self.asteroid)
     self.direction = 'N'
     self.robot.x, self.robot.y = 3, 4
     self.robot = Robot(self.x, self.y, self.direction, self.asteroid)
Пример #3
0
 def setup(self):
     self.a, self.b = 10, 15
     self.asteroid = Asteroid(self.a, self.b)
     self.x_obstacle, self.y_obstacle = 7, 11
     self.obstacle = Obstacle(self.x_obstacle, self.y_obstacle,
                              self.asteroid)
     self.x, self.y = 5, 10
     self.direction = "N"
 def test_check_if_robot_on_asteroid(self, asteroid_size,
                                     robot_obstacle_coordinates):
     obstacle = Obstacle(*robot_obstacle_coordinates)
     asteroid = Asteroid(*asteroid_size)
     robot = Robot(*robot_obstacle_coordinates, asteroid, "W")
     with pytest.raises(MissAsteroidError):
         asteroid.check_obstacle_position(obstacle)
         robot.check_position_on_asteroid()
     with pytest.raises(ObstacleCrashError):
         asteroid.add_obstacle(obstacle)
         robot.check_for_block()
Пример #5
0
 def test_parameters(self):
     x, y = 10, 15
     asteroid = Asteroid(x, y)
     x_obstacle, y_obstacle = 5, 6
     obstacle = Obstacle(x_obstacle, y_obstacle, asteroid)
     direction = 'N'
     robot = Robot(x, y, asteroid, direction, obstacle)
     assert robot.x == 10
     assert robot.y == 15
     assert robot.direction == direction
     assert robot.asteroid == asteroid
     assert robot.obstacle == obstacle
 def test_move_forward(self, current_direction, current_x, current_y,
                       expected_x, expected_y):
     obstacle = Obstacle(expected_x, expected_y)
     self.asteroid.add_obstacle(obstacle)
     robot = Robot(current_x, current_y, self.asteroid, current_direction)
     robot.move_forward()
     assert robot.x == expected_x and robot.y == expected_y
     # Check if it try to falls from asteroid during movement or get obstacle
     with pytest.raises(MissAsteroidError):
         robot.check_position_on_asteroid()
     with pytest.raises(ObstacleCrashError):
         robot.check_for_block()
class Test_robot_scan_ability:
    asteroid = Asteroid(4, 4)
    asteroid.add_obstacle(Obstacle(0, 3))
    asteroid.add_obstacle(Obstacle(4, 3))
    asteroid.add_obstacle(Obstacle(2, 0))
    asteroid.add_obstacle(Obstacle(2, 1))
    asteroid.add_obstacle(Obstacle(2, 4))
    asteroid.add_obstacle(Obstacle(1, 1))
    robot = Robot(2, 3, asteroid, "S")
    # map of the asteroid 5x5.
    # legend: 0 - valley; 1 - obstacle; 2 - robot position
    map = np.array([[0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [1, 1, 0, 2, 1],
                    [0, 0, 0, 0, 0], [0, 0, 0, 1, 0]], 'i')

    def test_spatial_scan(self):
        # This method is test scanned asteroid map creation
        self.robot.scan_create_map()
        assert np.array_equal(self.robot.aster_map, self.map)

    def test_get_obstacle_on_view_direction(self):
        # This method is test finding of obstacles
        self.robot.set_direction("S")
        assert self.robot.get_obstacle_on_view_direction() == [(0, 3)]
        self.robot.set_direction("N")
        assert self.robot.get_obstacle_on_view_direction() == [(4, 3)]
        self.robot.set_direction("E")
        assert self.robot.get_obstacle_on_view_direction() == [(2, 0), (2, 1)]
        self.robot.set_direction("W")
        assert self.robot.get_obstacle_on_view_direction() == [(2, 4)]
Пример #8
0
 def test_parameters(self):
     a, b = 20, 20
     asteroid = Asteroid(a, b)
     x_obstacle, y_obstacle = 7, 11
     obstacle = Obstacle(x_obstacle, y_obstacle, asteroid)
     x, y = 10, 15
     direction = "N"
     robot = Robot(x, y, asteroid, direction, obstacle)
     assert robot.x == 10
     assert robot.y == 15
     assert robot.direction == direction
     assert robot.asteroid == asteroid
     assert robot.obstacle == obstacle
Пример #9
0
 def test_check_if_obstacle_on_asteroid(self, asteroid_size,
                                        obstacle_coordinates):
     with pytest.raises(ObstacleError):
         asteroid = Asteroid(*asteroid_size)
         Obstacle(*obstacle_coordinates, asteroid)
Пример #10
0
 def test_check_if_robot_on_asteroid(self, asteroid_size, robot_coordinates,
                                     obstacle_coordinates):
     with pytest.raises(MissAsteroidError):
         asteroid = Asteroid(*asteroid_size)
         obstacle = Obstacle(*obstacle_coordinates, asteroid)
         Robot(*robot_coordinates, asteroid, 'W', obstacle)
Пример #11
0
 def test_robot_movement_problems(self, current_position, expected_position,
                                  obstacle_position):
     with pytest.raises(RobotMovementError):
         obstacle = Obstacle(*obstacle_position)
         Robot(*expected_position, obstacle, 'N')
 def setup(self):
     self.asteroid = Asteroid(15, 15)
     self.obstacle = Obstacle(10, 10, self.asteroid)
 def test_check_if_robot_on_obstacle(self, robot_coordinates, obstacle_coordinates):
     with pytest.raises(ObstacleCrashError):
         obstacle = Obstacle(*obstacle_coordinates, self.asteroid)
Пример #14
0
 def test_check_if_obstacle_on_asteroid(self, asteroid_size,
                                        obstacle_position):
     with pytest.raises(ObstaclePositionError):
         asteroid = Asteroid(*asteroid_size)
         Obstacle(*obstacle_position, asteroid)
Пример #15
0
 def test_check_if_robot_on_asteroid(self, asteroid_size, robot_coordinates,
                                     obstacle_position):
     with pytest.raises(OutsideAsteroidError):
         asteroid = Asteroid(*asteroid_size)
         obstacle = Obstacle(*obstacle_position, asteroid)
         Robot(*robot_coordinates, asteroid, "W", obstacle)