Exemplo n.º 1
0
    def start_action(self, instructions: str, position: RoverPosition):

        for instruction in instructions:
            if instruction == "M":
                position.coordinates = self.__movingController.moveAStep(
                    position.coordinates, position.direction)
            else:
                position.direction = self.__spiningController.spin(
                    instruction, position.direction)

        return position
Exemplo n.º 2
0
def testExploringWithMoving(get_plateau, x, y, direction, expected_x,
                            instructions, expected_y, expected_direction):
    rover = Rover(RoverPosition(RoverCoordinates(x, y), direction))
    rover.explorePlateau(instructions)
    assert (rover.position.coordinates.x
            == expected_x) and (rover.position.coordinates.y
                                == expected_y) and (rover.position.direction
                                                    == expected_direction)
Exemplo n.º 3
0
    def __getRoverPosition(self, roverPosition: str):
        """
        Get the rover position if its syntax respects Input Regex for rover Position : x y D
        :param a string of rover position
        :return: a RoverPosition
        """
        matched = re.match("(?P<x>[0-9]+?) *(?P<y>[0-9]+?) *(?P<D>[NESW]{1}?) *$", roverPosition)
        if not bool(matched):
            raise RoverPositionInputException(roverPosition)

        result = matched.groupdict()
        return RoverPosition(RoverCoordinates(int(result["x"]), int(result["y"])), result["D"])
Exemplo n.º 4
0
def testRoversCollision(get_plateau, x, y, direction, instructions):
    Plateau.getInstance().addRover(
        Rover(RoverPosition(RoverCoordinates(1, 1), "N")))
    with pytest.raises(NextSpotNotEmptyException):
        rover = Rover(RoverPosition(RoverCoordinates(x, y), direction))
        rover.explorePlateau(instructions)
Exemplo n.º 5
0
def testMoveOutsidePlateau(get_plateau, x, y, direction, expected_x,
                           instructions, expected_y, expected_direction):
    with pytest.raises(RoverOutsidePlateauException):
        rover = Rover(RoverPosition(RoverCoordinates(x, y), direction))
        rover.explorePlateau(instructions)