-
Notifications
You must be signed in to change notification settings - Fork 1
/
all_test.go
182 lines (171 loc) · 3.7 KB
/
all_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// This file provides helper routines needed by multiple tests.
package intern_test
import (
"fmt"
"math/rand"
"unicode/utf8"
)
// charSet is the list of characters from which to draw for randomly generated
// strings.
var charSet []rune
// init initializes our global state.
func init() {
const cs = "ÂBÇDÈFGHÍJKLMÑÖPQRSTÛVWXÝZ0123456789âbçdèfghíjklmñöpqrstûvwxýz @#$*-+<>一二三"
charSet = make([]rune, 0, utf8.RuneCountInString(cs))
for _, r := range cs {
charSet = append(charSet, r)
}
}
// randomString returns a random string of a given length.
func randomString(r *rand.Rand, n int) string {
rs := make([]rune, n)
nc := len(charSet)
for i := range rs {
rs[i] = charSet[r.Intn(nc)]
}
return string(rs)
}
// reverseString returns a string with its characters reversed.
func reverseString(s string) string {
rs := []rune(s)
nr := len(rs)
for i := nr / 2; i >= 0; i-- {
rs[i], rs[nr-i-1] = rs[nr-i-1], rs[i]
}
return string(rs)
}
// Dummy is used to prevent benchmarks from being treated as dead code.
var Dummy uint64
// nComp is the number of strings to compare all the others to when benchmarking.
const nComp = 1000
// generateSimilarStrings generates a list of strings that have a substantial
// prefix in common.
func generateSimilarStrings(n int) []string {
strs := make([]string, n)
for i := range strs {
strs[i] = fmt.Sprintf("String comparisons can be slow when the strings to compare have a long prefix in common. My favorite number is now %015d.", i+1)
}
return strs
}
// generateRandomStrings generates a list of long strings with random content.
func generateRandomStrings(n int) []string {
prng := rand.New(rand.NewSource(1920)) // Constant for reproducibility
strs := make([]string, n)
for i := range strs {
nc := prng.Intn(50) + 10 // Number of characters
strs[i] = randomString(prng, nc)
}
return strs
}
// ozChars is a list of characters in the Oz series of books.
var ozChars = []string{
"A-B-Sea Serpent",
"Abatha",
"Agnes",
"Army of Oogaboo",
"Aunt Em",
"Belfaygor of Bourne",
"Bell-snickle",
"Betsy Bobbin",
"Billina",
"Blinkem",
"Boq",
"Bristle",
"Button-Bright",
"Cap'n Bill",
"Cayke",
"China Princess",
"Chiss",
"Chopfyt",
"Cinnamon Bunn",
"Cowardly Lion",
"Dorothy Gale",
"Dr. Pipt",
"Ervic",
"Eureka",
"Evoldo",
"Foolish Owl",
"Frogman",
"Fyter the Tin Soldier",
"Gayelette",
"Glass Cat",
"Glinda",
"Good Witch of the North",
"Good Witch of the South",
"Graham Gems",
"Great Royal Marshmallow",
"Guardian of the Gates",
"Herby",
"Hungry Tiger",
"Jack Pumpkinhead",
"Jellia Jamb",
"Jenny Jump",
"Jester",
"Jim the Cab-Horse",
"Jinjur",
"Jinnicky the Red Jinn",
"John Dough",
"Johnny Cake",
"Johnny Dooit",
"Kabumpo",
"Kalidah",
"Kaliko",
"King Kinda Jolly",
"King Kleaver",
"King Krewl",
"King Kynd",
"King Pastoria",
"King of Bunnybury",
"King of the Fairy Beavers",
"Ku-Klip",
"Lavender Bear",
"Lonesome Duck",
"Mombi",
"Mr. Muffin",
"Mr. Yoop",
"Mrs. Yoop",
"Munchkins",
"Nimmie Amee",
"Nome King",
"Ojo the Lucky",
"Patchwork Girl",
"Phonograph",
"Polychrome",
"Pop Over",
"Prince Karver",
"Princess Langwidere",
"Princess Ozma",
"Professor Woggle-Bug",
"Queen Ann Soforth",
"Queen Coo-ee-oh",
"Queen Lurline",
"Rak",
"Robin Brown",
"Sally Lunn",
"Sawhorse",
"Scarecrow",
"Shaggy Man",
"Sir Hokus of Pokes",
"Smith",
"Soldier with the Green Whiskers",
"The Gump",
"Tik-Tok",
"Tin Woodman",
"Tinker",
"Tititi-Hoochoo",
"Toto",
"Trot",
"Tugg",
"Ugu the Shoemaker",
"Unc Nunkie",
"Uncle Henry",
"Wicked Witch of the East",
"Wicked Witch of the North",
"Wicked Witch of the South",
"Wicked Witch of the West",
"Wise Donkey",
"Wiser the Owl",
"Wizard of Oz",
"Woozy",
"Zeb Hugson",
}