forked from TomiHiltunen/geohash-golang
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeohash_test.go
92 lines (83 loc) · 1.57 KB
/
geohash_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package geohash
import "testing"
type geohashTest struct {
input string
output *BoundingBox
}
func TestDecode(t *testing.T) {
var tests = []geohashTest{
geohashTest{
"d",
&BoundingBox{
LatLng{0, -90},
LatLng{45, -45},
LatLng{22.5, -67.5},
},
},
geohashTest{
"dr",
&BoundingBox{
LatLng{39.375, -78.75},
LatLng{45, -67.5},
LatLng{42.1875, -73.125},
},
},
geohashTest{
"dr1",
&BoundingBox{
LatLng{39.375, -77.34375},
LatLng{40.78125, -75.9375},
LatLng{40.078125, -76.640625},
},
},
geohashTest{
"dr12",
&BoundingBox{
LatLng{39.375, -76.9921875},
LatLng{39.55078125, -76.640625},
LatLng{39.462890625, -76.81640625},
},
},
}
for _, test := range tests {
box := Decode(test.input)
if !equalBoundingBoxes(test.output, box) {
t.Errorf("expected bounding box %v, got %v", test.output, box)
}
}
}
func equalBoundingBoxes(b1, b2 *BoundingBox) bool {
return b1.ne == b2.ne &&
b1.sw == b2.sw &&
b1.center == b1.center
}
type encodeTest struct {
latlng LatLng
geohash string
}
func TestEncode(t *testing.T) {
var tests = []encodeTest{
encodeTest{
LatLng{39.55078125, -76.640625},
"dr12zzzzzzzz",
},
encodeTest{
LatLng{39.5507, -76.6406},
"dr18bpbp88fe",
},
encodeTest{
LatLng{39.55, -76.64},
"dr18bpb7qw65",
},
encodeTest{
LatLng{39, -76},
"dqcvyedrrwut",
},
}
for _, test := range tests {
geohash := Encode(test.latlng.lat, test.latlng.lng)
if test.geohash != geohash {
t.Errorf("expectd %s, got %s", test.geohash, geohash)
}
}
}