summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-11 15:06:59 -0700
committermo k <mo@mokhan.ca>2012-02-11 15:06:59 -0700
commitb1c2f983456637975dc41dee6f5bab65d2afaa66 (patch)
tree14a39d3d06d8e45bd2057f0910e869bc7646b2ea
parent80fecf3caf0f58f07f69bdfe3548f5f25e5706a9 (diff)
when facing east and turning left or right.
-rw-r--r--lib/rover.rb4
-rw-r--r--spec/rover_specs.rb18
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/rover.rb b/lib/rover.rb
index c09ffc2..591ec5a 100644
--- a/lib/rover.rb
+++ b/lib/rover.rb
@@ -7,6 +7,8 @@ class Rover
def turn_right
if(@heading == :north)
@heading = :east
+ elsif @heading == :east
+ @heading = :south
elsif @heading == :south
@heading = :west
end
@@ -14,6 +16,8 @@ class Rover
def turn_left
if(@heading == :north)
@heading = :west
+ elsif @heading == :east
+ @heading = :north
elsif @heading == :south
@heading = :east
end
diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb
index ccf3f02..7bef598 100644
--- a/spec/rover_specs.rb
+++ b/spec/rover_specs.rb
@@ -41,4 +41,22 @@ describe Rover do
end
end
+ describe "when facing east" do
+ before do
+ @sut.heading= :east
+ end
+ describe "when turning right" do
+ it "should face south" do
+ @sut.turn_right
+ @sut.heading.must_equal :south
+ end
+ end
+ describe "when turning left" do
+ it "should face north" do
+ @sut.turn_left
+ @sut.heading.must_equal :north
+ end
+ end
+ end
+
end