-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeomodel_test.go
83 lines (66 loc) · 1.71 KB
/
geomodel_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
package geomodel
import (
"log"
"sort"
"testing"
)
/*type LocationCapable interface {
Latitude() float64
Longitude() float64
Key() string
Geocells() []string
}*/
type Place struct {
lat, lon float64
key string
geocells []string
}
func (p Place) Latitude() float64 {
return p.lat
}
func (p Place) Longitude() float64 {
return p.lon
}
func (p Place) Key() string {
return p.key
}
func (p Place) Geocells() []string {
return p.geocells
}
func TestGeoHash(t *testing.T) {
log.Printf("GeoHash: %s", GeoCell(53.12869, 8.18976, 6))
}
func TestDecodeGeoHash(t *testing.T) {
lat, lon := DecodeGeoHash(GeoHash(53.12869, 8.18976, 13))
log.Printf("DecodeLat: %f, DecodeLon: %f", lat, lon)
}
func TestProximityFetch(t *testing.T) {
// Example Places
var places = []LocationCapable{Place{54, 8, "1", GeoCells(54, 8, 10)}, Place{50, 8, "2", GeoCells(50, 8, 10)}, Place{49, 8, "3", GeoCells(49, 8, 10)}, Place{48, 8, "4", GeoCells(48, 8, 10)}, Place{47, 8, "5", GeoCells(47, 8, 10)}}
var result = ProximityFetch(50, 8, 20, 300, func(cells []string) []LocationCapable {
// Implementing our own dirty thing here.
var result []LocationCapable = make([]LocationCapable, 0)
for _, place := range places {
var added bool = false
for _, c := range place.Geocells() {
index := sort.SearchStrings(cells, c)
if index < len(cells) {
if place != nil {
result = append(result, place)
}
}
}
if added {
break
}
}
return result
}, 10)
if len(result) > 1 {
t.Fail()
}
if result[0].Latitude() != 50 || result[0].Longitude() != 8 {
t.Fail()
}
// ProximityFetch(lat, lon float64, maxResults int, maxDistance float64, search RepositorySearch, maxResolution int) []LocationCapable
}