From 0f1b861eeedef482abb3b049c89078ae571138e5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 15 Nov 2019 20:43:59 +0100 Subject: [PATCH] rover: add direction field to Rover --- rover/rover.py | 9 +++++++++ rover/test_rover.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rover/rover.py b/rover/rover.py index af8a8a6..3d35656 100644 --- a/rover/rover.py +++ b/rover/rover.py @@ -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 diff --git a/rover/test_rover.py b/rover/test_rover.py index cb0b328..a7595ab 100644 --- a/rover/test_rover.py +++ b/rover/test_rover.py @@ -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