Exemple #1
0
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')
Exemple #2
0
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
Exemple #3
0
def test_report_position():
    plateau = Plateau(0, 1)
    rover = Rover(Position(0, 1, 'N'), plateau)
    assert "0 1 N\n" == rover.report_position()
Exemple #4
0
def test_move_rover_over_edge():
    plateau = Plateau(0, 1)
    rover = Rover(Position(0, 1, 'N'), plateau)
    with pytest.raises(ValueError):
        rover.move()
Exemple #5
0
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')
Exemple #6
0
def test_move():
    assert move(Position(1, 2, 'N')) == Position(1, 3, 'N')
    assert move(Position(1, 2, 'W')) == Position(0, 2, 'W')
    assert move(Position(1, 2, 'S')) == Position(1, 1, 'S')
    assert move(Position(1, 2, 'E')) == Position(2, 2, 'E')
Exemple #7
0
 def setUp(self):
     self.pos = Position()
Exemple #8
0
 def test_1(self):
     self.assertEqual(Position().get(), (0, 0, 'North'))