diff --git a/rover/rover.py b/rover/rover.py index 6fc531b..c02091d 100644 --- a/rover/rover.py +++ b/rover/rover.py @@ -34,3 +34,6 @@ class Rover(BaseModel): self.pos.x += self.planet_size.x if self.pos.y < 0: self.pos.y += self.planet_size.y + + self.pos.x %= self.planet_size.x + self.pos.y %= self.planet_size.y diff --git a/rover/test_rover.py b/rover/test_rover.py index 8c6e0a1..29fc698 100644 --- a/rover/test_rover.py +++ b/rover/test_rover.py @@ -76,3 +76,19 @@ def test_rover_can_wrap_under_east_west(): ) rov.forward() 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)