diff --git a/rover/rover.py b/rover/rover.py index 2190364..6fc531b 100644 --- a/rover/rover.py +++ b/rover/rover.py @@ -29,3 +29,8 @@ class Rover(BaseModel): self.pos.x += 1 elif self.dir == Direction.WEST: 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 diff --git a/rover/test_rover.py b/rover/test_rover.py index f5a00ca..8c6e0a1 100644 --- a/rover/test_rover.py +++ b/rover/test_rover.py @@ -60,3 +60,19 @@ def test_rover_can_go_forward_going_west(): ) rov.forward() 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)