forked from hailocab/go-geoindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo-index_test.go
52 lines (41 loc) · 851 Bytes
/
geo-index_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
package geoindex
import (
"strconv"
"testing"
)
type TestEntry struct {
id int
count int
}
func (e *TestEntry) Add(p Point) {
e.count++
}
func (e *TestEntry) Remove(_ Point) {
e.count--
}
func (e *TestEntry) String() string {
return strconv.Itoa(e.count)
}
var totalEntries = 0
var newTestEntry = func() interface{} {
totalEntries++
result := TestEntry{totalEntries, 0}
return &result
}
func TestGeoIndexRange(t *testing.T) {
index := newGeoIndex(Km(0.1), newTestEntry)
for _, point := range tubeStations() {
indexEntry := index.AddEntryAt(point)
entry := (indexEntry).(*TestEntry)
entry.Add(point)
}
entries := index.Range(oxford, embankment)
count := 0
for _, entry := range entries {
testEntry := (entry).(*TestEntry)
count += testEntry.count
}
if count != 6 {
t.Error("Invalid number of stations")
}
}