test/test_latlng.rb in geokit-1.9.0 vs test/test_latlng.rb in geokit-1.10.0

- old
+ new

@@ -1,29 +1,29 @@ -require File.join(File.dirname(__FILE__), 'helper') +require File.join(File.dirname(__FILE__), "helper") 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', + 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' - }) + 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.full_address = "Porscheplatz 1, 45127 Essen, Deutschland" + location.precision = "address" + location.provider = "google" location.success = true location end def test_existance_of_latitude_alias @@ -187,56 +187,56 @@ def test_valid_when_lat_and_lng_defined assert Geokit::LatLng.new(37.7690, -122.443).valid? end def test_not_valid_when_lat_is_nil - assert ! Geokit::LatLng.new(nil, -122.443).valid? + assert !Geokit::LatLng.new(nil, -122.443).valid? end def test_not_valid_when_lng_is_nil - assert ! Geokit::LatLng.new(37.7690, nil).valid? + assert !Geokit::LatLng.new(37.7690, nil).valid? 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_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 "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_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 + 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_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 + assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address # slightly different from yahoo + assert_equal "google", res.provider end def test_to_dms point = Geokit::LatLng.new(41.957254, -87.660333) @@ -251,7 +251,21 @@ assert_kind_of Array, dms assert_equal 3, dms.length assert_kind_of Numeric, dms.length assert_equal [-87, 39], dms[0, 2] assert_equal 37, dms[2].round + end + + def test_invalid_units + expected_exception_message = "feet is an unsupported unit of length." + + exception = assert_raise(ArgumentError) do + @loc_a.distance_to(@loc_e, units: :feet) + end + assert_equal expected_exception_message, exception.message + + exception = assert_raise(ArgumentError) do + @loc_a.endpoint(332, 3.97, units: :feet) + end + assert_equal expected_exception_message, exception.message end end