-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringrandomizer_test.go
More file actions
55 lines (46 loc) · 1.15 KB
/
Copy pathstringrandomizer_test.go
File metadata and controls
55 lines (46 loc) · 1.15 KB
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
package go_string_randomizer
import "testing"
func TestGenerateOne(t *testing.T) {
randomizer := StringRandomizer{
LettersUniverse: LOWER_UPPER_LETTERS_NUMS,
GeneratedMaxLen: 7,
NoCollisions: true,
RandSeed: 123,
}
res := randomizer.GenerateOne()
if len(res) != 7 {
t.Errorf("Generated len should be 7")
}
}
func TestGenerateBulk(t *testing.T) {
randomizer := StringRandomizer{
LettersUniverse: LOWER_UPPER_LETTERS_NUMS,
GeneratedMaxLen: 10,
NoCollisions: true,
RandSeed: 123,
}
err, res := randomizer.GenerateBulk(1000)
if len(res) != 1000 && err == nil {
t.Errorf("Generated slice len should be 1000")
}
if len(res[0]) != 10 && err == nil {
t.Errorf("Generated word len should be 10")
}
}
func TestIsCollision(t *testing.T) {
randomizer := StringRandomizer{
LettersUniverse: LOWER_UPPER_LETTERS_NUMS,
GeneratedMaxLen: 10,
NoCollisions: true,
RandSeed: 123,
}
ctrl := map[string]bool{"A": true, "B": false}
res := randomizer.isCollision(ctrl, "A")
if !res {
t.Errorf("A should return true")
}
res = randomizer.isCollision(ctrl, "B")
if !res {
t.Errorf("B should return true")
}
}