-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfilter_test.go
49 lines (38 loc) · 1.11 KB
/
filter_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
package topojson
import (
"testing"
"github.com/cheekybits/is"
geojson "github.com/paulmach/go.geojson"
)
func TestFilter(t *testing.T) {
is := is.New(t)
fc := geojson.NewFeatureCollection()
fc.AddFeature(NewTestFeature("one", geojson.NewLineStringGeometry([][]float64{
{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0},
})))
fc.AddFeature(NewTestFeature("two", geojson.NewLineStringGeometry([][]float64{
{1, 0}, {2, 0}, {2, 1}, {1, 1}, {1, 0},
})))
fc.AddFeature(NewTestFeature("three", geojson.NewLineStringGeometry([][]float64{
{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1},
})))
topo := NewTopology(fc, nil)
is.NotNil(topo)
al := len(topo.Arcs)
is.True(al > 0)
topo2 := topo.Filter([]string{"one", "two"})
is.NotNil(topo2)
al2 := len(topo2.Arcs)
is.True(al > al2) // Arc has been eliminated
expected := map[string][][]float64{
"one": {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}},
"two": {{1, 0}, {2, 0}, {2, 1}, {1, 1}, {1, 0}},
}
fc2 := topo2.ToGeoJSON()
is.NotNil(fc2)
for _, feat := range fc2.Features {
exp, ok := expected[feat.ID.(string)]
is.True(ok)
is.Equal(feat.Geometry.LineString, exp)
}
}