-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeohash_test.go
82 lines (73 loc) · 1.37 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
package gogeohash
import (
"fmt"
"testing"
)
func BenchmarkToChars(b *testing.B) {
inputs := []uint64{
14520001368503071193,
}
for _, v := range inputs {
n := fmt.Sprintf("%s_%d", b.Name(), v)
b.Run(n, func(b *testing.B) {
for i := 0; i < b.N; i++ {
toChars(v)
}
})
}
}
func BenchmarkToCharsUnrolled(b *testing.B) {
inputs := []uint64{
14520001368503071193,
}
for _, v := range inputs {
n := fmt.Sprintf("%s_%d", b.Name(), v)
b.Run(n, func(b *testing.B) {
for i := 0; i < b.N; i++ {
toCharsUnrolled(v)
}
})
}
}
func TestGeoHashEncode(t *testing.T) {
testcases := []struct {
lon float64
lat float64
exp uint64
}{
{
lat: 12.34,
lon: 56.78,
exp: 14520001368503071193,
},
}
for i, v := range testcases {
n := fmt.Sprintf("%s_%d_%f_%f", t.Name(), i, v.lat, v.lon)
t.Run(n, func(t *testing.T) {
r := GeoHashEncode(v.lat, v.lon)
if r != v.exp {
t.Errorf("%s: expected: %d got: %d", t.Name(), v.exp, r)
}
})
}
}
func TestToChars(t *testing.T) {
testcases := []struct {
input uint64
chars string
}{
{
input: 14520001368503071193,
chars: "t60qhn3vtysx",
},
}
for _, v := range testcases {
n := fmt.Sprintf("%s_%d", t.Name(), v.input)
t.Run(n, func(t *testing.T) {
r := toChars(v.input)
if r != v.chars {
t.Errorf("%s: expected: %s got: %s", t.Name(), v.chars, r)
}
})
}
}