-
Notifications
You must be signed in to change notification settings - Fork 48
/
polygon_test.go
111 lines (103 loc) · 1.94 KB
/
polygon_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package osm
import (
"reflect"
"testing"
)
func TestWay_Polygon(t *testing.T) {
w := &Way{}
w.Nodes = WayNodes{
{ID: 1}, {ID: 2},
{ID: 3}, {ID: 1},
}
w2 := &Way{Nodes: w.Nodes[:3]}
if w2.Polygon() {
t.Errorf("should be over 3 nodes to be polygon")
}
w.Nodes[3].ID = 10
if w2.Polygon() {
t.Errorf("first and last node must have same id")
}
c := polyConditions[1].Values
if !reflect.DeepEqual(c, []string{"elevator", "escape", "rest_area", "services"}) {
t.Errorf("values not sorted")
}
cases := []struct {
name string
tags []Tag
value bool
}{
{
name: "area no overrides",
tags: []Tag{
{Key: "area", Value: "no"},
{Key: "building", Value: "yes"},
},
value: false,
},
{
name: "non-empty area and not no",
tags: []Tag{
{Key: "area", Value: "maybe"},
{Key: "building", Value: "no"},
},
value: true,
},
{
name: "at least one condition met",
tags: []Tag{
{Key: "building", Value: "no"},
{Key: "boundary", Value: "yes"},
},
value: true,
},
{
name: "match within whitelist",
tags: []Tag{
{Key: "railway", Value: "station"},
},
value: true,
},
{
name: "not match if not within whitelist",
tags: []Tag{
{Key: "railway", Value: "line"},
},
value: false,
},
{
name: "not match within blacklist",
tags: []Tag{
{Key: "man_made", Value: "cutline"},
},
value: false,
},
{
name: "match if not within blacklist",
tags: []Tag{
{Key: "man_made", Value: "thing"},
},
value: true,
},
{
name: "indoor anything is a polygon",
tags: []Tag{
{Key: "indoor", Value: "anything"},
},
value: true,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
w := &Way{
Nodes: WayNodes{
{ID: 1}, {ID: 2},
{ID: 3}, {ID: 1},
},
Tags: Tags(tc.tags),
}
if v := w.Polygon(); v != tc.value {
t.Errorf("not correctly detected, %v != %v", v, tc.value)
}
})
}
}