diff --git a/rover/rover.py b/rover/rover.py index e49843e..1299eb7 100644 --- a/rover/rover.py +++ b/rover/rover.py @@ -93,6 +93,13 @@ class Commander(BaseModel): rover: Rover = Rover() obstacles: List[Vector] = [] + @root_validator() + def _rover_should_not_start_on_obstacle(cls, values): + rover, obstacles = values.get("rover"), values.get("obstacles") + if rover.pos in obstacles: + raise ValueError(f"Rover should not start on obstacle ({rover.pos})") + return values + def parse_execute(self, commands: str): for command in commands: save: Vector = deepcopy(self.rover.pos) diff --git a/rover/test_rover.py b/rover/test_rover.py index 2264006..5f198c7 100644 --- a/rover/test_rover.py +++ b/rover/test_rover.py @@ -247,3 +247,8 @@ def test_rover_oversize_x_construction(): def test_rover_oversize_y_construction(): with pytest.raises(ValidationError): _ = Rover(pos=Vector(x=0, y=11), planet_size=Vector(x=10, y=10)) + + +def test_commander_have_rover_start_on_obstacle(): + with pytest.raises(ValidationError): + _ = Commander(obstacles=[Vector()])