-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounds_test.go
66 lines (61 loc) · 2.01 KB
/
bounds_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
package flatsphere
import (
"testing"
)
func TestBoundsProperties(t *testing.T) {
testCases := []struct {
name string
bounds Bounds
width float64
height float64
xmax float64
ymax float64
}{
{"Circle", NewCircleBounds(1.0), 2.0, 2.0, 1.0, 1.0},
{"Ellipse", NewEllipseBounds(2.0, 3.0), 4.0, 6.0, 2.0, 3.0},
{"Rectangle", NewRectangleBounds(5.0, 1.0), 5.0, 1.0, 2.5, 0.5},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if !withinTolerance(tc.bounds.XMax, tc.xmax, 0.000001) {
t.Errorf("expected xmax %f, got %f", tc.xmax, tc.bounds.XMax)
}
if !withinTolerance(tc.bounds.YMax, tc.ymax, 0.000001) {
t.Errorf("expected ymax %f, got %f", tc.ymax, tc.bounds.YMax)
}
if !withinTolerance(tc.bounds.Width(), tc.width, 0.000001) {
t.Errorf("expected width %f, got %f", tc.width, tc.bounds.Width())
}
if !withinTolerance(tc.bounds.Height(), tc.height, 0.000001) {
t.Errorf("expected height %f, got %f", tc.height, tc.bounds.Height())
}
})
}
}
func TestWithin(t *testing.T) {
testCases := []struct {
name string
bounds Bounds
xloc float64
yloc float64
within bool
}{
{"Origin", NewRectangleBounds(2.0, 2.0), 0.0, 0.0, true},
{"OffsetInside", NewRectangleBounds(2.0, 2.0), 0.5, 0.5, true},
{"NegativeOffsetInside", NewRectangleBounds(2.0, 2.0), -0.5, -0.5, true},
{"Edge", NewRectangleBounds(2.0, 2.0), 1.0, 0.0, true},
{"Corner", NewRectangleBounds(2.0, 2.0), 1.0, 1.0, true},
{"NegativeCorner", NewRectangleBounds(2.0, 2.0), -1.0, -1.0, true},
{"Outside", NewRectangleBounds(2.0, 2.0), 3.0, 3.0, false},
{"NegativeOutside", NewRectangleBounds(2.0, 2.0), -3.0, -3.0, false},
{"XAxisOutside", NewRectangleBounds(2.0, 2.0), 3.0, 0.0, false},
{"YAxisOutside", NewRectangleBounds(2.0, 2.0), 0.0, 3.0, false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.bounds.Within(tc.xloc, tc.yloc) != tc.within {
t.Errorf("expected %v, got %v", tc.within, tc.bounds.Within(tc.xloc, tc.yloc))
}
})
}
}