def test_move_world(): rovers = [ Rover(Position(x=1, y=2, heading='N'), Plateau(max_x=5, max_y=5)), Rover(Position(x=3, y=3, heading='E'), Plateau(max_x=5, max_y=5)) ] world = World(Plateau(5, 5)) world.rovers = rovers world.instructions = ["LMLMLMLMM", "MMRMMRMRRM"] world.follow_instructions() assert world.rovers[0].position == Position(1, 3, 'N') assert world.rovers[1].position == Position(5, 1, 'E')
class TestPlateau(unittest.TestCase): """ Verifies if after landed, the rover can navigate on the plateau. """ def setUp(self): self.plateau = Plateau(5, 5) def test_validate(self): self.assertTrue(self.plateau.validate(2, 2))
def test_plateau_contains(): assert Plateau(1, 0).contains(Position(0, 0, 'W')) assert Plateau(1, 0).contains(Position(1, 0, 'W')) assert Plateau(1, 0).contains(Position(-1, 0, 'W')) is False assert Plateau(1, 0).contains(Position(0, -1, 'W')) is False assert Plateau(1, 0).contains(Position(1, 1, 'W')) is False assert Plateau(1, 0).contains(Position(0, 1, 'W')) is False
def test_parse_input(): input = """\ 5 5 1 2 N LMLMLMLMM 3 3 E MMRMMRMRRM """ world = parse(input) assert world.plateau == Plateau(5, 5) assert str( world.rovers ) == "[Rover(Position(x=1, y=2, heading='N'), Plateau(max_x=5, max_y=5)), Rover(Position(x=3, y=3, heading='E'), Plateau(max_x=5, max_y=5))]" assert str(world.instructions) == "['LMLMLMLMM', 'MMRMMRMRRM']"
def test_report_position(): plateau = Plateau(0, 1) rover = Rover(Position(0, 1, 'N'), plateau) assert "0 1 N\n" == rover.report_position()
def test_move_rover_over_edge(): plateau = Plateau(0, 1) rover = Rover(Position(0, 1, 'N'), plateau) with pytest.raises(ValueError): rover.move()
def test_move_rover_on_plateau(): plateau = Plateau(5, 5) rover = Rover(Position(1, 2, 'N'), plateau) rover.move() assert rover.position == Position(1, 3, 'N')
def test_ok_plateau(): assert Plateau(1, 2).max_x == 1 assert Plateau(1, 2).max_y == 2
def test_illegal_plateau(): with pytest.raises(ValueError): Plateau(0, 0)
def setUp(self): self.plateau = Plateau(5, 5) self.rover = Rover(1, 2, 'N', self.plateau)
def test_move_east(self): plateau = Plateau("mars", 5, 5) self.assertEqual((self.move.safe_to_move([0, 0, 1], plateau)), True) # self.assertEqual((self.move.update_location([0, 0, 1, plateau])), (1, 0, 1))
def setUp(self): self.plateau = Plateau(5, 5)