forked from go-spatial/geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle_test.go
49 lines (42 loc) · 993 Bytes
/
triangle_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 geom_test
import (
"strconv"
"testing"
"github.com/go-spatial/geom"
)
func TestNewTriangleForExtent(t *testing.T) {
type tcase struct {
Extent *geom.Extent
Buff float64
Expected geom.Triangle
Err error
}
fn := func(tc tcase) func(*testing.T) {
return func(t *testing.T) {
tri, err := geom.NewTriangleForExtent(tc.Extent, tc.Buff)
if tc.Err != nil {
if err != tc.Err {
t.Errorf("error, expected %v, got %v ", tc.Err, err)
}
return
}
if err != nil {
t.Errorf("error, expected nil, got %v ", err)
return
}
if tri[0] != tc.Expected[0] || tri[1] != tc.Expected[1] || tri[2] != tc.Expected[2] {
t.Errorf("triangle, expected %v, got %v ", tc.Expected, tri)
}
}
}
tests := [...]tcase{
{
Extent: geom.NewExtent([2]float64{0, 0}),
Buff: 10,
Expected: geom.Triangle{{-10, -10}, {0, 10}, {10, -10}},
},
}
for i := range tests {
t.Run(strconv.FormatInt(int64(i), 10), fn(tests[i]))
}
}