-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice_test.go
74 lines (63 loc) · 1.04 KB
/
dice_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
package dice
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestRandString
func TestRandString(t *testing.T) {
t.Parallel()
tests := []struct {
name string
want int
}{
{
name: "TestRandString",
want: 25,
},
}
//
for _, c := range tests {
t.Run("", func(t *testing.T) {
output := RandString(c.want)
if !assert.Len(t, output, c.want) {
assert.Fail(t, "RandString(%d) failed", c.want)
}
})
}
}
// BenchmarkRandString
func BenchmarkRandString(b *testing.B) {
for i := 0; i < b.N; i++ {
RandString(25)
}
}
//
// TestRandInt
func TestRandInt(t *testing.T) {
t.Parallel()
tests := []struct {
name string
min int
max int
}{
{
name: "TestRandInt",
min: 12,
max: 34,
},
}
//
for _, c := range tests {
t.Run("", func(t *testing.T) {
output := RandInt(c.min, c.max)
// c.min<=output<=c.max
assert.True(t, (c.min <= output && output <= c.max))
})
}
}
// BenchmarkRandInt
func BenchmarkRandInt(b *testing.B) {
for i := 0; i < b.N; i++ {
RandInt(0, 99999)
}
}