rover: wrap when going over planet size

This commit is contained in:
Bruno BELANYI 2019-11-15 21:14:42 +01:00
parent 24b3f63d3c
commit c96f44332c
2 changed files with 19 additions and 0 deletions

View file

@ -34,3 +34,6 @@ class Rover(BaseModel):
self.pos.x += self.planet_size.x self.pos.x += self.planet_size.x
if self.pos.y < 0: if self.pos.y < 0:
self.pos.y += self.planet_size.y self.pos.y += self.planet_size.y
self.pos.x %= self.planet_size.x
self.pos.y %= self.planet_size.y

View file

@ -76,3 +76,19 @@ def test_rover_can_wrap_under_east_west():
) )
rov.forward() rov.forward()
assert rov.pos == Vector(x=9, y=0) assert rov.pos == Vector(x=9, y=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)
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)