-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_test.go
85 lines (79 loc) · 1.76 KB
/
debug_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// +build debug
package assert
import (
"fmt"
"testing"
"github.com/eloff/assert"
)
func TestCompares(t *testing.T) {
type compares func(x, y interface{})
tests := []struct {
op string
cmp compares
// Truth table for
// cmp(0, 0)
// cmp(0, 1)
// cmp(0, 2)
// cmp(1, 0)
// cmp(1, 1)
// cmp(1, 2)
// cmp(2, 0)
// cmp(2, 1)
// cmp(2, 2)
expected [9]bool
invertedMessage bool
}{
{
op: ">",
cmp: Greater,
expected: [9]bool{false, false, false, true, false, false, true, true, false},
},
{
op: "<",
cmp: Lesser,
expected: [9]bool{false, true, true, false, false, true, false, false, false},
},
{
op: "==",
cmp: func(x, y interface{}) { Equal(x, y) },
expected: [9]bool{true, false, false, false, true, false, false, false, true},
invertedMessage: true,
},
{
op: "!=",
cmp: func(x, y interface{}) { NotEqual(x, y) },
expected: [9]bool{false, true, true, true, false, true, true, true, false},
invertedMessage: true,
},
{
op: ">=",
cmp: GreaterOrEqual,
expected: [9]bool{true, false, false, true, true, false, true, true, true},
},
{
op: "<=",
cmp: LesserOrEqual,
expected: [9]bool{true, true, true, false, true, true, false, false, true},
},
}
for _, test := range tests {
a := assert.New(t, test.op)
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
f := func() { test.cmp(i, j) }
var msg string
if test.invertedMessage {
msg = fmt.Sprintf("%d %s %d", j, test.op, i)
} else {
msg = fmt.Sprintf("%d %s %d", i, test.op, j)
}
t.Log(msg)
if !test.expected[i*3+j] {
a.Panics(f, msg)
} else {
f()
}
}
}
}
}