forked from jasonwinn/geocoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocoding_test.go
47 lines (40 loc) · 1.29 KB
/
geocoding_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package geocoder
import (
"testing"
)
const (
city = "Seattle"
state = "WA"
postalCode = "98164"
seattleLat = 47.603832
seattleLng = -122.330062
antwerpLat = 51.221110
antwerpLng = 4.399708
beijingLat = 39.905909
beijingLng = 116.391349
)
func TestGeocode(t *testing.T) {
query := "Seattle WA"
lat, lng := Geocode(query)
if lat != seattleLat || lng != seattleLng {
t.Errorf("Seattle: Expected %f, %f ~ Received %f, %f", seattleLat, seattleLng, lat, lng)
}
}
func TestReverseGeoCode(t *testing.T) {
address := ReverseGeocode(seattleLat, seattleLng)
if address.City != city || address.State != state || address.PostalCode != postalCode {
t.Errorf("Seattle (reverse): Expected %s %s %s ~ Received %s %s %s",
city, state, postalCode, address.City, address.State, address.PostalCode)
}
}
func TestBatchGeocode(t *testing.T) {
latLngs := BatchGeocode([]string{"Antwerp,Belgium", "Beijing,China"})
antwerp := latLngs[0]
if antwerp.Lat != antwerpLat || antwerp.Lng != antwerpLng {
t.Errorf("Antwerp: Expected %f, %f ~ Received %f, %f", antwerpLat, antwerpLng, antwerp.Lat, antwerp.Lng)
}
beijing := latLngs[1]
if beijing.Lat != beijingLat || beijing.Lng != beijingLng {
t.Errorf("Beijng: Expected %f, %f ~ Received %f, %f", beijingLat, beijingLng, beijing.Lat, beijing.Lng)
}
}