-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
61 lines (47 loc) · 1.22 KB
/
main_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
package geolib
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Geohash(t *testing.T) {
assert := assert.New(t)
location := GeoLocation{
lat: 48.668683,
lon: -4.329321,
}
encoded := GeoEncode(&location, 9)
t.Logf("Encoded: [%s]", encoded)
decoded := GeoDecode("gbsuv7z7x")
t.Logf("Decoded: [%v, %v]", decoded.lat, decoded.lon)
assert.Equal(location.lat, location.lat, "Wrong lat")
assert.Equal(decoded.lon, decoded.lon, "Wrong lon")
}
func Test_DistanceBoundingCheck(t *testing.T) {
assert := assert.New(t)
var points = []GeoLocation{
GeoLocation{
lat: -20.279877,
lon: 57.518932,
},
GeoLocation{
lat: -20.279343,
lon: 57.518374,
},
GeoLocation{
lat: -20.282030,
lon: 57.520021,
},
GeoLocation{
lat: -20.290418,
lon: 57.535239,
},
}
topLeft, bottomRight := DistanceBoundingCheck(points[0].lat, points[0].lon, 1.0)
t.Logf("Result: topLeft: [%v, %v], bottomRight: [%v, %v]", topLeft.lat, topLeft.lon, bottomRight.lat, bottomRight.lon)
expected := []bool{true, true, true, false}
for idx, p := range points {
r := IsGeoLocationInArea(&p, &topLeft, &bottomRight)
t.Logf("Decoded: [%v, %v] - %v", p.lat, p.lon, r)
assert.Equal(expected[idx], r)
}
}