-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_test.go
59 lines (52 loc) · 1.17 KB
/
point_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 convexhull
import (
"reflect"
"testing"
)
func TestLen(t *testing.T) {
tests := []struct {
in pointSlice
want int
}{
{pointSlice{Point{0, 0}}, 1},
{pointSlice{}, 0},
}
for _, test := range tests {
got := test.in.Len()
if got != test.want {
t.Errorf("got %v, wanted %v", got, test.want)
}
}
}
func TestLess(t *testing.T) {
tests := []struct {
in pointSlice
want bool
}{
{pointSlice{Point{0, 0}, Point{1, 1}, Point{2, 2}}, true},
{pointSlice{Point{0, 0}, Point{2, 2}, Point{1, 1}}, false},
{pointSlice{Point{0, 0}, Point{1, 1}, Point{1, 2}}, true},
{pointSlice{Point{0, 0}, Point{1, 1}, Point{2, 1}}, false},
{pointSlice{Point{0, 0}, Point{1, 1}, Point{1, 1}}, false},
}
for _, test := range tests {
got := test.in.Less(1, 2)
if got != test.want {
t.Errorf("got %v, wanted %v", got, test.want)
}
}
}
func TestSwap(t *testing.T) {
tests := []struct {
in pointSlice
want pointSlice
}{
{pointSlice{Point{0, 0}, Point{1, 1}}, pointSlice{Point{1, 1}, Point{0, 0}}},
}
for _, test := range tests {
test.in.Swap(0, 1)
if !reflect.DeepEqual(test.in, test.want) {
t.Errorf("got %v, wanted %v", test.in, test.want)
}
}
}