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 test_parameters(self):
     x, y = 10, 15
     asteroid = Asteroid(x, y)
     robot = Robot(x, y, asteroid)
     assert robot.x == 10
     assert robot.y == 15
     assert robot.asteroid == asteroid
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)]
 def test_turn_around(self):
     x, y = 10, 15
     asteroid = Asteroid(x + 1, y + 1)
     direction = "E"
     robot = Robot(x, y, asteroid, direction)
     robot.turn_around()
     assert robot.direction == "W"
Пример #5
0
 def test_check_if_robot_falls_from_asteroid(self, robot_direction,
                                             asteroid_size,
                                             robot_coordinates):
     with pytest.raises(RobotHasFallFromAsteroidError):
         asteroid = Asteroid(*asteroid_size)
         robot = Robot(*robot_coordinates, asteroid, *robot_direction)
         robot.move_forward()
Пример #6
0
 def test_check_if_robot_have_no_obstacles(self, direction, asteroid_size,
                                           current_position,
                                           expected_position,
                                           obstacle_position):
     with pytest.raises(ObstacleRobotError):
         asteroid = Asteroid(*asteroid_size)
         Robot(*expected_position, asteroid, direction, self.obstacle)
class TestTurns:
    x, y = 10, 15
    asteroid = Asteroid(x + 1, y + 1)

    @pytest.mark.parametrize(
        "current_direction,expected_direction",
        (
                ("N", "W"),
                ("W", "S"),
                ("S", "E"),
                ("E", "N"),
        )
    )
    def test_turn_left(self, current_direction, expected_direction):
        robot = Robot(self.x, self.y, self.asteroid, current_direction)
        robot.turn_left()
        assert robot.direction == expected_direction

    @pytest.mark.parametrize(
        "current_direction,expected_direction",
        (
                ("W", "N"),
                ("N", "E"),
                ("E", "S"),
                ("S", "W"),
        )
    )
    def test_turn_right(self, current_direction, expected_direction):
        robot = Robot(self.x, self.y, self.asteroid, current_direction)
        robot.turn_right()
        assert robot.direction == expected_direction
Пример #8
0
 def test_check_if_robot_do_not_fail_from_asteroid(self, direction,
                                                   asteroid_size,
                                                   current_position,
                                                   expected_position):
     with pytest.raises(OutsideAsteroidError):
         asteroid = Asteroid(*asteroid_size)
         Robot(*expected_position, asteroid, "W", self.obstacle)
 def test_turn_param(self, current_direction, expected_direction):
     x, y = 10, 15
     asteroid = Asteroid(x + 1, y + 1)
     robot = Robot(x, y, asteroid, "N")
     robot.direction = current_direction
     robot.turn_param()
     assert robot.direction == expected_direction
Пример #10
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)
 def test_if_robot_fell(self):
     x, y = 10, 15
     asteroid = Asteroid(x + 1, y + 1)
     robot = Robot(x, y, asteroid, "E")
     with pytest.raises(ValueError):
         robot.move_forward(100)
     with pytest.raises(ValueError):
         robot.move_backward(100)
Пример #12
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_move_backward(self, current_direction, current_x, current_y,
                        expected_x, expected_y):
     asteroid = Asteroid(5, 5)
     robot = Robot(current_x, current_y, asteroid, current_direction)
     assert current_x == robot.x and current_y == robot.y
     robot.move_backward()
     assert robot.x == expected_x and robot.y == expected_y
     with pytest.raises(MovementError):
         robot.check_robot_location()
Пример #14
0
 def test_parameters(self):
     x, y = 10, 15
     direction = "E"
     asteroid = Asteroid(x + 10, y + 10)
     robot = Robot(x, y, asteroid, direction)
     assert robot.x == 10
     assert robot.y == 15
     assert robot.asteroid == asteroid
     assert robot.direction == direction
Пример #15
0
class TestRobotMovement:
    x, y = 10, 15
    asteroid = Asteroid(x, y)

    @pytest.mark.parametrize("current_direction, expected_direction", (
        ("N", "W"),
        ("W", "S"),
        ("S", "E"),
        ("E", "N"),
    ))
    def test_turn_left(self, current_direction, expected_direction):
        robot = Robot(self.x, self.y, self.asteroid, current_direction)
        robot.turn_left()
        assert robot.direction == expected_direction

    @pytest.mark.parametrize("current_direction, expected_direction",
                             (("N", "E"), ("W", "N"), ("S", "W"), ("E", "S")))
    def test_turn_right(self, current_direction, expected_direction):
        robot = Robot(self.x, self.y, self.asteroid, current_direction)
        robot.turn_right()
        assert robot.direction == expected_direction

    @pytest.mark.parametrize(
        "current_direction, robot_coordinates, expected_coordinates", (
            ("N", (3, 20), (3, 21)),
            ("W", (-1, 6), (-2, 6)),
            ("S", (10, 0), (10, -1)),
            ("E", (10, 2), (11, 2)),
        ))
    def test_move_forward(self, current_direction, robot_coordinates,
                          expected_coordinates):
        robot = Robot(*robot_coordinates, self.asteroid, current_direction)
        robot.move_forward()
        assert (robot.x, robot.y) == expected_coordinates

        # check if robot falls from asteroid during movement
        with pytest.raises(RobotFallsFromAsteroidError):
            robot.check_robot_falls_from_asteroid()
            assert robot_coordinates == (robot.x, robot.y)

    @pytest.mark.parametrize(
        "current_direction, robot_coordinates, expected_coordinates", (
            ("N", (3, 20), (3, 19)),
            ("W", (10, 2), (11, 2)),
            ("S", (18, 45), (18, 46)),
            ("E", (0, 8), (-1, 8)),
        ))
    def test_move_backward(self, current_direction, robot_coordinates,
                           expected_coordinates):
        robot = Robot(*robot_coordinates, self.asteroid, current_direction)
        robot.move_backward()
        assert (robot.x, robot.y) == expected_coordinates

        # check if robot falls from asteroid during movement
        with pytest.raises(RobotFallsFromAsteroidError):
            robot.check_robot_falls_from_asteroid()
            assert robot_coordinates == (robot.x, robot.y)
 def test_parameters(self):
     x, y = 10, 15
     width = 40
     height = 40
     asteroid = Asteroid(width, height)
     direction = "W"
     robot = Robot(x, y, asteroid, direction)
     assert robot.x == 10
     assert robot.y == 15
     assert robot.asteroid == asteroid
     assert robot.direction == direction
    def test_parameters(self):
        x, y = 15, 25
        asteroid = Asteroid(x, y)

        direction = 'E'
        robot = Robot(x, y, asteroid, direction)

        assert robot.x == 15
        assert robot.y == 25
        assert robot.direction == direction
        assert robot.asteroid == asteroid
Пример #18
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
Пример #19
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
 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()
Пример #21
0
 def setup(self):
     self.x, self.y = 10, 15
     self.asteroid = Asteroid(self.x + 10, self.y + 10)
Пример #22
0
 def test_check_if_robot_on_asteroid(self, asteroid_size,
                                     robot_coordinates):
     with pytest.raises(MissAsteroidError):
         asteroid = Asteroid(*asteroid_size)
         Robot(*robot_coordinates, asteroid, "W")
def standard_asteroid():
    x, y = 5, 5
    return Asteroid(x, y)
Пример #24
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)
Пример #25
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)
 def setup(self):
     self.asteroid = Asteroid(15, 15)
     self.obstacle = Obstacle(10, 10, self.asteroid)
 def test_self_destroy(self):
     with pytest.raises(RobotCrashError):
         asteroid = Asteroid(15, 20)
class TestObstaclesMovement:

    def setup(self):
        self.asteroid = Asteroid(20, 20)
 def test_robot_fall_backward(self, current_direction, robot_coordinates, asteroid_size):
     with pytest.raises(RobotCrashError):
         asteroid = Asteroid(*asteroid_size)
def standard_robot():
    x, y = 3, 3
    asteroid = Asteroid(x, y)
    return Robot(x, y, asteroid, "N")