-
Notifications
You must be signed in to change notification settings - Fork 1
/
limitto_test.go
59 lines (56 loc) · 2.42 KB
/
limitto_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
package changes
import "testing"
func TestLimitTo_Contains(t *testing.T) {
for _, tt := range []struct {
l *LimitTo
long float64
lat float64
want bool
}{
{l: nil, long: 0, lat: 0, want: true},
{l: nil, long: 99999, lat: 99999, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: 0, lat: -0.01, want: false},
{l: &LimitTo{-20, 0, 10, 30}, long: 0, lat: 0, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: 0, lat: 30.01, want: false},
{l: &LimitTo{-20, 0, 10, 30}, long: 0, lat: 30, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: -20, lat: 10, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: -20.01, lat: 10, want: false},
{l: &LimitTo{-20, 0, 10, 30}, long: 10.01, lat: 10, want: false},
{l: &LimitTo{-20, 0, 10, 30}, long: 10, lat: 10, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: -20, lat: 0, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: -20, lat: 30, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: 10, lat: 0, want: true},
{l: &LimitTo{-20, 0, 10, 30}, long: 10, lat: 30, want: true},
} {
t.Run("", func(t *testing.T) {
if got := tt.l.Contains(tt.long, tt.lat); tt.want != got {
t.Errorf("check for contains of %f %f in %v was %v, want %v", tt.long, tt.lat, tt.l, got, tt.want)
}
})
}
}
func TestLimitTo_Intersects(t *testing.T) {
for _, tt := range []struct {
l *LimitTo
check [4]float64
want bool
}{
{l: nil, check: [4]float64{-100, -100, 100, 100}, want: true},
{l: nil, check: [4]float64{0, 0, 0, 0}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{0, 0, 0, 0}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-100, -100, 100, 100}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-10, 10, 5, 20}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, 10, -20.01, 20}, want: false},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, 10, -20.0, 20}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, 30.01, -10.0, 40}, want: false},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, 30, -10.0, 40}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, -30, -10.0, 0}, want: true},
{l: &LimitTo{-20, 0, 10, 30}, check: [4]float64{-30, -30, -10.0, -0.01}, want: false},
} {
t.Run("", func(t *testing.T) {
if got := tt.l.Intersects(tt.check); tt.want != got {
t.Errorf("check for intersection of %v and %v was %v, want %v", tt.check, tt.l, got, tt.want)
}
})
}
}