summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-14 13:00:40 -0700
committermo k <mo@mokhan.ca>2012-02-14 13:00:40 -0700
commit3cded90bf0ec8812f62ebb2041be5cfbc1005a1a (patch)
tree659a76e4d5d50950e2cc62de83438707dbf815a9
parentee6968d6fde0072e4bdb1e7b1b047189a6c7157e (diff)
remove terrain parameter when moving a heading forward.
-rwxr-xr-xlib/east.rb6
-rwxr-xr-x[-rw-r--r--]lib/north.rb6
-rwxr-xr-xlib/rover.rb3
-rwxr-xr-xlib/south.rb6
-rwxr-xr-x[-rw-r--r--]lib/west.rb2
-rwxr-xr-xspec/east_specs.rb10
-rwxr-xr-x[-rw-r--r--]spec/north_specs.rb18
-rwxr-xr-xspec/rover_specs.rb45
-rwxr-xr-xspec/south_specs.rb15
9 files changed, 29 insertions, 82 deletions
diff --git a/lib/east.rb b/lib/east.rb
index fd5752d..40745a4 100755
--- a/lib/east.rb
+++ b/lib/east.rb
@@ -5,9 +5,7 @@ class East
def turn_left
North.new
end
- def forward(location, terrain)
- unless terrain.is_out_of_bounds( {:x => location[:x]+1, :y => location[:y]})
- location[:x] = location[:x]+1
- end
+ def forward(location)
+ location[:x] = location[:x]+1
end
end
diff --git a/lib/north.rb b/lib/north.rb
index 9fe6aa8..769eb66 100644..100755
--- a/lib/north.rb
+++ b/lib/north.rb
@@ -5,9 +5,7 @@ class North
def turn_left
West.new
end
- def forward(location, terrain)
- unless terrain.is_out_of_bounds({:x =>location[:x],:y => location[:y]+1})
- location[:y] = location[:y]+1
- end
+ def forward(location)
+ location[:y] = location[:y]+1
end
end
diff --git a/lib/rover.rb b/lib/rover.rb
index fa5d976..779b6f9 100755
--- a/lib/rover.rb
+++ b/lib/rover.rb
@@ -14,8 +14,7 @@ class Rover
@heading = @heading.turn_left
end
def move_forward(terrain)
-# terrain.move_forward(@heading, @location)
- @heading.forward(@location, terrain)
+ terrain.move_forward(@heading, @location)
end
end
diff --git a/lib/south.rb b/lib/south.rb
index 5e8a434..5c7576a 100755
--- a/lib/south.rb
+++ b/lib/south.rb
@@ -5,9 +5,7 @@ class South
def turn_left
East.new
end
- def forward(location, terrain)
- unless terrain.is_out_of_bounds({:x => location[:x], :y => location[:y]-1})
- location[:y] = location[:y]-1
- end
+ def forward(location)
+ location[:y] = location[:y]-1
end
end
diff --git a/lib/west.rb b/lib/west.rb
index b77dd3f..58cdac2 100644..100755
--- a/lib/west.rb
+++ b/lib/west.rb
@@ -5,7 +5,7 @@ class West
def turn_left
South.new
end
- def forward(current_location, terrain)
+ def forward(current_location)
current_location[:x] = current_location[:x]-1
end
end
diff --git a/spec/east_specs.rb b/spec/east_specs.rb
index 5060956..19fe784 100755
--- a/spec/east_specs.rb
+++ b/spec/east_specs.rb
@@ -4,17 +4,13 @@ describe East do
before(:each) do
@sut = East.new
end
- describe "when at the edge of the terrain" do
describe "when moving forward" do
- it "should just stay at the current position" do
- @location[:x].must_equal 0
+ it "should move to the next position" do
+ @location[:x].must_equal 1
end
before do
- terrain = fake
- terrain.stub(:is_out_of_bounds).with({:x => -1, :y => 0}).and_return(true)
@location = {:x => 0, :y => 0}
- @sut.forward(@location, terrain)
+ @sut.forward(@location)
end
end
- end
end
diff --git a/spec/north_specs.rb b/spec/north_specs.rb
index aeb1308..da3e410 100644..100755
--- a/spec/north_specs.rb
+++ b/spec/north_specs.rb
@@ -4,17 +4,13 @@ describe North do
before(:each) do
@sut = North.new
end
- describe "when at the edge of the terrain" do
- describe "when moving forward" do
- it "should just stay at the current position" do
- @location[:y].must_equal 3
- end
- before do
- terrain = fake
- terrain.stub(:is_out_of_bounds).with({:x => 0, :y => 4}).and_return(true)
- @location = {:x => 0, :y => 3}
- @sut.forward(@location, terrain)
- end
+ describe "when moving forward" do
+ it "should move to the next position" do
+ @location[:y].must_equal 4
+ end
+ before do
+ @location = {:x => 0, :y => 3}
+ @sut.forward(@location)
end
end
end
diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb
index 8c3da03..d1ea411 100755
--- a/spec/rover_specs.rb
+++ b/spec/rover_specs.rb
@@ -26,15 +26,6 @@ describe Rover do
@sut.heading.must_equal :west
end
end
- describe "when driving forward" do
- before do
- @terrain = fake
- @sut.move_forward(@terrain)
- end
- it "should increment the y coordinate on the terrain" do
- @sut.location.must_equal({:x => 0, :y => 1})
- end
- end
end
describe "when facing south" do
@@ -53,15 +44,6 @@ describe Rover do
@sut.heading.must_equal :east
end
end
- describe "when driving forward" do
- before do
- @terrain = fake
- @sut.move_forward(@terrain)
- end
- it "should decrement the y coordinate on the terrain" do
- @sut.location.must_equal({:x => 0, :y => 2})
- end
- end
end
describe "when facing east" do
@@ -80,15 +62,6 @@ describe Rover do
@sut.heading.must_equal :north
end
end
- describe "when driving forward" do
- before do
- @terrain = fake
- @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
@@ -107,14 +80,16 @@ 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
+ describe "when driving forward" do
+ it "should move forward along the terrain" do
+ @terrain.received(:move_forward).called_with(@sut.instance_variable_get(:@heading), @sut.location).wont_be_nil
+ end
+ before do
+ @terrain = fake
+ @sut = create_sut(:north)
+ @sut.move_forward(@terrain)
+ end
+ end
end
diff --git a/spec/south_specs.rb b/spec/south_specs.rb
index 7d3fc33..a9ac0dd 100755
--- a/spec/south_specs.rb
+++ b/spec/south_specs.rb
@@ -5,26 +5,13 @@ describe South do
@sut = South.new
end
describe "when driving forward" do
- describe "when at the edge of the terrain" do
- it "should not move forward" do
- @location[:y].must_equal 1
- end
- before do
- @location = {:x => 0, :y => 1}
- @terrain = fake
- @terrain.stub(:is_out_of_bounds).with({:x => 0, :y => 0}).and_return(true);
- @sut.forward(@location, @terrain)
- end
- end
describe "when it is ok to move forward" do
it "should move forward" do
@location[:y].must_equal 0
end
before do
@location = {:x => 0, :y => 1}
- @terrain = fake
- @terrain.stub(:is_out_of_bounds).with({:x => 0, :y => 0}).and_return(false);
- @sut.forward(@location, @terrain)
+ @sut.forward(@location)
end
end
end