-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmp_test.go
57 lines (50 loc) · 1.17 KB
/
cmp_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
package functools
import "testing"
var cmpCases = []struct {
a interface{}
b interface{}
want int8
e bool
}{
{nil, nil, 0, false},
{nil, 0, -1, false},
{0, nil, 1, false},
{0, 0, 0, false},
{1, 2, -1, false},
{2, 1, 1, false},
{3, 1, 1, false},
{13.01, 13.02, -1, false},
{0.0001, 0.0001, 0, false},
{"abc", "cd", 1, false},
{"abc", "cde", 0, false},
{[]int{1, 2, 3}, []int{4, 5, 6}, 0, false},
{[]float64{1.1, 2.2}, []float64{1.1, 2.2, 3.3}, -1, false},
{false, false, 0, false},
{true, false, 1, false},
{false, true, -1, false},
{1, 2.4, -1, true},
{float64(1), 2.4, -1, false},
{"a", 'a', 0, true},
{map[int]int{1: 1, 2: 2, 3: 3}, map[int]int{4: 4}, 1, false},
}
func TestCmpSafe(t *testing.T) {
for _, c := range cmpCases {
got, err := CmpSafe(c.a, c.b)
if err != nil && !c.e {
t.Errorf("CmpSafe(%v, %v) raised %v", c.a, c.b, err)
}
if err == nil && got != c.want {
t.Errorf("CmpSafe(%v, %v) == %d want %d", c.a, c.b, got, c.want)
}
}
}
func TestCmp(t *testing.T) {
for _, c := range cmpCases {
if !c.e {
got := Cmp(c.a, c.b)
if got != c.want {
t.Errorf("Cmp(%v, %v) == %d want %d", c.a, c.b, got, c.want)
}
}
}
}