-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusername_test.go
57 lines (52 loc) · 927 Bytes
/
username_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
package pwg
import (
"math/big"
"testing"
rf "github.com/saihon/pwg/data"
)
func TestUsername(t *testing.T) {
p := &password{
options: new(Options),
max: new(big.Int),
}
data := []struct {
length int
capitalize bool
}{
{1, true},
{2, true},
{3, true},
{4, true},
{5, true},
{6, true},
{7, true},
{8, true},
{9, true},
{10, true},
{1, false},
{2, false},
{3, false},
{4, false},
{5, false},
{6, false},
{7, false},
{8, false},
{9, false},
{10, false},
}
for i, v := range data {
p.options.Capitalize = v.capitalize
a := p.Username(rf.Data, v.length)
if len(a) != v.length {
t.Errorf("%d:\ngot : %d, want: %d\n", i, len(a), v.length)
break
}
if v.capitalize {
if a[0] < 65 || a[0] > 90 {
t.Errorf("%d:\ngot : %c, want: %c\n", i, a[0], a[0]-32)
}
} else if a[0] < 97 || a[0] > 122 {
t.Errorf("%d:\ngot : %c\n", i, a[0])
}
}
}