diff options
| author | mo k <mo@mokhan.ca> | 2012-02-13 13:19:50 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-13 13:19:50 -0700 |
| commit | 86fda8f9ff0eb0bd32f67c5d2bbdae0ec5b6033c (patch) | |
| tree | a5902b6e1670fc5605e131cd4611521250d11485 | |
| parent | 9f635b54de51ac87b42d0f72f5f036a150bde4c9 (diff) | |
check bounds when facing south and moving forward.
| -rwxr-xr-x[-rw-r--r--] | lib/south.rb | 6 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/rover_specs.rb | 1 | ||||
| -rwxr-xr-x | spec/south_specs.rb | 31 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/ts_all.rb | 1 |
4 files changed, 37 insertions, 2 deletions
diff --git a/lib/south.rb b/lib/south.rb index 04851c0..5e8a434 100644..100755 --- a/lib/south.rb +++ b/lib/south.rb @@ -5,7 +5,9 @@ class South def turn_left East.new end - def forward(current_location, terrain) - current_location[:y] = current_location[:y]-1 + def forward(location, terrain) + unless terrain.is_out_of_bounds({:x => location[:x], :y => location[:y]-1}) + location[:y] = location[:y]-1 + end end end diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb index 52b45c3..f8d15f8 100644..100755 --- a/spec/rover_specs.rb +++ b/spec/rover_specs.rb @@ -55,6 +55,7 @@ describe Rover do 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 diff --git a/spec/south_specs.rb b/spec/south_specs.rb new file mode 100755 index 0000000..7d3fc33 --- /dev/null +++ b/spec/south_specs.rb @@ -0,0 +1,31 @@ +require 'south'
+
+describe South do
+ before 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)
+ end
+ end
+ end
+end
diff --git a/spec/ts_all.rb b/spec/ts_all.rb index b783a1e..36e285f 100644..100755 --- a/spec/ts_all.rb +++ b/spec/ts_all.rb @@ -8,4 +8,5 @@ require "library_specs" require "stack_specs" require "rover_specs" require "north_specs" +require "south_specs" require "specifications/find_all_books_by_author_specs" |
