-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict_test.go
97 lines (81 loc) · 2.57 KB
/
dict_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
package mutator
import (
"testing"
)
func TestCreateDict(t *testing.T) {
content := "word1 word2 word2 word3 word3 word3 word4 word4 word4 word4 word5 word5 word5 word5 word5 word6 word6 word6 word6 word6 word6 word7"
totalWords := 2
kind := "letters"
dict := CreateDict(content, totalWords, kind)
if len(dict) != totalWords {
t.Errorf("Expected %d words, but got %d", totalWords, len(dict))
}
for word, count := range dict {
if len(word) < 4 {
t.Errorf("Word %s is shorter than 4 characters", word)
}
if count < 5 {
t.Errorf("Word %s has fewer than 5 repetitions", word)
}
}
}
func TestCreateDictWithNumbers(t *testing.T) {
content := "word1 1234 1234 1234 1234 1234 word2 5678 5678 5678 5678 5678"
totalWords := 2
kind := "numbers"
dict := CreateDict(content, totalWords, kind)
if len(dict) != totalWords {
t.Errorf("Expected %d words, but got %d", totalWords, len(dict))
}
for word, count := range dict {
if len(word) < 4 {
t.Errorf("Word %s is shorter than 4 characters", word)
}
if count < 5 {
t.Errorf("Word %s has fewer than 5 repetitions", word)
}
if !isValidWord(word, false, true, false) {
t.Errorf("Word %s does not match the specified kind (numbers)", word)
}
}
}
func TestCreateDictWithSpecialCharacters(t *testing.T) {
content := "hello! hello! hello! hello! hello! $world $world $world $world $world"
totalWords := 1
kind := "special"
dict := CreateDict(content, totalWords, kind)
if len(dict) != totalWords {
t.Errorf("Expected %d words, but got %d", totalWords, len(dict))
}
for word, count := range dict {
if len(word) < 4 {
t.Errorf("Word %s is shorter than 4 characters", word)
}
if count < 5 {
t.Errorf("Word %s has fewer than 5 repetitions", word)
}
if !isValidWord(word, false, false, true) {
t.Errorf("Word %s does not match the specified kind (special characters)", word)
}
}
}
func TestCreateDictWithMixedCharacters(t *testing.T) {
content := "word1 word2 word2 word3 word3 word3 word4 word4 word4 word4 word5 word5 word5 word5 word5 hello! hello! hello! hello! hello!"
totalWords := 2
kind := "letters,special"
dict := CreateDict(content, totalWords, kind)
if len(dict) != totalWords {
t.Errorf("Expected %d words, but got %d", totalWords, len(dict))
}
for word, count := range dict {
if len(word) < 4 {
t.Errorf("Word %s is shorter than 4 characters", word)
}
if count < 5 {
t.Errorf("Word %s has fewer than 5 repetitions", word)
}
if !isValidWord(word, true, false, true) {
t.Errorf("Word %s does not match the specified kind (letters and special characters)", word)
}
}
}