From 191927b9bff9ba24377b1f35b8cf1e8ddb70b622 Mon Sep 17 00:00:00 2001 From: fr2d9y2 Date: Thu, 6 Apr 2017 14:44:44 -0700 Subject: [PATCH] Elaborate: add real list and path --- mars-rover/src/rover.py | 3 ++- mars-rover/test/test_rover.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mars-rover/src/rover.py b/mars-rover/src/rover.py index 395ab3e..bbfa5fe 100644 --- a/mars-rover/src/rover.py +++ b/mars-rover/src/rover.py @@ -9,7 +9,8 @@ def __init__(self, x, y, orientation): self.orientation = orientation def move(self, commands): - self.moveBy(commands[0]) + for command in commands: + self.moveBy(command) # use command pattern and lookup to avoid switch statements :) def moveBy(self, commandKey): diff --git a/mars-rover/test/test_rover.py b/mars-rover/test/test_rover.py index 07db160..4e69e41 100644 --- a/mars-rover/test/test_rover.py +++ b/mars-rover/test/test_rover.py @@ -113,3 +113,15 @@ def test_move_right(self): def test_move_left(self): r.move(list('l')); assert_equals('S', r.orientation) + +class TestMovePath: + + def setup(self): + global r + r = rover.Rover(10, 21, 'N') + + def test_simple_path(self): + r.move(list("ffrff")) + assert_equal('E', r.orientation) + assert_equal(12, r.x) + assert_equal(23, r.y)