Exemple #1
0
    def test_solution(self):
        ''' This one is a beauty (altough too complex for a unit test):

        We mock the builtin input method using a text file
        and in the end, we compare one or more results with the
        expected values from the output text file...
        '''
        solution = []
        with open('./tests/mocks/input/00.txt', 'r') as mock_input_file:
            mock_input = mock_input_file.read().split('\n')
            with patch('builtins.input', side_effect=mock_input):
                for (plateau, rover_position, commands) in Parser.read_input():
                    # print(plateau, rover_position, commands)
                    rover = Rover(plateau, rover_position)
                    for command in commands:
                        rover.execute(command)

                    rover_solution = '{} {} {}'.format(
                        rover.position.x, rover.position.y,
                        rover.position.direction.value)
                    solution.append(rover_solution)

        with open('./tests/mocks/output/00.txt', 'r') as mock_output_file:
            mock_output = mock_output_file.read().split('\n')
            self.assertEqual(solution, mock_output)
Exemple #2
0
 def test_object_instantiation(self):
     plateau = Plateau(x=10, y=10)
     position = Position(x=10, y=10, direction=Direction.NORTH)
     rover = Rover(plateau, position)
     self.assertIsInstance(rover, Rover)
Exemple #3
0
 def test_invalid_movement_out_of_boundaries(self):
     plateau = Plateau(x=10, y=10)
     position = Position(x=10, y=10, direction=Direction.NORTH)
     rover = Rover(plateau, position)
     rover.move_forward()
Exemple #4
0
 def test_rotation_right(self):
     plateau = Plateau(x=10, y=10)
     position = Position(x=10, y=10, direction=Direction.NORTH)
     rover = Rover(plateau, position)
     rover.rotate_right()
     self.assertEqual(rover.position.direction, Direction.EAST)
Exemple #5
0
 def test_invalid_object_instantiation_wrong_position_object(self):
     lateau = Plateau(x=10, y=10)
     position = (5, 5, 'n')
     rover = Rover(plateau, position)
Exemple #6
0
 def test_invalid_object_instantiation_wrong_plateau_object(self):
     lateau = (5, 5)
     position = Position(x=10, y=10, direction=Direction.NORTH)
     rover = Rover(plateau, position)
Exemple #7
0
from marsrovers.rover import Rover
from marsrovers.parser import Parser

if __name__ == '__main__':
    for (plateau, rover_position, commands) in Parser.read_input():
        # print(plateau, rover_position, commands)
        rover = Rover(plateau, rover_position)
        for command in commands:
            rover.execute(command)

        print(rover.position.x, rover.position.y,
              rover.position.direction.value)