forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_test.go
102 lines (98 loc) · 2.81 KB
/
line_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
package basic_test
import (
"testing"
"github.com/gdey/tbltest"
"github.com/go-spatial/tegola/basic"
)
func TestLineContainsPoint(t *testing.T) {
type testcase struct {
desc string
line basic.Line
point basic.Point
expected bool
}
tests := tbltest.Cases(
testcase{
desc: "Simple circle with point(1,1)",
line: basic.NewLine(0, 0, 5, 0, 5, 5, 0, 5),
point: basic.Point{1, 1},
expected: true,
},
testcase{
desc: "Simple circle with point(2,2)",
line: basic.NewLine(0, 0, 5, 0, 5, 5, 0, 5),
point: basic.Point{2, 2},
expected: true,
},
testcase{
desc: "Simple circle with point(5,5) on border",
line: basic.NewLine(0, 0, 5, 0, 5, 5, 0, 5),
point: basic.Point{5, 5},
expected: false,
},
testcase{
desc: "Simple circle with point(6,6) outside.",
line: basic.NewLine(0, 0, 5, 0, 5, 5, 0, 5),
point: basic.Point{6, 6},
expected: false,
},
)
tests.Run(func(idx int, test testcase) {
got := test.line.Contains(test.point)
if got != test.expected {
t.Errorf("Tests %v (%v): Expected %v got %v", test.desc, idx, test.expected, got)
}
})
}
func TestLineContainsLine(t *testing.T) {
type testcase struct {
desc string
line basic.Line
cline basic.Line
expected bool
}
tests := tbltest.Cases(
testcase{
desc: "small sqr(1 1, 3 3) fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(1, 1, 1, 3, 3, 3, 3, 1),
expected: true,
},
testcase{
desc: "small sqr(0 0, 3 3) not fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(0, 0, 0, 3, 3, 3, 3, 0),
expected: false,
},
testcase{
desc: "small sqr(-1 -1, 3 3) not fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(-1, -1, -1, 3, 3, 3, 3, -1),
expected: false,
},
testcase{
desc: "small sqr(-3 -3, -1 -1) not fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(-3, -3, -3, -1, -1, -1, -1, -3),
expected: false,
},
testcase{
desc: "small sqr(-3 -3, 0 0) not fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(-3, -3, -3, 0, 0, 0, 0, -3),
expected: false,
},
testcase{
desc: "small sqr(-3 -3, 3 3) not fully contained in sqr(0 0, 5 8).",
line: basic.NewLine(0, 0, 5, 0, 5, 8, 0, 8),
cline: basic.NewLine(-3, -3, -3, 3, 3, 3, 3, -3),
expected: false,
},
)
tests.Run(func(idx int, test testcase) {
got := test.line.ContainsLine(test.cline)
if got != test.expected {
t.Errorf("Tests %v (%v): expected: %v got %v", test.desc, idx, test.expected, got)
}
})
}