def test_rover_runner_goes_off_gird_south(self): grid = small_mars_with_one_rover_empty_commands.grid rover = Rover(0, 0, "S") tss = m.get_mocked_turn_command_selector_turn_right_from_north_command_only( ) mss = m.get_mocked_move_command_selector_south_command_only() rrs = RoverRunnerService(grid, rover, mss, tss) self.assertRaises(ValueError, rrs.run, ['M'])
def test_rover_runner_moves_rover_forward(self): grid = small_mars_with_one_rover_empty_commands.grid rover = small_mars_with_one_rover_empty_commands.rover_setups[0].rover tss = m.get_mocked_turn_command_selector_turn_left_from_north_command_only( ) mss = m.get_mocked_move_command_selector_north_command_only() rrs = RoverRunnerService(grid, rover, mss, tss) final_pos = rrs.run(['M']) self.assertEqual(Rover(0, 1, 'N'), final_pos)
def parse(commands): x, y = commands[0].upper().split() grid = Grid(int(x), int(y)) rover = None rover_setups = [] for idx, command in enumerate(commands[1:]): if idx % 2 == 0: rover_x, rover_y, direction = command.upper().split() rover = Rover(int(rover_x), int(rover_y), direction) else: rover_setups.append( RoverSetup(rover, [char for char in command.upper()])) return Mars(grid, rover_setups)
from data_objects import Rover rover_00N = Rover(0, 0, 'N') rover_00W = Rover(0, 0, 'W') rover_00S = Rover(0, 0, 'S') rover_00E = Rover(0, 0, 'E')
def test_turn_turns_rover_to_north(self): s = tc.TurnRightFromWestCommand() r = s.execute(rovers.rover_00W) self.assertEqual(Rover(0, 0, 'N'), r)
def test_turn_turns_rover_to_west(self): s = tc.TurnLeftFromNorthCommand() r = s.execute(rovers.rover_00N) self.assertEqual(Rover(0, 0, 'W'), r)
def test_turn_turns_rover_to_east(self): s = tc.TurnLeftFromSouthCommand() r = s.execute(rovers.rover_00S) self.assertEqual(Rover(0, 0, 'E'), r)
def test_turn_turns_rover_to_south(self): s = tc.TurnLeftFromWestCommand() r = s.execute(rovers.rover_00W) self.assertEqual(Rover(0, 0, 'S'), r)
def test_move_moves_rover_to_north(self): s = mc.MoveToNorthCommand() r = s.execute(rovers.rover_00N) self.assertEqual(Rover(0, 1, 'N'), r)
def test_move_moves_rover_to_south(self): s = mc.MoveToSouthCommand() r = s.execute(rovers.rover_00S) self.assertEqual(Rover(0, -1, 'S'), r)
def test_move_moves_rover_to_west(self): s = mc.MoveToWestCommand() r = s.execute(rovers.rover_00W) self.assertEqual(Rover(-1, 0, 'W'), r)
def test_move_moves_rover_to_east(self): s = mc.MoveToEastCommand() r = s.execute(rovers.rover_00E) self.assertEqual(Rover(1, 0, 'E'), r)