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
|
package orb
import "testing"
func TestMultiLineString_Bound(t *testing.T) {
// should be union of line strings
mls := MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
}
b := mls.Bound()
if !b.Equal(Bound{Min: Point{0, 0}, Max: Point{3, 3}}) {
t.Errorf("incorrect bound: %v", b)
}
}
func TestMultiLineString_Equal(t *testing.T) {
cases := []struct {
name string
mls1 MultiLineString
mls2 MultiLineString
expected bool
}{
{
name: "same multi line string",
mls1: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
mls2: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
expected: true,
},
{
name: "different number or line strings",
mls1: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
mls2: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
},
expected: false,
},
{
name: "second line is different",
mls1: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
mls2: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 2}, {2, 2}, {2, 1}, {1, 1}},
},
expected: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if v := tc.mls1.Equal(tc.mls2); v != tc.expected {
t.Errorf("mls1 != mls2: %v != %v", v, tc.expected)
}
if v := tc.mls2.Equal(tc.mls1); v != tc.expected {
t.Errorf("mls2 != mls1: %v != %v", v, tc.expected)
}
})
}
}
func TestMultiLineString_Clone(t *testing.T) {
cases := []struct {
name string
mls MultiLineString
expected MultiLineString
}{
{
name: "normal multi line string",
mls: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
expected: MultiLineString{
{{0, 0}, {0, 2}, {2, 2}, {2, 0}, {0, 0}},
{{1, 1}, {1, 3}, {3, 3}, {3, 1}, {1, 1}},
},
},
{
name: "nil should return nil",
mls: nil,
expected: nil,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
c := tc.mls.Clone()
if !c.Equal(tc.expected) {
t.Errorf("not cloned correctly: %v", c)
}
})
}
}
|