Esempio n. 1
0
def test_rover_can_go_forward_twice_going_north():
    rov = Rover(
        pos=Vector(x=0, y=0), planet_size=Vector(x=10, y=10), dir=Direction.NORTH
    )
    rov.forward()
    rov.forward()
    assert rov.pos == Vector(x=0, y=2)
Esempio n. 2
0
def test_commander_constructor():
    com = Commander(
        rover=Rover(
            pos=Vector(x=12, y=27), planet_size=Vector(x=100, y=100), dir=Direction.WEST
        )
    )
    assert (
        com.rover.pos == Vector(x=12, y=27)
        and com.rover.planet_size == Vector(x=100, y=100)
        and com.rover.dir == Direction.WEST
    )
Esempio n. 3
0
def test_rover_can_wrap_over_north_south():
    rov = Rover(
        pos=Vector(x=0, y=9), planet_size=Vector(x=10, y=10), dir=Direction.NORTH
    )
    rov.forward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 4
0
def test_rover_can_go_forward_going_west():
    rov = Rover(
        pos=Vector(x=1, y=0), planet_size=Vector(x=10, y=10), dir=Direction.WEST
    )
    rov.forward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 5
0
def test_rover_can_go_forward_going_south():
    rov = Rover(
        pos=Vector(x=0, y=1), planet_size=Vector(x=10, y=10), dir=Direction.SOUTH
    )
    rov.forward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 6
0
def test_rover_constructor():
    rov = Rover(pos={"x": 0, "y": 0}, planet_size={"x": 100, "y": 100})
    assert rov.pos == Vector(x=0, y=0) and rov.planet_size == Vector(x=100, y=100)
Esempio n. 7
0
def test_commander_have_rover_start_on_obstacle():
    with pytest.raises(ValidationError):
        _ = Commander(obstacles=[Vector()])
Esempio n. 8
0
def test_rover_can_go_backward_east():
    rov = Rover(
        pos=Vector(x=1, y=0), planet_size=Vector(x=10, y=10), dir=Direction.EAST
    )
    rov.backward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 9
0
def test_rover_negative_y_construction():
    with pytest.raises(ValidationError):
        _ = Rover(pos=Vector(x=0, y=-1))
Esempio n. 10
0
def test_commander_command_with_obstacles():
    com = Commander(obstacles=[Vector(x=1, y=0), Vector(x=1, y=2)])
    with pytest.raises(ObstacleError):
        com.parse_execute("FFRF")
    assert com.rover == Rover(pos=Vector(x=0, y=2), dir=Direction.EAST)
Esempio n. 11
0
def test_commmander_can_parse_backward():
    com = Commander(rover=Rover(pos=Vector(x=0, y=1)))
    com.parse_execute("B")
    assert com.rover == Rover()
Esempio n. 12
0
def test_commmander_can_parse_forward():
    com = Commander()
    com.parse_execute("F")
    assert com.rover == Rover(pos=Vector(x=0, y=1))
Esempio n. 13
0
def test_rover_can_go_backward_wrapping_over_east_west():
    rov = Rover(
        pos=Vector(x=9, y=0), planet_size=Vector(x=10, y=10), dir=Direction.WEST
    )
    rov.backward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 14
0
def test_rover_can_go_backward_wrapping_over_north_south():
    rov = Rover(
        pos=Vector(x=0, y=9), planet_size=Vector(x=10, y=10), dir=Direction.SOUTH
    )
    rov.backward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 15
0
def test_rover_can_wrap_over_east_west():
    rov = Rover(
        pos=Vector(x=9, y=0), planet_size=Vector(x=10, y=10), dir=Direction.EAST
    )
    rov.forward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 16
0
def test_rover_oversize_y_construction():
    with pytest.raises(ValidationError):
        _ = Rover(pos=Vector(x=0, y=11), planet_size=Vector(x=10, y=10))
Esempio n. 17
0
def test_rover_can_go_backward_north():
    rov = Rover(
        pos=Vector(x=0, y=1), planet_size=Vector(x=10, y=10), dir=Direction.NORTH
    )
    rov.backward()
    assert rov.pos == Vector(x=0, y=0)
Esempio n. 18
0
def test_rover_default_values():
    rov = Rover()
    assert rov.pos == Vector(x=0, y=0) and rov.planet_size == Vector(x=100, y=100)