rover: add rover starting on obstacle validation

This commit is contained in:
Bruno BELANYI 2019-11-16 04:26:24 +01:00
parent 39d1fcd5ac
commit 7352207636
2 changed files with 12 additions and 0 deletions

View file

@ -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)

View file

@ -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()])