-
Notifications
You must be signed in to change notification settings - Fork 15
/
generator_test.go
75 lines (69 loc) · 1.25 KB
/
generator_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
package vcgen_test
import (
"testing"
vcgen "github.com/AmirSoleimani/VoucherCodeGenerator/v2"
)
func TestGenerator(t *testing.T) {
tables := []struct {
options []vcgen.Option
want error
outputCount int
}{
{
options: nil,
want: nil,
outputCount: 1,
},
{
options: []vcgen.Option{
vcgen.SetCount(0),
},
want: vcgen.ErrInvalidCount,
},
{
options: []vcgen.Option{
vcgen.SetPattern("##"),
vcgen.SetCharset("AB"),
vcgen.SetCount(1000),
},
want: vcgen.ErrNotFeasible,
},
{
options: []vcgen.Option{
vcgen.SetPattern("##"),
vcgen.SetCharset("AB"),
vcgen.SetCount(2),
},
want: nil,
outputCount: 2,
},
{
options: []vcgen.Option{
vcgen.SetPattern("###-###-###"),
vcgen.SetCharset("123456789ABCDabfg"),
vcgen.SetCount(50),
},
want: nil,
outputCount: 50,
},
}
for _, b := range tables {
g, err := vcgen.NewWithOptions(b.options...)
if err != nil {
if err != b.want {
t.Error(err)
}
continue
}
codes, err := g.Run()
if err != nil {
if err != b.want {
t.Error(err)
}
continue
}
if len(codes) != b.outputCount {
t.Errorf("expected %d codes, got %d", b.outputCount, len(codes))
}
}
}