def test_moves_forward(
     self,
     direction: Direction,
     initial_coordinates: Coordinates,
     final_coordinates: Coordinates,
 ) -> None:
     rover = Rover(Position(direction, initial_coordinates))
     rover.move_forward()
     assert rover.position() == Position(direction, final_coordinates)
Beispiel #2
0
class MarsRoverApplication:

    @classmethod
    def landing_with(cls, rover_position: str) -> 'MarsRoverApplication':
        try:
            return cls(PositionFormat().position_from(rover_position))
        except RoverOutsideSurface:
            raise UserInputError.rover_outside_surface()

    def __init__(self, position: Position) -> None:
        self._rover = Rover(position)

    def rover_position(self) -> str:
        return PositionFormat().output_from(self._rover.position())

    def execute(self, command: str) -> None:
        if command == 'f':
            self._rover.move_forward()
        elif command == 'b':
            self._rover.move_backward()
        elif command == 'r':
            self._rover.turn_right()
        elif command == 'l':
            self._rover.turn_left()
        else:
            raise UserInputError.unknown_command(command)
 def test_can_not_land_outside_of_the_surface(
         self, coordinates: Coordinates) -> None:
     with pytest.raises(RoverOutsideSurface):
         Rover(Position(Direction.north(), coordinates))
 def test_turns_left(self, initial_direction: Direction,
                     final_direction: Direction) -> None:
     rover = Rover(Position(initial_direction, Coordinates(3, 3)))
     rover.turn_left()
     assert rover.position() == Position(final_direction, Coordinates(3, 3))
 def test_does_not_move_backward_outside_the_surface(
         self, position: Position) -> None:
     rover = Rover(position)
     rover.move_backward()
     assert rover.position() == position
Beispiel #6
0
 def __init__(self, position: Position) -> None:
     self._rover = Rover(position)