forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_string_test.go
49 lines (42 loc) · 897 Bytes
/
line_string_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 orb
import (
"testing"
)
func TestLineStringReverse(t *testing.T) {
t.Run("1 point line", func(t *testing.T) {
ls := LineString{{1, 2}}
rs := ls.Clone()
rs.Reverse()
if !rs.Equal(ls) {
t.Errorf("1 point lines should be equal if reversed")
}
})
cases := []struct {
name string
input LineString
output LineString
}{
{
name: "2 point line",
input: LineString{{1, 2}, {3, 4}},
output: LineString{{3, 4}, {1, 2}},
},
{
name: "3 point line",
input: LineString{{1, 2}, {3, 4}, {5, 6}},
output: LineString{{5, 6}, {3, 4}, {1, 2}},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
reversed := tc.input
reversed.Reverse()
if !reversed.Equal(tc.output) {
t.Errorf("line should be reversed: %v", reversed)
}
if !tc.input.Equal(reversed) {
t.Errorf("should reverse inplace")
}
})
}
}