This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextrand_test.go
85 lines (71 loc) · 1.57 KB
/
extrand_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
package extrand
import (
"math"
"testing"
"github.com/stretchr/testify/require"
)
func TestInt63(t *testing.T) {
got := Int63()
require.LessOrEqual(t, got, int64(math.MaxInt64))
require.LessOrEqual(t, int64(0), got)
}
func TestInt63n(t *testing.T) {
require.Panics(t, func() {
Int63n(-1)
})
got := Int63n(math.MaxInt64 / 2)
require.LessOrEqual(t, got, int64(math.MaxInt64/2))
require.LessOrEqual(t, int64(0), got)
}
func TestInt31(t *testing.T) {
got := Int31()
require.LessOrEqual(t, got, int32(math.MaxInt32))
require.LessOrEqual(t, int32(0), got)
}
func TestInt31n(t *testing.T) {
require.Panics(t, func() {
Int31n(-1)
})
got := Int31n(math.MaxInt32 / 2)
require.LessOrEqual(t, got, int32(math.MaxInt32/2))
require.LessOrEqual(t, int32(0), got)
}
func TestInt(t *testing.T) {
got := Int()
require.LessOrEqual(t, got, math.MaxInt64)
require.LessOrEqual(t, 0, got)
}
func TestIntn(t *testing.T) {
require.Panics(t, func() {
Intn(-1)
})
got := Intn(math.MaxInt64 / 2)
require.LessOrEqual(t, got, math.MaxInt64/2)
require.LessOrEqual(t, 0, got)
}
func TestFloat64(t *testing.T) {
got := Float64()
require.Less(t, got, 1.0)
require.LessOrEqual(t, 0.0, got)
}
func TestFloat32(t *testing.T) {
got := Float32()
require.Less(t, got, float32(1.0))
require.LessOrEqual(t, float32(0.0), got)
}
func TestPerm(t *testing.T) {
got := Perm(100)
for _, v := range got {
require.Less(t, v, 100)
}
}
func BenchmarkUint64(b *testing.B) {
for i := 0; i < b.N; i++ {
Uint64()
}
}
func BenchmarkUint32(b *testing.B) {
for i := 0; i < b.N; i++ {
Uint32()
}
}