def test_go_with_instructions( self, heading, position, instruction, expected_position, expected_heading ): rover = Rover(heading, position, (5, 5)) rover = rover.go(instruction) self.assertEqual(rover.position, expected_position) self.assertEqual(rover.heading, expected_heading)
def main(args): parser = argparse.ArgumentParser(description="") parser.add_argument("path", help="path of file") args = parser.parse_args(args) file = args.path if not os.path.isfile(file): print("The path specified does not exist or is not a file") sys.exit() with open(file, "r") as reader: plateau = parse_plateau(reader.readline()) for line1, line2 in itertools.zip_longest(*[reader] * 2): position, heading = parse_position(line1) instructions = parse_instructions(line2) rover = Rover(heading=heading, position=position, plateau=plateau) rover = rover.go(instructions) print(f"{rover.position[0]} {rover.position[1]} {rover.heading}")
def test_invalid_commands(self, invalid_command): with self.assertRaises(KeyError): rover = Rover("N", (0, 0), (5, 5)) rover.do_command(invalid_command)
def test_do_commands(self, command, expected_heading, expected_position): rover = Rover("N", (0, 0), (5, 5)) rover = rover.do_command(command) self.assertEqual(rover.position, expected_position) self.assertEqual(rover.heading, expected_heading)
def test_move_out_of_bounds(self, heading, position): with self.assertRaises(ValueError): rover = Rover(heading, position, (5, 5)) rover.go("M") x = 0
def test_move_forward(self, heading, expected_position): rover = Rover(heading, (3, 3), (5, 5)) rover = rover.move() self.assertEqual(rover.position, expected_position)
def test_turn_right(self, heading, expected_heading): rover = Rover(heading, (0, 0), (5, 5)) rover = rover.rotate_right() self.assertEqual(rover.heading, expected_heading)