-
Notifications
You must be signed in to change notification settings - Fork 105
/
linearring_test.go
137 lines (129 loc) · 3.38 KB
/
linearring_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package geom
import (
"strconv"
"testing"
"github.com/alecthomas/assert/v2"
)
// LinearRing implements interface T.
var _ T = &LinearRing{}
type expectedLinearRing struct {
layout Layout
stride int
flatCoords []float64
coords []Coord
bounds *Bounds
}
func (g *LinearRing) assertEquals(t *testing.T, e *expectedLinearRing) {
t.Helper()
assert.NoError(t, g.verify())
assert.Equal(t, e.layout, g.Layout())
assert.Equal(t, e.stride, g.Stride())
assert.Equal(t, e.flatCoords, g.FlatCoords())
assert.Zero(t, g.Ends())
assert.Zero(t, g.Endss())
assert.Equal(t, e.coords, g.Coords())
assert.Equal(t, e.bounds, g.Bounds())
assert.Equal(t, len(e.coords), g.NumCoords())
for i, c := range e.coords {
assert.Equal(t, c, g.Coord(i))
}
}
func TestLinearRing(t *testing.T) {
for i, tc := range []struct {
lr *LinearRing
expected *expectedLinearRing
}{
{
lr: NewLinearRing(XY).MustSetCoords([]Coord{{1, 2}, {3, 4}, {5, 6}}),
expected: &expectedLinearRing{
layout: XY,
stride: 2,
flatCoords: []float64{1, 2, 3, 4, 5, 6},
coords: []Coord{{1, 2}, {3, 4}, {5, 6}},
bounds: NewBounds(XY).Set(1, 2, 5, 6),
},
},
{
lr: NewLinearRing(XYZ).MustSetCoords([]Coord{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}),
expected: &expectedLinearRing{
layout: XYZ,
stride: 3,
flatCoords: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9},
coords: []Coord{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
bounds: NewBounds(XYZ).Set(1, 2, 3, 7, 8, 9),
},
},
{
lr: NewLinearRing(XYM).MustSetCoords([]Coord{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}),
expected: &expectedLinearRing{
layout: XYM,
stride: 3,
flatCoords: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9},
coords: []Coord{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
bounds: NewBounds(XYM).Set(1, 2, 3, 7, 8, 9),
},
},
{
lr: NewLinearRing(XYZM).MustSetCoords([]Coord{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}),
expected: &expectedLinearRing{
layout: XYZM,
stride: 4,
flatCoords: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
coords: []Coord{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}},
bounds: NewBounds(XYZM).Set(1, 2, 3, 4, 9, 10, 11, 12),
},
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
tc.lr.assertEquals(t, tc.expected)
assert.False(t, aliases(tc.lr.FlatCoords(), tc.lr.Clone().FlatCoords()))
})
}
}
func TestLinearRingStrideMismatch(t *testing.T) {
for i, tc := range []struct {
l Layout
cs []Coord
expected error
}{
{
l: XY,
cs: nil,
expected: nil,
},
{
l: XY,
cs: []Coord{},
expected: nil,
},
{
l: XY,
cs: []Coord{{1, 2}, {}},
expected: ErrStrideMismatch{Got: 0, Want: 2},
},
{
l: XY,
cs: []Coord{{1, 2}, {1}},
expected: ErrStrideMismatch{Got: 1, Want: 2},
},
{
l: XY,
cs: []Coord{{1, 2}, {3, 4}},
expected: nil,
},
{
l: XY,
cs: []Coord{{1, 2}, {3, 4, 5}},
expected: ErrStrideMismatch{Got: 3, Want: 2},
},
} {
t.Run(strconv.Itoa(i), func(t *testing.T) {
_, err := NewLinearRing(tc.l).SetCoords(tc.cs)
assert.Equal(t, tc.expected, err)
})
}
}
func TestLinearRingSetSRID(t *testing.T) {
assert.Equal(t, 4326, NewLinearRing(NoLayout).SetSRID(4326).SRID())
assert.Equal(t, 4326, Must(SetSRID(NewLinearRing(NoLayout), 4326)).SRID())
}