From 86fda8f9ff0eb0bd32f67c5d2bbdae0ec5b6033c Mon Sep 17 00:00:00 2001 From: mo k Date: Mon, 13 Feb 2012 13:19:50 -0700 Subject: check bounds when facing south and moving forward. --- lib/south.rb | 6 ++++-- spec/rover_specs.rb | 1 + spec/south_specs.rb | 31 +++++++++++++++++++++++++++++++ spec/ts_all.rb | 1 + 4 files changed, 37 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/south.rb mode change 100644 => 100755 spec/rover_specs.rb create mode 100755 spec/south_specs.rb mode change 100644 => 100755 spec/ts_all.rb diff --git a/lib/south.rb b/lib/south.rb old mode 100644 new mode 100755 index 04851c0..5e8a434 --- 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 old mode 100644 new mode 100755 index 52b45c3..f8d15f8 --- 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 old mode 100644 new mode 100755 index b783a1e..36e285f --- 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" -- cgit v1.2.3