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
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)
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"])
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)
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)