test/test_latlng.rb in Pr0d1r2-geokit-1.3.2.10 vs test/test_latlng.rb in Pr0d1r2-geokit-1.4.1

- old
+ new

@@ -1,16 +1,36 @@ require 'test/unit' require 'lib/geokit' +require 'mocha' class LatLngTest < Test::Unit::TestCase #:nodoc: all def setup @loc_a = Geokit::LatLng.new(32.918593,-96.958444) @loc_e = Geokit::LatLng.new(32.969527,-96.990159) @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng) end + def valid_reverse_geocoding_result + location = Geokit::GeoLoc.new({ + :city => "Essen", + :country_code => "DE", + :lat => 51.4578329, + :lng => 7.0166848, + :provider => "google", + :state => "Nordrhein-Westfalen", + :street_address => "Porscheplatz 1", + :zip => "45127" + }) + + location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland" + location.precision = 'address' + location.provider = 'google' + location.success = true + location + end + def test_distance_between_same_using_defaults assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a) assert_equal 0, @loc_a.distance_to(@loc_a) end @@ -142,7 +162,48 @@ lng=-122.443 first = Geokit::LatLng.new(lat,lng) second = Geokit::LatLng.new(lat,lng) assert first.eql?(second) assert second.eql?(first) + end + + def test_reverse_geocode + point = Geokit::LatLng.new(51.4578329, 7.0166848) + Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result) + res = point.reverse_geocode + + assert_equal "Nordrhein-Westfalen", res.state + assert_equal "Essen", res.city + assert_equal "45127", res.zip + assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo + assert res.is_us? == false + assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo + end + + def test_reverse_geocoding_using_specific_geocoder + point = Geokit::LatLng.new(51.4578329, 7.0166848) + Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result) + res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder) + + assert_equal "Nordrhein-Westfalen", res.state + assert_equal "Essen", res.city + assert_equal "45127", res.zip + assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo + assert res.is_us? == false + assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo + assert_equal "google", res.provider + end + + def test_reverse_geocoding_using_specific_geocoder_short_syntax + point = Geokit::LatLng.new(51.4578329, 7.0166848) + Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result) + res = point.reverse_geocode(:using => :google) + + assert_equal "Nordrhein-Westfalen", res.state + assert_equal "Essen", res.city + assert_equal "45127", res.zip + assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo + assert res.is_us? == false + assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo + assert_equal "google", res.provider end end \ No newline at end of file