summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-12 14:41:04 -0700
committermo k <mo@mokhan.ca>2012-02-12 14:41:04 -0700
commit1cdb42b82c58fd2b2512a41d11db4285561a9b9d (patch)
treec9577fa20c9974fd640b597539e0334ceaf9fbb6
parentad9ab2585464ab34c8abdbe797e0c73aed36c8b5 (diff)
split out each heading into a separate file.
-rw-r--r--lib/east.rb11
-rw-r--r--lib/north.rb11
-rw-r--r--lib/rover.rb44
-rw-r--r--lib/south.rb11
-rw-r--r--lib/west.rb11
-rw-r--r--spec/rover_specs.rb4
6 files changed, 48 insertions, 44 deletions
diff --git a/lib/east.rb b/lib/east.rb
new file mode 100644
index 0000000..1699ffc
--- /dev/null
+++ b/lib/east.rb
@@ -0,0 +1,11 @@
+class East
+ def turn_right
+ South.new
+ end
+ def turn_left
+ North.new
+ end
+ def forward(current_location, terrain)
+ current_location[:x] = current_location[:x]+1
+ end
+end
diff --git a/lib/north.rb b/lib/north.rb
new file mode 100644
index 0000000..438d52d
--- /dev/null
+++ b/lib/north.rb
@@ -0,0 +1,11 @@
+class North
+ def turn_right
+ East.new
+ end
+ def turn_left
+ West.new
+ end
+ def forward(current_location, terrain)
+ current_location[:y] = current_location[:y]+1
+ end
+end
diff --git a/lib/rover.rb b/lib/rover.rb
index 3e85ecf..42fdfda 100644
--- a/lib/rover.rb
+++ b/lib/rover.rb
@@ -18,47 +18,3 @@ class Rover
end
end
-class North
- def turn_right
- East.new
- end
- def turn_left
- West.new
- end
- def forward(current_location, terrain)
- current_location[:y] = current_location[:y]+1
- end
-end
-class East
- def turn_right
- South.new
- end
- def turn_left
- North.new
- end
- def forward(current_location, terrain)
- current_location[:x] = current_location[:x]+1
- end
-end
-class West
- def turn_right
- North.new
- end
- def turn_left
- South.new
- end
- def forward(current_location, terrain)
- current_location[:x] = current_location[:x]-1
- end
-end
-class South
- def turn_right
- West.new
- end
- def turn_left
- East.new
- end
- def forward(current_location, terrain)
- current_location[:y] = current_location[:y]-1
- end
-end
diff --git a/lib/south.rb b/lib/south.rb
new file mode 100644
index 0000000..04851c0
--- /dev/null
+++ b/lib/south.rb
@@ -0,0 +1,11 @@
+class South
+ def turn_right
+ West.new
+ end
+ def turn_left
+ East.new
+ end
+ def forward(current_location, terrain)
+ current_location[:y] = current_location[:y]-1
+ end
+end
diff --git a/lib/west.rb b/lib/west.rb
new file mode 100644
index 0000000..b77dd3f
--- /dev/null
+++ b/lib/west.rb
@@ -0,0 +1,11 @@
+class West
+ def turn_right
+ North.new
+ end
+ def turn_left
+ South.new
+ end
+ def forward(current_location, terrain)
+ current_location[:x] = current_location[:x]-1
+ end
+end
diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb
index 9dc73d0..5e99495 100644
--- a/spec/rover_specs.rb
+++ b/spec/rover_specs.rb
@@ -1,4 +1,8 @@
require 'rover'
+require 'north'
+require 'east'
+require 'west'
+require 'south'
describe Rover do
def create_sut(heading, x = 0, y = 0)