Commit 68b921b

mo k <mo@mokhan.ca>
2012-08-11 22:47:56
moving params to run method up to constructor.
1 parent 728fb21
Changed files (3)
lib/navigate_rover.rb
@@ -1,8 +1,15 @@
 class NavigateRover
-  def run(plateau_size, starting_position, instructions)
-    terrain = create_terrain(plateau_size)
-    rover = terrain.deploy_rover_to(starting_position.split()[2], starting_position.split()[0].to_i, starting_position.split()[1].to_i)
-    instructions.split(//).each do |instruction|
+  def initialize(plateau_size, starting_position, instructions)
+    @plateau_size = plateau_size
+    @x = starting_position.split()[0].to_i
+    @y = starting_position.split()[1].to_i
+    @heading = starting_position.split()[2]
+    @instructions = instructions
+  end
+  def run
+    terrain = create_terrain(@plateau_size)
+    rover = terrain.deploy_rover_to(@heading, @x, @x)
+    @instructions.split(//).each do |instruction|
       case(instruction)
       when 'M'
         rover.move_forward(terrain)
lib/terrain.rb
@@ -6,7 +6,7 @@ class Terrain
 
   def move_forward( heading, location)
     new_location = heading.forward(location.clone)
-    puts "#{new_location[:x]}"
+
     if(new_location[:x] > @map[:x])
       location[:x] = new_location[:x] - @map[:x]
     elsif (new_location[:x] < 0)
spec/integration/navigate_rover_spec.rb
@@ -1,7 +1,7 @@
 require "navigate_rover"
 
 describe NavigateRover do
-  let(:sut) { NavigateRover.new }
+  let(:sut) { NavigateRover.new(plateau, starting_position, instructions ) }
 
   describe "when navigating" do
     context "plateau of 5 by 5" do
@@ -9,17 +9,18 @@ describe NavigateRover do
 
       context "starting at 1 2 N" do
         let(:starting_position) { '1 2 N' }
+        let(:instructions) {'LMLMLMLMM' }
 
         it "should reply with the proper final coordinates" do
-          sut.run(plateau, starting_position, 'LMLMLMLMM').should == '1 3 N'
+          sut.run.should == '1 3 N'
         end
       end
       #context "starting at 3 3 E" do
-      #let(:starting_position) { '3 3 E' }
+        #let(:starting_position) { '3 3 E' }
 
-      #it "should reply with the proper final coordinates" do
-      #sut.run(plateau, starting_position, 'MMRMMRMRRM').should == '5 1 E'
-      #end
+        #it "should reply with the proper final coordinates" do
+          #sut.run(plateau, starting_position, 'MMRMMRMRRM').should == '5 1 E'
+        #end
       #end
     end
   end