-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_test.go
115 lines (101 loc) · 1.95 KB
/
generate_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2022 Jonas Kwiedor. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package goten_test
import (
"github.com/gowizzard/goten"
"reflect"
"testing"
)
// TestGenerate is to test the generate function with table
// driven tests. We simulate the generation and check the result.
func TestGenerate(t *testing.T) {
tests := []struct {
length int
options goten.Options
}{
{
length: 50,
options: goten.Options{
Uppercase: false,
Numbers: false,
Symbols: false,
},
},
{
length: 256,
options: goten.Options{
Uppercase: true,
Numbers: false,
Symbols: false,
},
},
{
length: 10,
options: goten.Options{
Uppercase: false,
Numbers: true,
Symbols: false,
},
},
{
length: 25,
options: goten.Options{
Uppercase: false,
Numbers: false,
Symbols: true,
},
},
{
length: 124,
options: goten.Options{
Uppercase: true,
Numbers: true,
Symbols: false,
},
},
{
length: 16,
options: goten.Options{
Uppercase: true,
Numbers: false,
Symbols: true,
},
},
{
length: 36,
options: goten.Options{
Uppercase: false,
Numbers: true,
Symbols: true,
},
},
{
length: 512,
options: goten.Options{
Uppercase: true,
Numbers: true,
Symbols: true,
},
},
}
for _, value := range tests {
token := goten.Generate(value.length, &value.options)
length := reflect.ValueOf(token).Len()
if !reflect.DeepEqual(value.length, length) {
t.Fatalf("expected: %d, got %d", value.length, length)
}
}
}
// BenchmarkGenerate is to test the Generate function with benchmark tests.
func BenchmarkGenerate(b *testing.B) {
length, options := 64, goten.Options{
Uppercase: true,
Numbers: true,
Symbols: true,
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
goten.Generate(length, &options)
}
}