-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutil_test.go
129 lines (114 loc) · 2.06 KB
/
util_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package decimal
import "testing"
func replayOnFail(t *testing.T, f func()) pass {
t.Helper()
alreadyFailed := t.Failed()
defer func() {
t.Helper()
if r := recover(); r != nil {
t.Errorf("panic: %+v", r)
}
if !alreadyFailed && t.Failed() {
f() // Set a breakpoint here to replay the first failed test.
}
}()
f()
return !pass(alreadyFailed && t.Failed())
}
type pass bool
func (p pass) Or(f func()) {
if !p {
f()
}
}
func check(t *testing.T, ok bool) pass {
t.Helper()
if !ok {
t.Errorf("expected true")
return false
}
return true
}
func epsilon(t *testing.T, a, b float64) pass {
t.Helper()
if a/b-1 > 0.00000001 {
t.Errorf("%f and %f too dissimilar", a, b)
return false
}
return true
}
func equal[T comparable](t *testing.T, a, b T) pass {
t.Helper()
if a != b {
t.Errorf("expected %+v, got %+v", a, b)
return false
}
return true
}
func equalD64(t *testing.T, expected, actual Decimal64) pass {
t.Helper()
return equal(t, expected.String(), actual.String())
}
func isnil(t *testing.T, a any) pass {
t.Helper()
if a != nil {
t.Errorf("expected nil, got %+v", a)
return false
}
return true
}
func nopanic(t *testing.T, f func()) (b pass) {
t.Helper()
defer func() {
t.Helper()
if r := recover(); r != nil {
t.Errorf("panic: %+v", r)
b = false
}
}()
f()
return true
}
func notequal[T comparable](t *testing.T, a, b T) pass {
t.Helper()
if a == b {
t.Errorf("equal values %+v", a)
return false
}
return true
}
func notnil(t *testing.T, a any) pass {
t.Helper()
if a == nil {
t.Errorf("expected non-nil")
return false
}
return true
}
func panics(t *testing.T, f func()) (b pass) {
t.Helper()
defer func() {
t.Helper()
if r := recover(); r == nil {
t.Errorf("expected panic")
b = false
}
}()
f()
return true
}
func TestUmul64_po10(t *testing.T) {
t.Parallel()
for i, u := range tenToThe128[:39] {
if u.hi == 0 {
for j, v := range tenToThe128[:39] {
if v.hi == 0 {
e := tenToThe128[i+j]
var a uint128T
a.umul64(u.lo, v.lo)
equal(t, e, a)
}
}
}
}
}