def test_reader_wrong_input(self):
		"""
		Test if reader avoids wrong input and don't
		crash.
		"""

		filename = TestReaderReadRoverStartingPosition.file_path + "test_reader_wrong_input.txt"

		with reader.Reader(filename) as r:
			self.assertRaises(ValueError, r.read_upper_right_coordinates)
	def test_reader_valid_filename(self):
		"""
		Test if reader can open a file correctly.
		"""

		filename = TestReader.file_path + "test_init_filename.txt"

		with reader.Reader(filename) as r:
			pass

		self.assertIsNotNone(r.file)
	def test_reader_read_direction(self):
		"""
		Test if reader gets correct direction from
		a file that contains 3 1 N information.
		"""

		filename = TestReaderReadRoverStartingPosition.file_path + "test_reader_rover_pos.txt"

		with reader.Reader(filename) as r:
			x_coord, y_coord, direction = r.read_rover_starting_position()
		self.assertEqual(direction, 'N')
    def test_reader_read_command_line(self):
        """
		Test if reader gets correct command list
		from a file that contains ABCDEF information.
		"""

        filename = TestReaderReadRoverCommands.file_path + "test_reader_commands.txt"

        with reader.Reader(filename) as r:
            commands = r.read_rover_commands()

        self.assertEqual(commands, ['A', 'B', 'C', 'D', 'E', 'F'])
    def test_reader_read_one_input(self):
        """
		Test if reader get correct command from file
		with only one command: A.
		"""

        filename = TestReaderReadRoverCommands.file_path + "test_reader_one_input.txt"

        with reader.Reader(filename) as r:
            commands = r.read_rover_commands()

        self.assertEqual(commands, ['A'])
    def test_reader_read_empty_line(self):
        """
		Test if reader gets empty list if
		line has zero commands.
		"""

        filename = TestReaderReadRoverCommands.file_path + "test_reader_zero_input.txt"

        with reader.Reader(filename) as r:
            commands = r.read_rover_commands()

        self.assertEqual(commands, [])
    def test_has_rover_simulation_not_found(self):
        """
		Test if reader correctly peeks next line of
		input file to check if there is still content
		and fails.
		"""

        filename = TestReaderHasRoverSim.file_path + "test_2_line_file.txt"

        with reader.Reader(filename) as r:
            # read a couple of lines
            _ = r.file.readline()
            _ = r.file.readline()

            self.assertEqual(r.has_rover_simulation(), False)
    def init_controller_for_test(self):
        """
		(TestControllerDoCommand) -> Controller

		TestControllerDoCommand auxiliar method to avoid duplicate of code.
		This inits x_limit and y_limit to 5.
		"""
        filename = TestControllerDoCommand.file_path + "test_real_input.txt"

        c = controller.Controller(filename)

        with reader.Reader(c.filename) as r:
            c.x_limit, c.y_limit = r.read_upper_right_coordinates()

        return c
Exemplo n.º 9
0
    def run(self):
        """(Controller) -> NoneType

		Executes all lines of input file.
		>>> cat input.txt
		5 5
		1 2 N
		LMLMLMLMM
		>>> c = Controller("input.txt")
		>>> c.run()
		1 3 N
		"""

        with reader.Reader(self.filename) as r:
            self.x_limit, self.y_limit = r.read_upper_right_coordinates()
            while r.has_rover_simulation():
                rover_starting_position = r.read_rover_starting_position()
                m_rover = rover.Rover(rover_starting_position)
                commands = r.read_rover_commands()
                for command in commands:
                    self.do_command(m_rover, command)
                print(self.format_position(m_rover.get_position()))