-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigned.go
44 lines (40 loc) · 830 Bytes
/
signed.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
package assert
import (
"testing"
)
// SignedAndFloat is a constraint that requires a type to be signed or float.
type SignedAndFloat interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~float32 | ~float64
}
// Positive asserts that the value is positive.
//
//nolint:thelper // It's called below.
func Positive[T SignedAndFloat](tb testing.TB, v T, opts ...Option) bool {
ok := v > 0
if !ok {
tb.Helper()
Fail(
tb,
"positive",
"not positive:\nv = "+ValueStringer(v),
opts...,
)
}
return ok
}
// Negative asserts that the value is negative.
//
//nolint:thelper // It's called below.
func Negative[T SignedAndFloat](tb testing.TB, v T, opts ...Option) bool {
ok := v < 0
if !ok {
tb.Helper()
Fail(
tb,
"positive",
"not negative:\nv = "+ValueStringer(v),
opts...,
)
}
return ok
}