Beispiel #1
0
    def processFile(self, file_path):
        """
            Return an Output file with current Position
        :param str file_path: Folder path of Input File
        :return: Generates Output File with current Position of Rover.
        :raises InputReaderError: if input file instruction is not valid
        :raises Exception: if any error is generated
        """



        rovers_current_poistion= []
        reader = InputReader()

        # Read Input File and create a list of instruction to be executed for each Rover
        # in list of rovers
        set_of_instructions = reader.readFile(file_path)
        for instruction in set_of_instructions.roverInstructions:
            #create rover object for 1 rover
            rover = Rover(set_of_instructions.plateau, instruction.initialPosition)
            # run instruction commands for selected rover
            rover.processCommands(instruction.movementCommands)
            # Append final position of rover in output list
            rovers_current_poistion.append(rover.currentPosition.toString())

        return rovers_current_poistion
 def processFile(self, filePath: str, parser: Parser):
     try:
         setOfInstructions = parser.parseFile(filePath)
         for instruction in setOfInstructions.roverInstructions:
             rover = Rover(setOfInstructions.plateau,
                           instruction.initialPosition)
             rover.processCommands(instruction.movementCommands)
             print(rover.currentPosition.toString())
     except ParsingError as error:
         print(error)
     except ValueError as error:
         print(error)
Beispiel #3
0
 def test_RoverCanMoveToPosition(self):
     """
     test to check X- Y coordinates and Orientation changes when rover is given command to move
     :return:
     """
     # Given
     initialPosition = RoverPosition(2, 2, 'N')
     plateau = Plateau(5, 5)
     movementCommands = ['M','R','M','L','M']
     rover = Rover(plateau, initialPosition)
     # When
     rover.processCommands(movementCommands)
     # Then
     expectedFinalPosition = '3 4 N'
     self.assertEqual(rover.currentPosition.toString() ,expectedFinalPosition)
Beispiel #4
0
    def test_CannotMoveRoverOutOfPlateau(self):
        """
        test to check validation error is raised when current X- Y coordinates of rover is
        outside plateau dimesnion
        :return:
                """
        # Given
        initialPosition = RoverPosition(2, 2, 'N')
        plateau = Plateau(3, 3)
        movementCommands = ['M', 'M', 'M']
        rover = Rover(plateau, initialPosition)
        # Then
        self.assertRaises(ValueError, rover.processCommands,  movementCommands)
        expected_error = 'rover cannot be driven out of plateau area'
        try:
            # check that correct error message is reported when plateau dimension is not correct
            rover.processCommands(movementCommands)
        except Exception as error:

            self.assertTrue(expected_error in str(error))