-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordered.go
75 lines (70 loc) · 1.57 KB
/
ordered.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
package assert
import (
"cmp"
"fmt"
"testing"
)
// Greater asserts that v1 > v2.
//
//nolint:thelper // It's called below.
func Greater[T cmp.Ordered](tb testing.TB, v1, v2 T, opts ...Option) bool {
ok := v1 > v2
if !ok {
tb.Helper()
Fail(
tb,
fmt.Sprintf("greater[%s]", typeName[T]()),
fmt.Sprintf("not greater than:\nv1 = %s\nv2 = %s", ValueStringer(v1), ValueStringer(v2)),
opts...,
)
}
return ok
}
// GreaterOrEqual asserts that v1 >= v2.
//
//nolint:thelper // It's called below.
func GreaterOrEqual[T cmp.Ordered](tb testing.TB, v1, v2 T, opts ...Option) bool {
ok := v1 >= v2
if !ok {
tb.Helper()
Fail(
tb,
fmt.Sprintf("greater_or_equal[%s]", typeName[T]()),
fmt.Sprintf("not greater than or equal to:\nv1 = %s\nv2 = %s", ValueStringer(v1), ValueStringer(v2)),
opts...,
)
}
return ok
}
// Less asserts that v1 < v2.
//
//nolint:thelper // It's called below.
func Less[T cmp.Ordered](tb testing.TB, v1, v2 T, opts ...Option) bool {
ok := v1 < v2
if !ok {
tb.Helper()
Fail(
tb,
fmt.Sprintf("less[%s]", typeName[T]()),
fmt.Sprintf("not less than:\nv1 = %s\nv2 = %s", ValueStringer(v1), ValueStringer(v2)),
opts...,
)
}
return ok
}
// LessOrEqual asserts that v1 <= v2.
//
//nolint:thelper // It's called below.
func LessOrEqual[T cmp.Ordered](tb testing.TB, v1, v2 T, opts ...Option) bool {
ok := v1 <= v2
if !ok {
tb.Helper()
Fail(
tb,
fmt.Sprintf("less_or_equal[%s]", typeName[T]()),
fmt.Sprintf("not less than or equal to:\nv1 = %s\nv2 = %s", ValueStringer(v1), ValueStringer(v2)),
opts...,
)
}
return ok
}