-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_test.go
77 lines (74 loc) · 2.04 KB
/
process_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
package changes
import (
"reflect"
"testing"
osm "github.com/omniscale/go-osm"
)
func TestFilterNodes(t *testing.T) {
for _, tc := range []struct {
bbox LimitTo
nodes []osm.Node
want []osm.Node
numInserted int
}{
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{},
want: []osm.Node{},
numInserted: 0,
},
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{{Long: 0, Lat: 0, Element: osm.Element{ID: 1}}},
want: []osm.Node{{Long: 0, Lat: 0, Element: osm.Element{ID: 1}}},
numInserted: 1,
},
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{{Long: -0.0001, Lat: 0, Element: osm.Element{ID: 1}}},
want: []osm.Node{},
numInserted: 0,
},
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{{Long: 1, Lat: 10.01, Element: osm.Element{ID: 1}}},
want: []osm.Node{},
numInserted: 0,
},
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{
{Long: 1, Lat: 1, Element: osm.Element{ID: 1}},
{Long: 20, Lat: 0, Element: osm.Element{ID: 2}},
{Long: 2, Lat: 2, Element: osm.Element{ID: 3}},
},
want: []osm.Node{
{Long: 1, Lat: 1, Element: osm.Element{ID: 1}},
{Long: 2, Lat: 2, Element: osm.Element{ID: 3}},
},
numInserted: 2,
},
{
bbox: [4]float64{0, 0, 10, 10},
nodes: []osm.Node{
{Long: 1, Lat: 1, Element: osm.Element{ID: 1}},
{Long: 2, Lat: 2, Element: osm.Element{ID: 2}},
{Long: 20, Lat: 2, Element: osm.Element{ID: 3}},
},
want: []osm.Node{
{Long: 1, Lat: 1, Element: osm.Element{ID: 1}},
{Long: 2, Lat: 2, Element: osm.Element{ID: 2}},
},
numInserted: 2,
},
} {
insertedNodes := map[int64]struct{}{}
got := filterNodes(tc.nodes, &tc.bbox, insertedNodes)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("unexpected result got:\n\t%v\nwant:\n\t%v", got, tc.want)
}
if len(insertedNodes) != tc.numInserted {
t.Errorf("expected %d entries in insertedNodes, got %d", tc.numInserted, len(insertedNodes))
}
}
}