-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathck_uint64.go
More file actions
180 lines (146 loc) · 4.72 KB
/
Copy pathck_uint64.go
File metadata and controls
180 lines (146 loc) · 4.72 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Golang test helper library: sztest.
Copyright (C) 2023-2025 Leslie Dancsecs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package sztest
const uint64TypeName = "uint64"
// Uint64f compares the got uint64 against want.
//
// If they differ, the failure is reported with a formatted message built from
// msgFmt and msgArgs. Returns true if got == want.
func (chk *Chk) Uint64f(
got, want uint64, msgFmt string, msgArgs ...any,
) bool {
if got == want {
return true
}
chk.t.Helper()
return chk.errChkf(got, want, uint64TypeName, msgFmt, msgArgs...)
}
// Uint64 compares the got uint64 against want.
//
// If they differ, the failure is reported via the underlying testingT and the
// optional msg values are formatted and appended to the report. Returns true
// if got == want.
func (chk *Chk) Uint64(got, want uint64, msg ...any) bool {
if got == want {
return true
}
chk.t.Helper()
return chk.errChk(got, want, uint64TypeName, msg...)
}
// Uint64Slicef compares two uint64 slices for equality.
//
// A mismatch is reported to the underlying test with a formatted message
// built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (chk *Chk) Uint64Slicef(
got, want []uint64, msgFmt string, msgArgs ...any,
) bool {
l := len(got)
equal := l == len(want)
for i := 0; equal && i < l; i++ {
equal = got[i] == want[i]
}
if equal {
return true
}
chk.t.Helper()
return errSlicef(chk,
got, want, uint64TypeName, defaultCmpFunc[uint64],
msgFmt, msgArgs...,
)
}
// Uint64Slice compares two uint64 slices for equality.
//
// A mismatch in length or element values is reported to the underlying test.
// Optional msg values are included in the failure output. Returns true if
// slices are exactly equal.
func (chk *Chk) Uint64Slice(got, want []uint64, msg ...any) bool {
l := len(got)
equal := l == len(want)
for i := 0; equal && i < l; i++ {
equal = got[i] == want[i]
}
if equal {
return true
}
chk.t.Helper()
return errSlice(
chk, got, want, uint64TypeName, defaultCmpFunc[uint64], msg...,
)
}
//
// Bounded and Unbounded Ranges.
//
// Uint64Boundedf checks that got lies within the bounded interval defined by
// minV and maxV according to the chosen option.
//
// On failure, the test is reported with a formatted message built from msgFmt
// and msgArgs. Returns true if got is within bounds.
func (chk *Chk) Uint64Boundedf(
got uint64, option BoundedOption, minV, maxV uint64,
msgFmt string, msgArgs ...any,
) bool {
inRange, want := inBoundedRange(got, option, minV, maxV)
if inRange {
return true
}
chk.t.Helper()
return chk.errGotWntf(uint64TypeName, got, want, msgFmt, msgArgs...)
}
// Uint64Bounded checks that got lies within the bounded interval defined by
// minV and maxV according to the chosen option.
//
// On failure, the test is reported with the optional msg values appended.
// Returns true if got is within bounds.
func (chk *Chk) Uint64Bounded(
got uint64, option BoundedOption, minV, maxV uint64, msg ...any,
) bool {
inRange, want := inBoundedRange(got, option, minV, maxV)
if inRange {
return true
}
chk.t.Helper()
return chk.errGotWnt(uint64TypeName, got, want, msg...)
}
// Uint64Unboundedf checks that got lies within the unbounded interval defined
// by bound and option.
//
// On failure, the test is reported with a formatted message built from msgFmt
// and msgArgs. Returns true if got is within bounds.
func (chk *Chk) Uint64Unboundedf(
got uint64, option UnboundedOption, bound uint64,
msgFmt string, msgArgs ...any,
) bool {
inRange, want := inUnboundedRange(got, option, bound)
if inRange {
return true
}
chk.t.Helper()
return chk.errGotWntf(uint64TypeName, got, want, msgFmt, msgArgs...)
}
// Uint64Unbounded checks that got lies within the unbounded interval defined
// by bound and option.
//
// On failure, the test is reported with optional msg values appended. Returns
// true if got is within bounds.
func (chk *Chk) Uint64Unbounded(
got uint64, option UnboundedOption, bound uint64, msg ...any,
) bool {
inRange, want := inUnboundedRange(got, option, bound)
if inRange {
return true
}
chk.t.Helper()
return chk.errGotWnt(uint64TypeName, got, want, msg...)
}