-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmax_test.go
68 lines (65 loc) · 1.18 KB
/
max_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
package g
import "testing"
func TestMaxInt(t *testing.T) {
var r int
var err error
_, err = MaxIntInSlice([]int{})
if err == nil {
t.Fatal("should be error")
}
_, err = MaxIntInSlice(nil)
if err == nil {
t.Fatal("should be error")
}
r, err = MaxIntInSlice([]int{1, 2, 3})
if err != nil {
t.Fatal(err)
}
if r != 3 {
t.Fatalf("bad result: %v", r)
}
r, err = MaxIntInSlice([]int{3, 2, 1})
if err != nil {
t.Fatal(err)
}
if r != 3 {
t.Fatalf("bad result: %v", r)
}
r, err = MaxIntInSlice([]int{1, -2, 3})
if err != nil {
t.Fatal(err)
}
if r != 3 {
t.Fatalf("bad result: %v", r)
}
r, err = MaxIntInSlice([]int{-1, -2, -3})
if err != nil {
t.Fatal(err)
}
if r != -1 {
t.Fatalf("bad result: %v", r)
}
}
func TestMaxIntWithDefault(t *testing.T) {
var r int
r = MaxIntWithDefault(3, []int{}...)
if r != 3 {
t.Fatalf("bad result: %v", r)
}
r = MaxIntWithDefault(3)
if r != 3 {
t.Fatalf("bad result: %v", r)
}
r = MaxIntWithDefault(3, 1, 2)
if r != 2 {
t.Fatalf("bad result: %v", r)
}
r = MaxIntWithDefault(3, 4, 5)
if r != 5 {
t.Fatalf("bad result: %v", r)
}
r = MaxIntWithDefault(3, -4, -5)
if r != -4 {
t.Fatalf("bad result: %v", r)
}
}