def test_invalid_height(self): with self.assertRaises(ValueError) as e: width, height = 10, -1 plateau = Plateau(width, height) self.assertEqual(type(e.exception), ValueError) self.assertEqual(str(e.exception), "Invalid height: {}".format(height))
def test_invalid_width(self): with self.assertRaises(ValueError) as e: width, height = -1, 10 plateau = Plateau(width, height) self.assertEqual(type(e.exception), ValueError) self.assertEqual(str(e.exception), "Invalid width: {}".format(width))
def test_spin_right(self): plateau = Plateau(5, 5) position = Position(1, 2) initial_heading = 'N' rover = Rover(plateau, position, initial_heading) self.assertEqual(rover.heading, initial_heading) rover.spin_right() self.assertEqual(rover.heading, rover.DIRECTIONS[initial_heading]['R'])
def test___str__(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') self.assertEqual( str(rover), '{} {} {}'.format(rover.position.x, rover.position.y, rover.heading))
def test_move_east(self): plateau = Plateau(5, 5) position = Position(1, 2) heading = 'E' rover = Rover(plateau, position, heading) self.assertEqual(rover.position, position) res = rover.move() self.assertEqual(res, True) self.assertEqual(rover.position, Position(2, 2))
def test_process(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') rover.process('LMLMLMLMM') self.assertEqual(rover.position, Position(1, 3)) self.assertEqual(rover.heading, 'N')
def test_current_position(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') self.assertEqual( rover.current_position, '{} {} {}'.format(rover.position.x, rover.position.y, rover.heading))
def test_run_command_success(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') rover.run_command('L') self.assertEqual(rover.position, Position(1, 2)) self.assertEqual(rover.heading, 'W')
def move_not_available(self): plateau = Plateau(5, 5) position = Position(1, 8) initial_heading = 'N' rover = Rover(plateau, position, initial_heading) with self.assertRaises(Exception) as e: res = rover.move() self.assertEqual(type(e.exception), Exception) self.assertEqual(str(e.exception), "Move not available")
def test_run_command_unrecognized_command(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') command = 'A' with self.assertRaises(Exception) as e: rover.run_command(command) self.assertEqual(type(e.exception), Exception) self.assertEqual(str(e.exception), "Unrecognized command: {0}".format(command))
def test___str__(self): plateau = Plateau(5, 5) position = Position(1, 2) rover = Rover(plateau, position, 'N') self.assertEqual( str(rover.plateau), '0 0 0 0 0 0\n' '0 0 0 0 0 0\n' '0 0 0 0 0 0\n' '0 1 0 0 0 0\n' '0 0 0 0 0 0\n' '0 0 0 0 0 0\n')
def main(): plateau = Plateau(5, 5) position = Position(1, 2) # Create rover instance rovers = Rovers(plateau, position, Rovers.directions.get('N')) instructions = input('Enter Instructions:') rovers.validate_instruction(instructions) print(rovers) rovers.set_position(3, 3, Rovers.directions.get('E')) instructions_new = input('Enter New Instructions:') rovers.validate_instruction(instructions_new) print(rovers)
def main(): input_plateau = input().split() plateau_x, plateau_y = int(input_plateau[0]), int(input_plateau[1]) plateau = Plateau(plateau_x, plateau_y) rovers = [] while True: input_rover = input().split() if not input_rover: break rover_x, rover_y, heading = int(input_rover[0]), int( input_rover[1]), input_rover[2] position = Position(rover_x, rover_y) rover = Rover(plateau, position, heading) commands = input() rover.process(commands) rovers.append(rover) for rover in rovers: print(rover)
def test_move_available_east_inside(self): width, height = 10, 10 plateau = Plateau(width, height) position, heading = Position(5, 5), 'E' self.assertEqual(plateau.move_available(position, heading), True)
def test_valid(self): plateau = Plateau(7, 10) self.assertEqual(plateau.width - 1, 7) self.assertEqual(plateau.height - 1, 10)
def test_move_not_available_east_boundary(self): width, height = 10, 10 plateau = Plateau(width, height) position, heading = Position(10, 5), 'E' self.assertEqual(plateau.move_available(position, heading), False)