forked from lilith44/gox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_rand_test.go
54 lines (48 loc) · 1002 Bytes
/
string_rand_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
package gox
import (
`testing`
)
func TestRandDigit(t *testing.T) {
tests := []struct {
input int
expected int
}{
{input: 1, expected: 1},
{input: 2, expected: 2},
{input: 3, expected: 3},
{input: 4, expected: 4},
{input: 5, expected: 5},
{input: 6, expected: 6},
}
for _, tc := range tests {
got := RandDigit(tc.input)
if len(got) != tc.expected {
t.Fatalf("期望:%v,实际:%v", tc.expected, got)
}
}
}
func TestRandString(t *testing.T) {
tests := []struct {
input int
expected int
}{
{input: 1, expected: 1},
{input: 2, expected: 2},
{input: 3, expected: 3},
{input: 4, expected: 4},
{input: 5, expected: 5},
{input: 6, expected: 6},
}
for _, tc := range tests {
got := RandString(tc.input)
if len(got) != tc.expected {
t.Fatalf("期望:%v,实际:%v", tc.expected, got)
}
}
}
func TestRandVerificationCode(t *testing.T) {
got := RandCode()
if 6 != len(got) {
t.Fatalf("期望:%v,实际:%v", 6, got)
}
}