def main(): plateau = Plateau(5, 5) position = RoverPosition(1, 2) rover = Rover(plateau, position, Rover.DIRECTIONS.get('N')) rover.execute_instructions("LMLMLMLMM") #Get the rover position print(rover) rover.set_position(3, 3, Rover.DIRECTIONS.get('E')) rover.execute_instructions("MMRMMRMRRM") # Get the rover position print(rover)
def main(): plateau = Plateau(5, 5) position = Position(1, 2) # Create rover instance rover = Rover(plateau, position, Rover.DIRECTIONS.get('N')) rover.process("LMLMLMLMM") print(rover) # prints 1 3 N rover.set_position(3, 3, Rover.DIRECTIONS.get('E')) rover.process("MMRMMRMRRM") print(rover) # prints 5 1 E
def test_complex_movements(): rover = Rover(x=1, y=2, direction='N') movements = 'LMLMLMLMM' rover.execute(movements) assert rover.x == 1 assert rover.y == 3 assert rover.direction == 'N' rover = Rover(x=3, y=3, direction='E') movements = 'MMRMMRMRRM' rover.execute(movements) assert rover.x == 5 assert rover.y == 1 assert rover.direction == 'E'
def test_right_turns(): test_cases = {"N": "E", 'E': 'S', 'S': 'W', 'W': 'N'} for key, value in test_cases.iteritems(): rover = Rover(x=0, y=0, direction=key) rover.turn('R') assert rover.direction == value
def test_move_step(): rover = Rover(x=0, y=0, direction='N') rover.move() assert rover.x == 0 and rover.y == 1 and rover.direction == 'N'
def setUp(self): self.erover = Rover(0, 0, 'N')
def test_planet_is_a_sphere(self): self.i = '4' move_command = ['f', 'l', 'f'] self.assertTrue(Rover.move_rover(self.erover, move_command), msg=Rover.print_current_location(self.erover))
def test_check_wrong_commands(self): self.i = '3' move_command = ['f', 'u', 'as', 'k', 'f'] self.assertTrue(Rover.move_rover(self.erover, move_command), msg=Rover.print_current_location(self.erover))
def test_rover_detects_obstacles(self): self.i = '2' move_command = ['f', 'f', 'r', 'f', 'f'] self.assertTrue(Rover.move_rover(self.erover, move_command), msg=Rover.print_current_location(self.erover))
def test_will_rover_move(self): self.i = '1' move_command = ['f', 'f', 'f', 'r', 'f', 'l', 'f'] # output should be 1,4 E self.assertTrue(Rover.move_rover(self.erover, move_command), msg=Rover.print_current_location(self.erover))
def test_rover_starts_at_x_0(): rover = Rover() assert rover.position_x == 0
def test_rover_moves_back_when_given_int(): rover = Rover() rover.move_back(5) assert rover.position_y == -5
def test_rover_moves_forward_when_given_int(): rover = Rover() rover.move_forward(5) assert rover.position_y == 5
def test_rover_turns_right(): rover = Rover() rover.turn("right") assert rover.orientation == "W"
def test_rover_starts_facing_north(): rover = Rover() assert rover.orientation == "N"