Skip to content
Browse files

Add simple region detection code

  • Loading branch information...
1 parent fd11ac7 commit abe138152872944fe9fac5493181e9af652ebf1a @practicingruby practicingruby committed Apr 14, 2012
Showing with 60 additions and 0 deletions.
  1. +25 −0 lib/blind/world.rb
  2. +1 −0 test/suite.rb
  3. +34 −0 test/world_test.rb
View
25 lib/blind/world.rb
@@ -0,0 +1,25 @@
+require_relative "point"
+
+# possibly refactor to be a simple lookup
+# rather than doing point manipulation
+
+module Blind
+ class World
+ def initialize
+ @center = Blind::Point.new(0,0)
+ end
+
+ def region(point)
+ case point.distance(@center)
+ when 0...20
+ :safe_zone
+ when 20...100
+ :mine_field
+ when 100...120
+ :danger_zone
+ else
+ :outer_rim
+ end
+ end
+ end
+end
View
1 test/suite.rb
@@ -1 +1,2 @@
require_relative "point_test"
+require_relative "world_test"
View
34 test/world_test.rb
@@ -0,0 +1,34 @@
+require_relative "helper"
+require_relative "../lib/blind/point"
+require_relative "../lib/blind/world"
+
+describe Blind::World do
+
+ let(:world) { Blind::World.new }
+
+ it "must locate points in the safe zone" do
+ world.region(pt(0,0)).must_equal(:safe_zone)
+ world.region(pt(0,19)).must_equal(:safe_zone)
+ world.region(pt(19,0)).must_equal(:safe_zone)
+ end
+
+ it "must locate points in the mine field" do
+ world.region(pt(20,0)).must_equal(:mine_field)
+ world.region(pt(0,99)).must_equal(:mine_field)
+ end
+
+ it "must locate points in the danger zone" do
+ world.region(pt(0,100)).must_equal(:danger_zone)
+ world.region(pt(60,80)).must_equal(:danger_zone)
+ end
+
+ it "must locate points in the outer rim" do
+ world.region(pt(0,120)).must_equal(:outer_rim)
+ world.region(pt(0,120)).must_equal(:outer_rim)
+ world.region(pt(75,150)).must_equal(:outer_rim)
+ end
+
+ def pt(x,y)
+ Blind::Point.new(x,y)
+ end
+end

0 comments on commit abe1381

Please sign in to comment.
Something went wrong with that request. Please try again.