summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rover.rb6
-rw-r--r--spec/rover_specs.rb18
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/rover.rb b/lib/rover.rb
index 35ab1f9..90d7757 100644
--- a/lib/rover.rb
+++ b/lib/rover.rb
@@ -42,6 +42,9 @@ class East
def turn_left
North.new
end
+ def forward(current_location)
+ current_location[:x] = current_location[:x]+1
+ end
end
class West
def direction
@@ -53,6 +56,9 @@ class West
def turn_left
South.new
end
+ def forward(current_location)
+ current_location[:x] = current_location[:x]-1
+ end
end
class South
def direction
diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb
index c8e5ec8..a54e2c2 100644
--- a/spec/rover_specs.rb
+++ b/spec/rover_specs.rb
@@ -73,11 +73,19 @@ describe Rover do
@sut.heading.must_equal :north
end
end
+ describe "when driving forward" do
+ before do
+ @sut.move_forward(@terrain)
+ end
+ it "should increment the x coordinate on the terrain" do
+ @sut.location.must_equal({:x => 1, :y => 0})
+ end
+ end
end
describe "when facing west" do
before do
- @sut = create_sut :west
+ @sut = create_sut :west, 1, 0
end
describe "when turning right" do
it "should face north" do
@@ -91,6 +99,14 @@ describe Rover do
@sut.heading.must_equal :south
end
end
+ describe "when driving forward" do
+ before do
+ @sut.move_forward(@terrain)
+ end
+ it "should decrement the x coordinate on the terrain" do
+ @sut.location.must_equal({:x => 0, :y => 0})
+ end
+ end
end
end