darrell-geokit 1.2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ require 'test/unit'
2
+ require 'net/http'
3
+ require 'rubygems'
4
+ require 'mocha'
5
+ require 'lib/geokit'
6
+
7
+ class MockSuccess < Net::HTTPSuccess #:nodoc: all
8
+ def initialize
9
+ end
10
+ end
11
+
12
+ class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all
13
+ def initialize
14
+ end
15
+ end
16
+
17
+ # Base class for testing geocoders.
18
+ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
19
+
20
+ # Defines common test fixtures.
21
+ def setup
22
+ @address = 'San Francisco, CA'
23
+ @full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
24
+ @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
25
+
26
+ @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
27
+ @success.success = true
28
+ end
29
+
30
+ def test_timeout_call_web_service
31
+ Geokit::Geocoders::Geocoder.class_eval do
32
+ def self.do_get(url)
33
+ sleep(2)
34
+ end
35
+ end
36
+ url = "http://www.anything.com"
37
+ Geokit::Geocoders::timeout = 1
38
+ assert_nil Geokit::Geocoders::Geocoder.call_geocoder_service(url)
39
+ end
40
+
41
+ def test_successful_call_web_service
42
+ url = "http://www.anything.com"
43
+ Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
44
+ assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
45
+ end
46
+
47
+ def test_find_geocoder_methods
48
+ public_methods = Geokit::Geocoders::Geocoder.public_methods.map { |m| m.to_s }
49
+ assert public_methods.include?("yahoo_geocoder")
50
+ assert public_methods.include?("google_geocoder")
51
+ assert public_methods.include?("ca_geocoder")
52
+ assert public_methods.include?("us_geocoder")
53
+ assert public_methods.include?("multi_geocoder")
54
+ assert public_methods.include?("ip_geocoder")
55
+ end
56
+ end
@@ -0,0 +1,74 @@
1
+ require 'test/unit'
2
+ require 'lib/geokit'
3
+
4
+ class BoundsTest < Test::Unit::TestCase #:nodoc: all
5
+
6
+ def setup
7
+ # This is the area in Texas
8
+ @sw = Geokit::LatLng.new(32.91663,-96.982841)
9
+ @ne = Geokit::LatLng.new(32.96302,-96.919495)
10
+ @bounds=Geokit::Bounds.new(@sw,@ne)
11
+ @loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
12
+ @loc_b=Geokit::LatLng.new(32.914144,-96.958444) # outside bouds
13
+
14
+ # this is a cross-meridan area
15
+ @cross_meridian=Geokit::Bounds.normalize([30,170],[40,-170])
16
+ @inside_cm=Geokit::LatLng.new(35,175)
17
+ @inside_cm_2=Geokit::LatLng.new(35,-175)
18
+ @east_of_cm=Geokit::LatLng.new(35,-165)
19
+ @west_of_cm=Geokit::LatLng.new(35,165)
20
+
21
+ end
22
+
23
+ def test_equality
24
+ assert_equal Geokit::Bounds.new(@sw,@ne), Geokit::Bounds.new(@sw,@ne)
25
+ end
26
+
27
+ def test_normalize
28
+ res=Geokit::Bounds.normalize(@sw,@ne)
29
+ assert_equal res,Geokit::Bounds.new(@sw,@ne)
30
+ res=Geokit::Bounds.normalize([@sw,@ne])
31
+ assert_equal res,Geokit::Bounds.new(@sw,@ne)
32
+ res=Geokit::Bounds.normalize([@sw.lat,@sw.lng],[@ne.lat,@ne.lng])
33
+ assert_equal res,Geokit::Bounds.new(@sw,@ne)
34
+ res=Geokit::Bounds.normalize([[@sw.lat,@sw.lng],[@ne.lat,@ne.lng]])
35
+ assert_equal res,Geokit::Bounds.new(@sw,@ne)
36
+ end
37
+
38
+ def test_point_inside_bounds
39
+ assert @bounds.contains?(@loc_a)
40
+ end
41
+
42
+ def test_point_outside_bounds
43
+ assert !@bounds.contains?(@loc_b)
44
+ end
45
+
46
+ def test_point_inside_bounds_cross_meridian
47
+ assert @cross_meridian.contains?(@inside_cm)
48
+ assert @cross_meridian.contains?(@inside_cm_2)
49
+ end
50
+
51
+ def test_point_outside_bounds_cross_meridian
52
+ assert !@cross_meridian.contains?(@east_of_cm)
53
+ assert !@cross_meridian.contains?(@west_of_cm)
54
+ end
55
+
56
+ def test_center
57
+ assert_in_delta 32.939828,@bounds.center.lat,0.00005
58
+ assert_in_delta(-96.9511763,@bounds.center.lng,0.00005)
59
+ end
60
+
61
+ def test_center_cross_meridian
62
+ assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
63
+ assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
64
+ end
65
+
66
+ def test_creation_from_circle
67
+ bounds=Geokit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
68
+ inside=Geokit::LatLng.new 32.9695270000,-96.9901590000
69
+ outside=Geokit::LatLng.new 32.8951550000,-96.9584440000
70
+ assert bounds.contains?(inside)
71
+ assert !bounds.contains?(outside)
72
+ end
73
+
74
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+
3
+ Geokit::Geocoders::geocoder_ca = "SOMEKEYVALUE"
4
+
5
+ class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
6
+
7
+ CA_SUCCESS=<<-EOF
8
+ <?xml version="1.0" encoding="UTF-8" ?>
9
+ <geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
10
+ EOF
11
+
12
+ def setup
13
+ @ca_full_hash = {:street_address=>"2105 West 32nd Avenue",:city=>"Vancouver", :state=>"BC"}
14
+ @ca_full_loc = Geokit::GeoLoc.new(@ca_full_hash)
15
+ end
16
+
17
+ def test_geocoder_with_geo_loc_with_account
18
+ response = MockSuccess.new
19
+ response.expects(:body).returns(CA_SUCCESS)
20
+ url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
21
+ Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
22
+ verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
23
+ end
24
+
25
+ def test_service_unavailable
26
+ response = MockFailure.new
27
+ #Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
28
+ url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
29
+ Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
30
+ assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
31
+ end
32
+
33
+ private
34
+
35
+ def verify(location)
36
+ assert_equal "BC", location.state
37
+ assert_equal "Vancouver", location.city
38
+ assert_equal "49.243086,-123.153684", location.ll
39
+ assert !location.is_us?
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ require 'test/unit'
2
+ require 'lib/geokit'
3
+
4
+ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
5
+
6
+ def setup
7
+ @loc = Geokit::GeoLoc.new
8
+ end
9
+
10
+ def test_is_us
11
+ assert !@loc.is_us?
12
+ @loc.country_code = 'US'
13
+ assert @loc.is_us?
14
+ end
15
+
16
+ def test_street_number
17
+ @loc.street_address = '123 Spear St.'
18
+ assert_equal '123', @loc.street_number
19
+ end
20
+
21
+ def test_street_name
22
+ @loc.street_address = '123 Spear St.'
23
+ assert_equal 'Spear St.', @loc.street_name
24
+ end
25
+
26
+ def test_city
27
+ @loc.city = "san francisco"
28
+ assert_equal 'San Francisco', @loc.city
29
+ end
30
+
31
+ def test_full_address
32
+ @loc.city = 'San Francisco'
33
+ @loc.state = 'CA'
34
+ @loc.zip = '94105'
35
+ @loc.country_code = 'US'
36
+ assert_equal 'San Francisco, CA, 94105, US', @loc.full_address
37
+ @loc.full_address = 'Irving, TX, 75063, US'
38
+ assert_equal 'Irving, TX, 75063, US', @loc.full_address
39
+ end
40
+
41
+ def test_hash
42
+ @loc.city = 'San Francisco'
43
+ @loc.state = 'CA'
44
+ @loc.zip = '94105'
45
+ @loc.country_code = 'US'
46
+ @another = Geokit::GeoLoc.new @loc.to_hash
47
+ assert_equal @loc, @another
48
+ end
49
+
50
+ def test_all
51
+ assert_equal [@loc], @loc.all
52
+ end
53
+
54
+ end
@@ -0,0 +1,116 @@
1
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+
3
+ Geokit::Geocoders::google = 'Google'
4
+
5
+ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
6
+
7
+ GOOGLE_FULL=<<-EOF.strip
8
+ <?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>100 Spear St, San Francisco, CA 94105, USA</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName><Thoroughfare><ThoroughfareName>100 Spear St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>94105</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.393985,37.792501,0</coordinates></Point></Placemark></Response></kml>
9
+ EOF
10
+
11
+ GOOGLE_CITY=<<-EOF.strip
12
+ <?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>San Francisco</name><Status><code>200</code><request>geocode</request></Status><Placemark><address>San Francisco, CA, USA</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><AdministrativeArea><AdministrativeAreaName>CA</AdministrativeAreaName><Locality><LocalityName>San Francisco</LocalityName></Locality></AdministrativeArea></Country></AddressDetails><Point><coordinates>-122.418333,37.775000,0</coordinates></Point></Placemark></Response></kml>
13
+ EOF
14
+
15
+ GOOGLE_MULTI="<?xml version='1.0' encoding='UTF-8'?>\n<kml xmlns='http://earth.google.com/kml/2.0'><Response>\n <name>via Sandro Pertini 8, Ossona, MI</name>\n <Status>\n <code>200</code>\n <request>geocode</request>\n </Status>\n <Placemark id='p1'>\n <address>Via Sandro Pertini, 8, 20010 Mesero MI, Italy</address>\n <AddressDetails Accuracy='8' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>IT</CountryNameCode><CountryName>Italy</CountryName><AdministrativeArea><AdministrativeAreaName>Lombardy</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Milan</SubAdministrativeAreaName><Locality><LocalityName>Mesero</LocalityName><Thoroughfare><ThoroughfareName>8 Via Sandro Pertini</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>20010</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>\n <Point><coordinates>8.8527131,45.4966243,0</coordinates></Point>\n </Placemark>\n <Placemark id='p2'>\n <address>Via Sandro Pertini, 20010 Ossona MI, Italy</address>\n <AddressDetails Accuracy='6' xmlns='urn:oasis:names:tc:ciq:xsdschema:xAL:2.0'><Country><CountryNameCode>IT</CountryNameCode><CountryName>Italy</CountryName><AdministrativeArea><AdministrativeAreaName>Lombardy</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Milan</SubAdministrativeAreaName><Locality><LocalityName>Ossona</LocalityName><Thoroughfare><ThoroughfareName>Via Sandro Pertini</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>20010</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>\n <Point><coordinates>8.9023200,45.5074444,0</coordinates></Point>\n </Placemark>\n</Response></kml>\n"
16
+
17
+ def setup
18
+ super
19
+ @google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
20
+ @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
21
+
22
+ @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
23
+ @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
24
+ end
25
+
26
+ def test_google_full_address
27
+ response = MockSuccess.new
28
+ response.expects(:body).returns(GOOGLE_FULL)
29
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
30
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
31
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
32
+ assert_equal "CA", res.state
33
+ assert_equal "San Francisco", res.city
34
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
35
+ assert res.is_us?
36
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
37
+ assert_equal "google", res.provider
38
+ end
39
+
40
+ def test_google_full_address_with_geo_loc
41
+ response = MockSuccess.new
42
+ response.expects(:body).returns(GOOGLE_FULL)
43
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
44
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
45
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
46
+ assert_equal "CA", res.state
47
+ assert_equal "San Francisco", res.city
48
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
49
+ assert res.is_us?
50
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
51
+ assert_equal "google", res.provider
52
+ end
53
+
54
+ def test_google_city
55
+ response = MockSuccess.new
56
+ response.expects(:body).returns(GOOGLE_CITY)
57
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
58
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
59
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
60
+ assert_equal "CA", res.state
61
+ assert_equal "San Francisco", res.city
62
+ assert_equal "37.775,-122.418333", res.ll
63
+ assert res.is_us?
64
+ assert_equal "San Francisco, CA, USA", res.full_address
65
+ assert_nil res.street_address
66
+ assert_equal "google", res.provider
67
+ end
68
+
69
+ def test_google_city_with_geo_loc
70
+ response = MockSuccess.new
71
+ response.expects(:body).returns(GOOGLE_CITY)
72
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
73
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
74
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
75
+ assert_equal "CA", res.state
76
+ assert_equal "San Francisco", res.city
77
+ assert_equal "37.775,-122.418333", res.ll
78
+ assert res.is_us?
79
+ assert_equal "San Francisco, CA, USA", res.full_address
80
+ assert_nil res.street_address
81
+ assert_equal "google", res.provider
82
+ end
83
+
84
+ def test_service_unavailable
85
+ response = MockFailure.new
86
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address)}&output=xml&key=Google&oe=utf-8"
87
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
88
+ assert !Geokit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
89
+ end
90
+
91
+ def test_multiple_results
92
+ #Geokit::Geocoders::GoogleGeocoder.do_geocode('via Sandro Pertini 8, Ossona, MI')
93
+ response = MockSuccess.new
94
+ response.expects(:body).returns(GOOGLE_MULTI)
95
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape('via Sandro Pertini 8, Ossona, MI')}&output=xml&key=Google&oe=utf-8"
96
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
97
+ res=Geokit::Geocoders::GoogleGeocoder.geocode('via Sandro Pertini 8, Ossona, MI')
98
+ assert_equal "Lombardy", res.state
99
+ assert_equal "Mesero", res.city
100
+ assert_equal "45.4966243,8.8527131", res.ll
101
+ assert !res.is_us?
102
+ assert_equal "Via Sandro Pertini, 8, 20010 Mesero MI, Italy", res.full_address
103
+ assert_equal "8 Via Sandro Pertini", res.street_address
104
+ assert_equal "google", res.provider
105
+
106
+ assert_equal 2, res.all.size
107
+ res = res.all[1]
108
+ assert_equal "Lombardy", res.state
109
+ assert_equal "Ossona", res.city
110
+ assert_equal "45.5074444,8.90232", res.ll
111
+ assert !res.is_us?
112
+ assert_equal "Via Sandro Pertini, 20010 Ossona MI, Italy", res.full_address
113
+ assert_equal "Via Sandro Pertini", res.street_address
114
+ assert_equal "google", res.provider
115
+ end
116
+ end
@@ -0,0 +1,132 @@
1
+ require 'test/unit'
2
+ require 'lib/geokit'
3
+
4
+ class LatLngTest < Test::Unit::TestCase #:nodoc: all
5
+
6
+ def setup
7
+ @loc_a = Geokit::LatLng.new(32.918593,-96.958444)
8
+ @loc_e = Geokit::LatLng.new(32.969527,-96.990159)
9
+ @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
10
+ end
11
+
12
+ def test_distance_between_same_using_defaults
13
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
14
+ assert_equal 0, @loc_a.distance_to(@loc_a)
15
+ end
16
+
17
+ def test_distance_between_same_with_miles_and_flat
18
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
19
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
20
+ end
21
+
22
+ def test_distance_between_same_with_kms_and_flat
23
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
24
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
25
+ end
26
+
27
+ def test_distance_between_same_with_nms_and_flat
28
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
29
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
30
+ end
31
+
32
+ def test_distance_between_same_with_miles_and_sphere
33
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
34
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
35
+ end
36
+
37
+ def test_distance_between_same_with_kms_and_sphere
38
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
39
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
40
+ end
41
+
42
+ def test_distance_between_same_with_nms_and_sphere
43
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
44
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
45
+ end
46
+
47
+ def test_distance_between_diff_using_defaults
48
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e), 0.01
49
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e), 0.01
50
+ end
51
+
52
+ def test_distance_between_diff_with_miles_and_flat
53
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
54
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
55
+ end
56
+
57
+ def test_distance_between_diff_with_kms_and_flat
58
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
59
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
60
+ end
61
+
62
+ def test_distance_between_diff_with_nms_and_flat
63
+ assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
64
+ assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
65
+ end
66
+
67
+ def test_distance_between_diff_with_miles_and_sphere
68
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
69
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
70
+ end
71
+
72
+ def test_distance_between_diff_with_kms_and_sphere
73
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
74
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
75
+ end
76
+
77
+ def test_distance_between_diff_with_nms_and_sphere
78
+ assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
79
+ assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
80
+ end
81
+
82
+ def test_manually_mixed_in
83
+ assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
84
+ assert_equal 0, @point.distance_to(@point)
85
+ assert_equal 0, @point.distance_to(@loc_a)
86
+ assert_in_delta 3.97, @point.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
87
+ assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
88
+ assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
89
+ end
90
+
91
+ def test_heading_between
92
+ assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
93
+ end
94
+
95
+ def test_heading_to
96
+ assert_in_delta 332, @loc_a.heading_to(@loc_e), 0.5
97
+ end
98
+
99
+ def test_class_endpoint
100
+ endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
101
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
102
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
103
+ end
104
+
105
+ def test_instance_endpoint
106
+ endpoint=@loc_a.endpoint(332, 3.97)
107
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
108
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
109
+ end
110
+
111
+ def test_midpoint
112
+ midpoint=@loc_a.midpoint_to(@loc_e)
113
+ assert_in_delta 32.944061, midpoint.lat, 0.0005
114
+ assert_in_delta(-96.974296, midpoint.lng, 0.0005)
115
+ end
116
+
117
+ def test_normalize
118
+ lat=37.7690
119
+ lng=-122.443
120
+ res=Geokit::LatLng.normalize(lat,lng)
121
+ assert_equal res,Geokit::LatLng.new(lat,lng)
122
+ res=Geokit::LatLng.normalize("#{lat}, #{lng}")
123
+ assert_equal res,Geokit::LatLng.new(lat,lng)
124
+ res=Geokit::LatLng.normalize("#{lat} #{lng}")
125
+ assert_equal res,Geokit::LatLng.new(lat,lng)
126
+ res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
127
+ assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
128
+ res=Geokit::LatLng.normalize([lat,lng])
129
+ assert_equal res,Geokit::LatLng.new(lat,lng)
130
+ end
131
+
132
+ end