-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandstrslice_test.go
82 lines (58 loc) · 1.33 KB
/
randstrslice_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
package testutil_test
import (
"testing"
"github.com/openacid/testutil"
"github.com/stretchr/testify/require"
)
func TestRandStrSlice(t *testing.T) {
ta := require.New(t)
strs := testutil.RandStrSlice(1000, 5, 10)
for _, s := range strs {
ta.GreaterOrEqual(len(s), 5)
ta.Less(len(s), 10)
for _, c := range []byte(s) {
ta.True(isIn(testutil.Runes, c))
}
}
}
func TestRandStrSlice_specifyRunes(t *testing.T) {
ta := require.New(t)
strs := testutil.RandStrSlice(10, 5, 10, []rune("12"))
for _, s := range strs {
ta.GreaterOrEqual(len(s), 5)
ta.Less(len(s), 10)
for _, c := range []byte(s) {
ta.True(c == byte('1') || c == byte('2'))
}
}
}
func TestRandBytesSlice(t *testing.T) {
ta := require.New(t)
bss := testutil.RandBytesSlice(1000, 5, 10)
for _, s := range bss {
ta.GreaterOrEqual(len(s), 5)
ta.Less(len(s), 10)
for _, c := range s {
ta.True(isIn(testutil.Runes, c))
}
}
}
func TestRandBytesSlice_specifyRunes(t *testing.T) {
ta := require.New(t)
bss := testutil.RandBytesSlice(10, 5, 10, []rune("12"))
for _, s := range bss {
ta.GreaterOrEqual(len(s), 5)
ta.Less(len(s), 10)
for _, c := range s {
ta.True(c == '1' || c == '2')
}
}
}
func isIn(collection []rune, c byte) bool {
for _, r := range collection {
if c == byte(r) {
return true
}
}
return false
}