rover: wrap when going negative
This commit is contained in:
parent
d9bf239c39
commit
24b3f63d3c
|
@ -29,3 +29,8 @@ class Rover(BaseModel):
|
||||||
self.pos.x += 1
|
self.pos.x += 1
|
||||||
elif self.dir == Direction.WEST:
|
elif self.dir == Direction.WEST:
|
||||||
self.pos.x -= 1
|
self.pos.x -= 1
|
||||||
|
|
||||||
|
if self.pos.x < 0:
|
||||||
|
self.pos.x += self.planet_size.x
|
||||||
|
if self.pos.y < 0:
|
||||||
|
self.pos.y += self.planet_size.y
|
||||||
|
|
|
@ -60,3 +60,19 @@ def test_rover_can_go_forward_going_west():
|
||||||
)
|
)
|
||||||
rov.forward()
|
rov.forward()
|
||||||
assert rov.pos == Vector(x=0, y=0)
|
assert rov.pos == Vector(x=0, y=0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rover_can_wrap_under_north_south():
|
||||||
|
rov = Rover(
|
||||||
|
pos=Vector(x=0, y=0), planet_size=Vector(x=10, y=10), dir=Direction.SOUTH
|
||||||
|
)
|
||||||
|
rov.forward()
|
||||||
|
assert rov.pos == Vector(x=0, y=9)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rover_can_wrap_under_east_west():
|
||||||
|
rov = Rover(
|
||||||
|
pos=Vector(x=0, y=0), planet_size=Vector(x=10, y=10), dir=Direction.WEST
|
||||||
|
)
|
||||||
|
rov.forward()
|
||||||
|
assert rov.pos == Vector(x=9, y=0)
|
||||||
|
|
Loading…
Reference in a new issue