rover: add direction field to Rover

This commit is contained in:
Bruno BELANYI 2019-11-15 20:43:59 +01:00
parent b6d74b24eb
commit 0f1b861eee
2 changed files with 20 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import enum
from dataclasses import dataclass
@ -7,7 +8,15 @@ class Vector:
y: int
class Direction(enum.Enum):
NORTH = "N"
SOUTH = "S"
EAST = "E"
WEST = "W"
@dataclass
class Rover:
pos: Vector = (0, 0)
planet_size: Vector = (100, 100)
dir: Direction = Direction.NORTH

View file

@ -1,4 +1,4 @@
from rover import Rover
from rover import Direction, Rover
def test_rover_constructor():
@ -9,3 +9,13 @@ def test_rover_constructor():
def test_rover_default_values():
rov = Rover()
assert rov.pos == (0, 0) and rov.planet_size == (100, 100)
def test_rover_has_direction():
rov = Rover(dir=Direction.NORTH)
assert rov.dir == Direction.NORTH
def test_rover_default_direction_is_north():
rov = Rover()
assert rov.dir == Direction.NORTH