sayso-geokit 1.5.0.3.001

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,196 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/geokit')
3
+ require 'mocha'
4
+
5
+ class LatLngTest < Test::Unit::TestCase #:nodoc: all
6
+
7
+ def setup
8
+ @loc_a = Geokit::LatLng.new(32.918593,-96.958444)
9
+ @loc_e = Geokit::LatLng.new(32.969527,-96.990159)
10
+ @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
11
+ end
12
+
13
+ def valid_reverse_geocoding_result
14
+ location = Geokit::GeoLoc.new({
15
+ :city => "Essen",
16
+ :country_code => "DE",
17
+ :lat => 51.4578329,
18
+ :lng => 7.0166848,
19
+ :provider => "google",
20
+ :state => "Nordrhein-Westfalen",
21
+ :street_address => "Porscheplatz 1",
22
+ :zip => "45127"
23
+ })
24
+
25
+ location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
26
+ location.precision = 'address'
27
+ location.provider = 'google'
28
+ location.success = true
29
+ location
30
+ end
31
+
32
+ def test_distance_between_same_using_defaults
33
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
34
+ assert_equal 0, @loc_a.distance_to(@loc_a)
35
+ end
36
+
37
+ def test_distance_between_same_with_miles_and_flat
38
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
39
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
40
+ end
41
+
42
+ def test_distance_between_same_with_kms_and_flat
43
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
44
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
45
+ end
46
+
47
+ def test_distance_between_same_with_nms_and_flat
48
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
49
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
50
+ end
51
+
52
+ def test_distance_between_same_with_miles_and_sphere
53
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
54
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
55
+ end
56
+
57
+ def test_distance_between_same_with_kms_and_sphere
58
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
59
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
60
+ end
61
+
62
+ def test_distance_between_same_with_nms_and_sphere
63
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
64
+ assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
65
+ end
66
+
67
+ def test_distance_between_diff_using_defaults
68
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e), 0.01
69
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e), 0.01
70
+ end
71
+
72
+ def test_distance_between_diff_with_miles_and_flat
73
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
74
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
75
+ end
76
+
77
+ def test_distance_between_diff_with_kms_and_flat
78
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
79
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
80
+ end
81
+
82
+ def test_distance_between_diff_with_nms_and_flat
83
+ assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
84
+ assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
85
+ end
86
+
87
+ def test_distance_between_diff_with_miles_and_sphere
88
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
89
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
90
+ end
91
+
92
+ def test_distance_between_diff_with_kms_and_sphere
93
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
94
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
95
+ end
96
+
97
+ def test_distance_between_diff_with_nms_and_sphere
98
+ assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
99
+ assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
100
+ end
101
+
102
+ def test_manually_mixed_in
103
+ assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
104
+ assert_equal 0, @point.distance_to(@point)
105
+ assert_equal 0, @point.distance_to(@loc_a)
106
+ assert_in_delta 3.97, @point.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
107
+ assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
108
+ assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
109
+ end
110
+
111
+ def test_heading_between
112
+ assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
113
+ end
114
+
115
+ def test_heading_to
116
+ assert_in_delta 332, @loc_a.heading_to(@loc_e), 0.5
117
+ end
118
+
119
+ def test_class_endpoint
120
+ endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
121
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
122
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
123
+ end
124
+
125
+ def test_instance_endpoint
126
+ endpoint=@loc_a.endpoint(332, 3.97)
127
+ assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
128
+ assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
129
+ end
130
+
131
+ def test_midpoint
132
+ midpoint=@loc_a.midpoint_to(@loc_e)
133
+ assert_in_delta 32.944061, midpoint.lat, 0.0005
134
+ assert_in_delta(-96.974296, midpoint.lng, 0.0005)
135
+ end
136
+
137
+ def test_normalize
138
+ lat=37.7690
139
+ lng=-122.443
140
+ res=Geokit::LatLng.normalize(lat,lng)
141
+ assert_equal res,Geokit::LatLng.new(lat,lng)
142
+ res=Geokit::LatLng.normalize("#{lat}, #{lng}")
143
+ assert_equal res,Geokit::LatLng.new(lat,lng)
144
+ res=Geokit::LatLng.normalize("#{lat} #{lng}")
145
+ assert_equal res,Geokit::LatLng.new(lat,lng)
146
+ res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
147
+ assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
148
+ res=Geokit::LatLng.normalize([lat,lng])
149
+ assert_equal res,Geokit::LatLng.new(lat,lng)
150
+ end
151
+
152
+ def test_hash
153
+ lat=37.7690
154
+ lng=-122.443
155
+ first = Geokit::LatLng.new(lat,lng)
156
+ second = Geokit::LatLng.new(lat,lng)
157
+ assert_equal first.hash, second.hash
158
+ end
159
+
160
+ def test_eql?
161
+ lat=37.7690
162
+ lng=-122.443
163
+ first = Geokit::LatLng.new(lat,lng)
164
+ second = Geokit::LatLng.new(lat,lng)
165
+ assert first.eql?(second)
166
+ assert second.eql?(first)
167
+ end
168
+
169
+ def test_reverse_geocoding_using_specific_geocoder
170
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
171
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
172
+ res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder)
173
+
174
+ assert_equal "Nordrhein-Westfalen", res.state
175
+ assert_equal "Essen", res.city
176
+ assert_equal "45127", res.zip
177
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
178
+ assert res.is_us? == false
179
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
180
+ assert_equal "google", res.provider
181
+ end
182
+
183
+ def test_reverse_geocoding_using_specific_geocoder_short_syntax
184
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
185
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
186
+ res = point.reverse_geocode(:using => :google)
187
+
188
+ assert_equal "Nordrhein-Westfalen", res.state
189
+ assert_equal "Essen", res.city
190
+ assert_equal "45127", res.zip
191
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
192
+ assert res.is_us? == false
193
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
194
+ assert_equal "google", res.provider
195
+ end
196
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sayso-geokit
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.5.0.3.001
6
+ platform: ruby
7
+ authors:
8
+ - SaySo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-12-10 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: yajl-ruby
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.7.8
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Geokit Gem - forked and gemified for sayso
39
+ email:
40
+ - sayso@truvolabs.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - Manifest.txt
47
+ - README.markdown
48
+ files:
49
+ - Manifest.txt
50
+ - README.markdown
51
+ - Rakefile
52
+ - lib/geokit/geocoders.rb
53
+ - lib/geokit.rb
54
+ - lib/geokit/mappable.rb
55
+ - lib/geokit/inflector.rb
56
+ - lib/geokit/geocoder_google.rb
57
+ - test/fake_geo_requests.rb
58
+ - test/test_base_geocoder.rb
59
+ - test/test_bounds.rb
60
+ - test/test_geoloc.rb
61
+ - test/test_google_geocoder.rb
62
+ - test/test_latlng.rb
63
+ - test/test_google_reverse_geocoder.rb
64
+ - test/test_inflector.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/sayso/geokit-gem
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: none
93
+ test_files:
94
+ - test/test_base_geocoder.rb
95
+ - test/test_bounds.rb
96
+ - test/test_geoloc.rb
97
+ - test/test_google_geocoder.rb
98
+ - test/test_google_reverse_geocoder.rb
99
+ - test/test_inflector.rb
100
+ - test/test_latlng.rb