forked from twpayne/go-geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultipolygon_test.go
121 lines (114 loc) · 3 KB
/
multipolygon_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
112
113
114
115
116
117
118
119
120
121
package geom
import (
"reflect"
"testing"
)
type testMultiPolygon struct {
layout Layout
stride int
coords [][][]Coord
flatCoords []float64
endss [][]int
bounds *Bounds
}
func testMultiPolygonEquals(t *testing.T, mp *MultiPolygon, tmp *testMultiPolygon) {
if err := mp.verify(); err != nil {
t.Error(err)
}
if mp.Layout() != tmp.layout {
t.Errorf("mp.Layout() == %v, want %v", mp.Layout(), tmp.layout)
}
if mp.Stride() != tmp.stride {
t.Errorf("mp.Stride() == %v, want %v", mp.Stride(), tmp.stride)
}
if !reflect.DeepEqual(mp.Coords(), tmp.coords) {
t.Errorf("mp.Coords() == %v, want %v", mp.Coords(), tmp.coords)
}
if !reflect.DeepEqual(mp.FlatCoords(), tmp.flatCoords) {
t.Errorf("mp.FlatCoords() == %v, want %v", mp.FlatCoords(), tmp.flatCoords)
}
if !reflect.DeepEqual(mp.Endss(), tmp.endss) {
t.Errorf("mp.Endss() == %v, want %v", mp.Endss(), tmp.endss)
}
if !reflect.DeepEqual(mp.Bounds(), tmp.bounds) {
t.Errorf("mp.Bounds() == %v, want %v", mp.Bounds(), tmp.bounds)
}
if got := mp.NumPolygons(); got != len(tmp.coords) {
t.Errorf("mp.NumPolygons() == %v, want %v", got, len(tmp.coords))
}
for i, c := range tmp.coords {
want := NewPolygon(mp.Layout()).MustSetCoords(c)
if got := mp.Polygon(i); !reflect.DeepEqual(got, want) {
t.Errorf("mp.Polygon(%v) == %v, want %v", i, got, want)
}
}
}
func TestMultiPolygon(t *testing.T) {
for _, c := range []struct {
mp *MultiPolygon
tmp *testMultiPolygon
}{
{
mp: NewMultiPolygon(XY).MustSetCoords([][][]Coord{{{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}}}),
tmp: &testMultiPolygon{
layout: XY,
stride: 2,
coords: [][][]Coord{{{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}}},
flatCoords: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
endss: [][]int{{6, 12}},
bounds: NewBounds(XY).Set(1, 2, 11, 12),
},
},
} {
testMultiPolygonEquals(t, c.mp, c.tmp)
}
}
func TestMultiPolygonClone(t *testing.T) {
p1 := NewMultiPolygon(XY).MustSetCoords([][][]Coord{{{{1, 2}, {3, 4}, {5, 6}}}})
if p2 := p1.Clone(); aliases(p1.FlatCoords(), p2.FlatCoords()) {
t.Error("Clone() should not alias flatCoords")
}
}
func TestMultiPolygonStrideMismatch(t *testing.T) {
for _, c := range []struct {
layout Layout
coords [][][]Coord
err error
}{
{
layout: XY,
coords: nil,
err: nil,
},
{
layout: XY,
coords: [][][]Coord{},
err: nil,
},
{
layout: XY,
coords: [][][]Coord{{{{1, 2}, {}}}},
err: ErrStrideMismatch{Got: 0, Want: 2},
},
{
layout: XY,
coords: [][][]Coord{{{{1, 2}, {1}}}},
err: ErrStrideMismatch{Got: 1, Want: 2},
},
{
layout: XY,
coords: [][][]Coord{{{{1, 2}, {3, 4}}}},
err: nil,
},
{
layout: XY,
coords: [][][]Coord{{{{1, 2}, {3, 4, 5}}}},
err: ErrStrideMismatch{Got: 3, Want: 2},
},
} {
mp := NewMultiPolygon(c.layout)
if _, err := mp.SetCoords(c.coords); err != c.err {
t.Errorf("mp.SetCoords(%v) == %v, want %v", c.coords, err, c.err)
}
}
}