sayso-geokit 1.5.0.3.001
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +21 -0
- data/README.markdown +200 -0
- data/Rakefile +22 -0
- data/lib/geokit/geocoder_google.rb +187 -0
- data/lib/geokit/geocoders.rb +119 -0
- data/lib/geokit/inflector.rb +41 -0
- data/lib/geokit/mappable.rb +534 -0
- data/lib/geokit.rb +30 -0
- data/test/fake_geo_requests.rb +424 -0
- data/test/test_base_geocoder.rb +39 -0
- data/test/test_bounds.rb +97 -0
- data/test/test_geoloc.rb +72 -0
- data/test/test_google_geocoder.rb +199 -0
- data/test/test_google_reverse_geocoder.rb +291 -0
- data/test/test_inflector.rb +24 -0
- data/test/test_latlng.rb +196 -0
- metadata +100 -0
@@ -0,0 +1,424 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module FakeGeoRequests
|
5
|
+
#Fake resonses are not exactyl the same like from google for testing purposes
|
6
|
+
|
7
|
+
GOOGLE_FULL=<<-EOF.strip
|
8
|
+
{
|
9
|
+
"name": "100 spear st, san francisco, ca",
|
10
|
+
"Status": {
|
11
|
+
"code": 200,
|
12
|
+
"request": "geocode"
|
13
|
+
},
|
14
|
+
"Placemark": [ {
|
15
|
+
"id": "p1",
|
16
|
+
"address": "100 Spear St, San Francisco, CA 94105, USA",
|
17
|
+
"AddressDetails": {
|
18
|
+
"Accuracy" : 8,
|
19
|
+
"Country" : {
|
20
|
+
"AdministrativeArea" : {
|
21
|
+
"AdministrativeAreaName" : "CA",
|
22
|
+
"SubAdministrativeArea" : {
|
23
|
+
"Locality" : {
|
24
|
+
"LocalityName" : "San Francisco",
|
25
|
+
"PostalCode" : {
|
26
|
+
"PostalCodeNumber" : "94105"
|
27
|
+
},
|
28
|
+
"Thoroughfare" : {
|
29
|
+
"ThoroughfareName" : "100 Spear St"
|
30
|
+
}
|
31
|
+
},
|
32
|
+
"SubAdministrativeAreaName" : "San Francisco"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"CountryName" : "USA",
|
36
|
+
"CountryNameCode" : "US"
|
37
|
+
}
|
38
|
+
},
|
39
|
+
"Point": {
|
40
|
+
"coordinates": [ -122.3940000, 37.7921509, 0 ]
|
41
|
+
}
|
42
|
+
} ]
|
43
|
+
}
|
44
|
+
EOF
|
45
|
+
|
46
|
+
GOOGLE_RESULT_WITH_SUGGESTED_BOUNDS=<<-EOF.strip
|
47
|
+
{
|
48
|
+
"name": "100 spear st, san francisco, ca",
|
49
|
+
"Status": {
|
50
|
+
"code": 200,
|
51
|
+
"request": "geocode"
|
52
|
+
},
|
53
|
+
"Placemark": [ {
|
54
|
+
"id": "p1",
|
55
|
+
"address": "100 Spear St, San Francisco, CA 94105, USA",
|
56
|
+
"AddressDetails": {
|
57
|
+
"Accuracy" : 8,
|
58
|
+
"Country" : {
|
59
|
+
"AdministrativeArea" : {
|
60
|
+
"AdministrativeAreaName" : "CA",
|
61
|
+
"SubAdministrativeArea" : {
|
62
|
+
"Locality" : {
|
63
|
+
"LocalityName" : "San Francisco",
|
64
|
+
"PostalCode" : {
|
65
|
+
"PostalCodeNumber" : "94105"
|
66
|
+
},
|
67
|
+
"Thoroughfare" : {
|
68
|
+
"ThoroughfareName" : "100 Spear St"
|
69
|
+
}
|
70
|
+
},
|
71
|
+
"SubAdministrativeAreaName" : "San Francisco"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"CountryName" : "USA",
|
75
|
+
"CountryNameCode" : "US"
|
76
|
+
}
|
77
|
+
},
|
78
|
+
"ExtendedData": {
|
79
|
+
"LatLonBox": {
|
80
|
+
"north": 37.7952985,
|
81
|
+
"south": 37.7890033,
|
82
|
+
"east": -122.3908524,
|
83
|
+
"west": -122.3971476
|
84
|
+
}
|
85
|
+
},
|
86
|
+
"Point": {
|
87
|
+
"coordinates": [ -122.3940000, 37.7921509, 0 ]
|
88
|
+
}
|
89
|
+
} ]
|
90
|
+
}
|
91
|
+
EOF
|
92
|
+
|
93
|
+
GOOGLE_CITY=<<-EOF.strip
|
94
|
+
{
|
95
|
+
"name": "San Francisco",
|
96
|
+
"Status": {
|
97
|
+
"code": 200,
|
98
|
+
"request": "geocode"
|
99
|
+
},
|
100
|
+
"Placemark": [ {
|
101
|
+
"id": "p1",
|
102
|
+
"address": "San Francisco, CA, USA",
|
103
|
+
"AddressDetails": {
|
104
|
+
"Accuracy" : 4,
|
105
|
+
"Country" : {
|
106
|
+
"AdministrativeArea" : {
|
107
|
+
"AdministrativeAreaName" : "CA",
|
108
|
+
"SubAdministrativeArea" : {
|
109
|
+
"Locality" : {
|
110
|
+
"LocalityName" : "San Francisco"
|
111
|
+
},
|
112
|
+
"SubAdministrativeAreaName" : "San Francisco"
|
113
|
+
}
|
114
|
+
},
|
115
|
+
"CountryName" : "USA",
|
116
|
+
"CountryNameCode" : "US"
|
117
|
+
}
|
118
|
+
},
|
119
|
+
|
120
|
+
"Point": {
|
121
|
+
"coordinates": [ -122.4194155, 37.7749295, 0 ]
|
122
|
+
}
|
123
|
+
} ]
|
124
|
+
}
|
125
|
+
EOF
|
126
|
+
|
127
|
+
GOOGLE_MULTI=<<-EOF
|
128
|
+
{
|
129
|
+
"name": "via Sandro Pertini 8, Ossona, MI",
|
130
|
+
"Status": {
|
131
|
+
"code": 200,
|
132
|
+
"request": "geocode"
|
133
|
+
},
|
134
|
+
"Placemark": [ {
|
135
|
+
"id": "p1",
|
136
|
+
"address": "Via Sandro Pertini, 8, 20010 Mesero Milan, Italy",
|
137
|
+
"AddressDetails": {
|
138
|
+
"Accuracy" : 8,
|
139
|
+
"Country" : {
|
140
|
+
"AdministrativeArea" : {
|
141
|
+
"AdministrativeAreaName" : "Lombardia",
|
142
|
+
"SubAdministrativeArea" : {
|
143
|
+
"Locality" : {
|
144
|
+
"LocalityName" : "Mesero",
|
145
|
+
"PostalCode" : {
|
146
|
+
"PostalCodeNumber" : "20010"
|
147
|
+
},
|
148
|
+
"Thoroughfare" : {
|
149
|
+
"ThoroughfareName" : "Via Sandro Pertini, 8"
|
150
|
+
}
|
151
|
+
},
|
152
|
+
"SubAdministrativeAreaName" : "MI"
|
153
|
+
}
|
154
|
+
},
|
155
|
+
"CountryName" : "Italia",
|
156
|
+
"CountryNameCode" : "IT"
|
157
|
+
}
|
158
|
+
},
|
159
|
+
"ExtendedData": {
|
160
|
+
"LatLonBox": {
|
161
|
+
"north": 45.4997707,
|
162
|
+
"south": 45.4934754,
|
163
|
+
"east": 8.8558512,
|
164
|
+
"west": 8.8495559
|
165
|
+
}
|
166
|
+
},
|
167
|
+
"Point": {
|
168
|
+
"coordinates": [ 8.8526940, 45.4966218, 0 ]
|
169
|
+
}
|
170
|
+
},{
|
171
|
+
"id": "p2",
|
172
|
+
"address": "Via Sandro Pertini, 8, 20010 Mesero Milan, Italy",
|
173
|
+
"AddressDetails": {
|
174
|
+
"Accuracy" : 8,
|
175
|
+
"Country" : {
|
176
|
+
"AdministrativeArea" : {
|
177
|
+
"AdministrativeAreaName" : "Lombardia",
|
178
|
+
"SubAdministrativeArea" : {
|
179
|
+
"Locality" : {
|
180
|
+
"LocalityName" : "Mesero",
|
181
|
+
"PostalCode" : {
|
182
|
+
"PostalCodeNumber" : "20010"
|
183
|
+
},
|
184
|
+
"Thoroughfare" : {
|
185
|
+
"ThoroughfareName" : "Via Sandro Pertini, 8"
|
186
|
+
}
|
187
|
+
},
|
188
|
+
"SubAdministrativeAreaName" : "MI"
|
189
|
+
}
|
190
|
+
},
|
191
|
+
"CountryName" : "Italia",
|
192
|
+
"CountryNameCode" : "IT"
|
193
|
+
}
|
194
|
+
},
|
195
|
+
"ExtendedData": {
|
196
|
+
"LatLonBox": {
|
197
|
+
"north": 45.4997707,
|
198
|
+
"south": 45.4934754,
|
199
|
+
"east": 8.8558512,
|
200
|
+
"west": 8.8495559
|
201
|
+
}
|
202
|
+
},
|
203
|
+
"Point": {
|
204
|
+
"coordinates": [ 8.8526940, 45.4966218, 0 ]
|
205
|
+
}
|
206
|
+
} ]
|
207
|
+
}
|
208
|
+
EOF
|
209
|
+
|
210
|
+
GOOGLE_REVERSE_MADRID=<<-EOF
|
211
|
+
{
|
212
|
+
"name": "40.416741,-3.703250",
|
213
|
+
"Status": {
|
214
|
+
"code": 200,
|
215
|
+
"request": "geocode"
|
216
|
+
},
|
217
|
+
"Placemark": [ {
|
218
|
+
"id": "p1",
|
219
|
+
"address": "Calle de las Carretas, 3, 28012 Madrid, Spain",
|
220
|
+
"AddressDetails": {
|
221
|
+
"Accuracy" : 8,
|
222
|
+
"Country" : {
|
223
|
+
"AdministrativeArea" : {
|
224
|
+
"AdministrativeAreaName" : "Comunidad de Madrid",
|
225
|
+
"SubAdministrativeArea" : {
|
226
|
+
"Locality" : {
|
227
|
+
"LocalityName" : "Madrid",
|
228
|
+
"PostalCode" : {
|
229
|
+
"PostalCodeNumber" : "28012"
|
230
|
+
},
|
231
|
+
"Thoroughfare" : {
|
232
|
+
"ThoroughfareName" : "Calle de las Carretas, 3"
|
233
|
+
}
|
234
|
+
},
|
235
|
+
"SubAdministrativeAreaName" : "Madrid"
|
236
|
+
}
|
237
|
+
},
|
238
|
+
"CountryName" : "España",
|
239
|
+
"CountryNameCode" : "ES"
|
240
|
+
}
|
241
|
+
},
|
242
|
+
"ExtendedData": {
|
243
|
+
"LatLonBox": {
|
244
|
+
"north": 40.4197745,
|
245
|
+
"south": 40.4134793,
|
246
|
+
"east": -3.7000393,
|
247
|
+
"west": -3.7063345
|
248
|
+
}
|
249
|
+
},
|
250
|
+
"Point": {
|
251
|
+
"coordinates": [ -3.7031869, 40.4166269, 0 ]
|
252
|
+
}
|
253
|
+
}, {
|
254
|
+
"id": "p2",
|
255
|
+
"address": "Calle de las Carretas, 3, 28012 Madrid, Spain",
|
256
|
+
"AddressDetails": {
|
257
|
+
"Accuracy" : 8,
|
258
|
+
"Country" : {
|
259
|
+
"AdministrativeArea" : {
|
260
|
+
"AdministrativeAreaName" : "Comunidad de Madrid",
|
261
|
+
"SubAdministrativeArea" : {
|
262
|
+
"Locality" : {
|
263
|
+
"LocalityName" : "Madrid",
|
264
|
+
"PostalCode" : {
|
265
|
+
"PostalCodeNumber" : "28012"
|
266
|
+
},
|
267
|
+
"Thoroughfare" : {
|
268
|
+
"ThoroughfareName" : "Calle de las Carretas, 3"
|
269
|
+
}
|
270
|
+
},
|
271
|
+
"SubAdministrativeAreaName" : "Madrid"
|
272
|
+
}
|
273
|
+
},
|
274
|
+
"CountryName" : "España",
|
275
|
+
"CountryNameCode" : "ES"
|
276
|
+
}
|
277
|
+
},
|
278
|
+
"ExtendedData": {
|
279
|
+
"LatLonBox": {
|
280
|
+
"north": 40.4197745,
|
281
|
+
"south": 40.4134793,
|
282
|
+
"east": -3.7000393,
|
283
|
+
"west": -3.7063345
|
284
|
+
}
|
285
|
+
},
|
286
|
+
"Point": {
|
287
|
+
"coordinates": [ -3.7031869, 40.4166269, 0 ]
|
288
|
+
}
|
289
|
+
} , {
|
290
|
+
"id": "p3",
|
291
|
+
"address": "Calle de las Carretas, 3, 28012 Madrid, Spain",
|
292
|
+
"AddressDetails": {
|
293
|
+
"Accuracy" : 8,
|
294
|
+
"Country" : {
|
295
|
+
"AdministrativeArea" : {
|
296
|
+
"AdministrativeAreaName" : "Comunidad de Madrid",
|
297
|
+
"SubAdministrativeArea" : {
|
298
|
+
"Locality" : {
|
299
|
+
"LocalityName" : "Madrid",
|
300
|
+
"PostalCode" : {
|
301
|
+
"PostalCodeNumber" : "28012"
|
302
|
+
},
|
303
|
+
"Thoroughfare" : {
|
304
|
+
"ThoroughfareName" : "Calle de las Carretas, 3"
|
305
|
+
}
|
306
|
+
},
|
307
|
+
"SubAdministrativeAreaName" : "Madrid"
|
308
|
+
}
|
309
|
+
},
|
310
|
+
"CountryName" : "España",
|
311
|
+
"CountryNameCode" : "ES"
|
312
|
+
}
|
313
|
+
},
|
314
|
+
"ExtendedData": {
|
315
|
+
"LatLonBox": {
|
316
|
+
"north": 40.4197745,
|
317
|
+
"south": 40.4134793,
|
318
|
+
"east": -3.7000393,
|
319
|
+
"west": -3.7063345
|
320
|
+
}
|
321
|
+
},
|
322
|
+
"Point": {
|
323
|
+
"coordinates": [ -3.7031869, 40.4166269, 0 ]
|
324
|
+
}
|
325
|
+
} ]
|
326
|
+
}
|
327
|
+
EOF
|
328
|
+
|
329
|
+
GOOGLE_COUNTRY_CODE_BIASED_RESULT=<<-EOF.strip
|
330
|
+
{
|
331
|
+
"name": "Syracuse",
|
332
|
+
"Status": {
|
333
|
+
"code": 200,
|
334
|
+
"request": "geocode"
|
335
|
+
},
|
336
|
+
"Placemark": [ {
|
337
|
+
"id": "p1",
|
338
|
+
"address": "Syracuse, Italy",
|
339
|
+
"AddressDetails": {
|
340
|
+
"Accuracy" : 3,
|
341
|
+
"Country" : {
|
342
|
+
"AdministrativeArea" : {
|
343
|
+
"AdministrativeAreaName" : "Sicile",
|
344
|
+
"SubAdministrativeArea" : {
|
345
|
+
"SubAdministrativeAreaName" : "SR"
|
346
|
+
}
|
347
|
+
},
|
348
|
+
"CountryName" : "Italie",
|
349
|
+
"CountryNameCode" : "IT"
|
350
|
+
}
|
351
|
+
},
|
352
|
+
"ExtendedData": {
|
353
|
+
"LatLonBox": {
|
354
|
+
"north": 37.3474070,
|
355
|
+
"south": 36.7775664,
|
356
|
+
"east": 15.4978552,
|
357
|
+
"west": 14.4733800
|
358
|
+
}
|
359
|
+
},
|
360
|
+
"Point": {
|
361
|
+
"coordinates": [ 14.9856176, 37.0630218, 0 ]
|
362
|
+
}
|
363
|
+
} ]
|
364
|
+
}
|
365
|
+
|
366
|
+
EOF
|
367
|
+
|
368
|
+
GOOGLE_BOUNDS_BIASED_RESULT=<<-EOF.strip
|
369
|
+
{
|
370
|
+
"name": "Winnetka,Ca",
|
371
|
+
"Status": {
|
372
|
+
"code": 200,
|
373
|
+
"request": "geocode"
|
374
|
+
},
|
375
|
+
"Placemark": [ {
|
376
|
+
"id": "p1",
|
377
|
+
"address": "Winnetka, Los Angeles, CA, USA",
|
378
|
+
"AddressDetails": {
|
379
|
+
"Accuracy" : 4,
|
380
|
+
"Country" : {
|
381
|
+
"AdministrativeArea" : {
|
382
|
+
"AdministrativeAreaName" : "CA",
|
383
|
+
"SubAdministrativeArea" : {
|
384
|
+
"Locality" : {
|
385
|
+
"DependentLocality" : {
|
386
|
+
"DependentLocalityName" : "Winnetka"
|
387
|
+
},
|
388
|
+
"LocalityName" : "Los Angeles"
|
389
|
+
},
|
390
|
+
"SubAdministrativeAreaName" : "Los Angeles"
|
391
|
+
}
|
392
|
+
},
|
393
|
+
"CountryName" : "USA",
|
394
|
+
"CountryNameCode" : "US"
|
395
|
+
}
|
396
|
+
},
|
397
|
+
"ExtendedData": {
|
398
|
+
"LatLonBox": {
|
399
|
+
"north": 34.2317822,
|
400
|
+
"south": 34.1948738,
|
401
|
+
"east": -118.5390952,
|
402
|
+
"west": -118.6031248
|
403
|
+
}
|
404
|
+
},
|
405
|
+
"Point": {
|
406
|
+
"coordinates": [ -118.5711100, 34.2133300, 0 ]
|
407
|
+
}
|
408
|
+
} ]
|
409
|
+
}
|
410
|
+
|
411
|
+
EOF
|
412
|
+
|
413
|
+
GOOGLE_TOO_MANY=<<-EOF.strip
|
414
|
+
{
|
415
|
+
"name": "3435345345",
|
416
|
+
"Status": {
|
417
|
+
"code": 620,
|
418
|
+
"request": "geocode"
|
419
|
+
}
|
420
|
+
}
|
421
|
+
|
422
|
+
EOF
|
423
|
+
|
424
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mocha'
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/geokit')
|
5
|
+
|
6
|
+
# Base class for testing geocoders.
|
7
|
+
class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
8
|
+
|
9
|
+
class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
|
10
|
+
def self.do_get(url)
|
11
|
+
sleep(2)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Defines common test fixtures.
|
16
|
+
def setup
|
17
|
+
@address = 'San Francisco, CA'
|
18
|
+
@full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
|
19
|
+
@full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
|
20
|
+
|
21
|
+
@latlng = Geokit::LatLng.new(37.7742, -122.417068)
|
22
|
+
@success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_timeout_call_web_service
|
26
|
+
url = "http://www.anything.com"
|
27
|
+
Geokit::Geocoders::request_timeout = 1
|
28
|
+
assert_raise Geokit::TimeoutError do
|
29
|
+
Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_successful_call_web_service
|
34
|
+
url = "http://www.anything.com"
|
35
|
+
Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
|
36
|
+
assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/test_bounds.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/geokit')
|
3
|
+
|
4
|
+
class BoundsTest < Test::Unit::TestCase
|
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
|
+
def test_bounds_to_span
|
75
|
+
sw = Geokit::LatLng.new(32, -96)
|
76
|
+
ne = Geokit::LatLng.new(40, -70)
|
77
|
+
bounds = Geokit::Bounds.new(sw, ne)
|
78
|
+
|
79
|
+
assert_equal Geokit::LatLng.new(8, 26), bounds.to_span
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_bounds_to_span_with_bounds_crossing_prime_meridian
|
83
|
+
sw = Geokit::LatLng.new(20, -70)
|
84
|
+
ne = Geokit::LatLng.new(40, 100)
|
85
|
+
bounds = Geokit::Bounds.new(sw, ne)
|
86
|
+
|
87
|
+
assert_equal Geokit::LatLng.new(20, 170), bounds.to_span
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_bounds_to_span_with_bounds_crossing_dateline
|
91
|
+
sw = Geokit::LatLng.new(20, 100)
|
92
|
+
ne = Geokit::LatLng.new(40, -70)
|
93
|
+
bounds = Geokit::Bounds.new(sw, ne)
|
94
|
+
|
95
|
+
assert_equal Geokit::LatLng.new(20, 190), bounds.to_span
|
96
|
+
end
|
97
|
+
end
|
data/test/test_geoloc.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../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_success
|
17
|
+
assert !@loc.success?
|
18
|
+
@loc.success = false
|
19
|
+
assert !@loc.success?
|
20
|
+
@loc.success = true
|
21
|
+
assert @loc.success?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_street_number
|
25
|
+
@loc.street_address = '123 Spear St.'
|
26
|
+
assert_equal '123', @loc.street_number
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_street_name
|
30
|
+
@loc.street_address = '123 Spear St.'
|
31
|
+
assert_equal 'Spear St.', @loc.street_name
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_city
|
35
|
+
@loc.city = "san francisco"
|
36
|
+
assert_equal 'San Francisco', @loc.city
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_full_address
|
40
|
+
@loc.city = 'San Francisco'
|
41
|
+
@loc.state = 'CA'
|
42
|
+
@loc.zip = '94105'
|
43
|
+
@loc.country_code = 'US'
|
44
|
+
assert_equal 'San Francisco, CA, 94105, US', @loc.full_address
|
45
|
+
@loc.full_address = 'Irving, TX, 75063, US'
|
46
|
+
assert_equal 'Irving, TX, 75063, US', @loc.full_address
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_hash
|
50
|
+
@loc.city = 'San Francisco'
|
51
|
+
@loc.state = 'CA'
|
52
|
+
@loc.zip = '94105'
|
53
|
+
@loc.country_code = 'US'
|
54
|
+
@another = Geokit::GeoLoc.new @loc.to_hash
|
55
|
+
assert_equal @loc, @another
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_all
|
59
|
+
assert_equal [@loc], @loc.all
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_to_yaml
|
63
|
+
@loc.city = 'San Francisco'
|
64
|
+
@loc.state = 'CA'
|
65
|
+
@loc.zip = '94105'
|
66
|
+
@loc.country_code = 'US'
|
67
|
+
assert_equal(
|
68
|
+
"--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nsuccess: false\nzip: \"94105\"\n",
|
69
|
+
@loc.to_yaml)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|