Commit 611fa14

mo k <mo@mokhan.ca>
2012-11-05 05:05:13
rename move_forward
1 parent 63a1beb
lib/location.rb
@@ -26,20 +26,12 @@ class Location
 
   def increment(axis, map)
     next_position = current(axis) + 1
-    if(next_position > map[axis])
-      move_to(axis, 0)
-    else
-      move_to(axis, next_position)
-    end
+    move_to(axis, (next_position > map[axis]) ? 0 : next_position )
   end
 
   def decrement(axis, map)
     next_position = current(axis) - 1
-    if (next_position < 0)
-      move_to(axis, map[axis])
-    else
-      move_to(axis, next_position)
-    end
+    move_to(axis, (next_position < 0) ? map[axis] : next_position)
   end
 
   def to_s
lib/plateau.rb
@@ -10,7 +10,7 @@ class Plateau
     @directions = {:N => North.new, :E => East.new, :W => West.new, :S => South.new}
   end
 
-  def move_forward(location)
+  def move_forward_from(location)
     location.forward(self)
   end
 
lib/rover.rb
@@ -10,7 +10,7 @@ class Rover
   end
 
   def drive
-    @plateau.move_forward(@location)
+    @plateau.move_forward_from(@location)
   end
 
   def is_facing(direction)
spec/unit/plateau_spec.rb
@@ -11,7 +11,7 @@ describe Plateau do
       end
       before do
         @location = Location.new(3, 0, East.new)
-        sut.move_forward(@location)
+        sut.move_forward_from(@location)
       end
     end
 
@@ -22,7 +22,7 @@ describe Plateau do
       end
       before do
         @location = Location.new(0, 0, West.new)
-        sut.move_forward(@location)
+        sut.move_forward_from(@location)
       end
     end
 
@@ -33,7 +33,7 @@ describe Plateau do
       end
       before do
         @location = Location.new(0, 3, North.new)
-        sut.move_forward(@location)
+        sut.move_forward_from(@location)
       end
     end
 
@@ -44,7 +44,7 @@ describe Plateau do
       end
       before do
         @location = Location.new( 0,  0, South.new)
-        sut.move_forward(@location)
+        sut.move_forward_from(@location)
       end
     end
 
@@ -55,7 +55,7 @@ describe Plateau do
       end
       before do
         @location = Location.new( 1,  0, North.new)
-        sut.move_forward(@location)
+        sut.move_forward_from(@location)
       end
     end
   end
spec/unit/rover_spec.rb
@@ -73,16 +73,6 @@ describe Rover do
     end
   end
 
-  context "when driving forward" do
-    it "should move forward along the terrain" do
-      plateau.should have_received(:move_forward)
-    end
-    before do
-      @sut = create_sut(:north)
-      @sut.drive
-    end
-  end
-
   context "when printed" do
     it "should return the heading and location" do
       create_sut(:north).to_s.should == '0 0 N'