From 9240e8188c8afc3c14bf5fcad764577e728cdced Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Thu, 24 Mar 2011 23:41:32 -0400
Subject: [PATCH] Add bounding box calculation tests.

---
 test/geocoder_test.rb | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb
index 232c8ac3..f3cfc0dd 100644
--- a/test/geocoder_test.rb
+++ b/test/geocoder_test.rb
@@ -176,6 +176,26 @@ class GeocoderTest < Test::Unit::TestCase
     assert_equal [0.0, 0.5], Geocoder::Calculations.geographic_center([p1, p2])
   end
 
+  def test_bounding_box_calculation_in_miles
+    center = [51, 7] # Cologne, DE
+    radius = 10 # miles
+    dlon = radius / Geocoder::Calculations.latitude_degree_distance
+    dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0])
+    corners = [50.86, 6.77, 51.14, 7.23]
+    assert_equal corners.map{ |i| (i * 100).round },
+      Geocoder::Calculations.bounding_box(center[0], center[1], radius).map{ |i| (i * 100).round }
+  end
+
+  def test_bounding_box_calculation_in_kilometers
+    center = [51, 7] # Cologne, DE
+    radius = 111 # kilometers (= 1 degree latitude)
+    dlon = radius / Geocoder::Calculations.latitude_degree_distance(:km)
+    dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0], :km)
+    corners = [50, 5.41, 52, 8.59]
+    assert_equal corners.map{ |i| (i * 100).round },
+      Geocoder::Calculations.bounding_box(center[0], center[1], radius, :units => :km).map{ |i| (i * 100).round }
+  end
+
 
   # --- bearing ---
 
-- 
GitLab