-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallonsay_test.go
226 lines (194 loc) · 5.23 KB
/
allonsay_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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package main
import (
"os"
"testing"
)
// -----------------------------------------------------------------------------
func TestMainFunction(t *testing.T) {
var strings = []struct {
description string
arguments []string
}{
{"No argument", []string{"allonsay"}},
{"Empty argument", []string{"allonsay", ""}},
{"Empty-ish argument", []string{"allonsay", " "}},
{"Two arguments", []string{"allonsay", " ", "Allons-y!"}},
}
for _, tt := range strings {
t.Run(string(tt.description), func(t *testing.T) {
// Arrange
os.Args = tt.arguments
// Act & Assert
main()
// Just don’t break for now
})
}
}
// -----------------------------------------------------------------------------
func TestGetVoice(t *testing.T) {
var strings = []struct {
input string
voice Voice
}{
{"University of Hong Kong", EnglishVoice},
{"Nederlandse Spoorwegen", DutchVoice},
{"香港大學", CantoneseVoice},
}
for _, tt := range strings {
t.Run(string(tt.input), func(t *testing.T) {
// Arrange
var expected = tt.voice
// Act
var actual = getVoice(tt.input, tt.input)
// Assert
if actual != expected {
t.Error(tt.input)
}
})
}
}
// -----------------------------------------------------------------------------
func TestGuessLanguage(t *testing.T) {
var strings = []struct {
label string
input string
language Language
}{
{
"English 1",
`
Harvard University is devoted to excellence in teaching, learning,
and research, and to developing leaders in many disciplines who make
a difference globally. The University, which is based in Cambridge
and Boston, Massachusetts, has an enrollment of over 20,000 degree
candidates
`,
EnglishLanguage,
},
{
"English 2",
`
Royal Schiphol Group brings the world within reach. We connect the
Netherlands with the rest of the world, thus creating value for the
economy and society.
`,
EnglishLanguage,
},
{
"Dutch 1",
`
De Universiteit van Amsterdam is een van de meest vooraanstaande
onderzoeksuniversiteiten in Europa, een moderne universiteit met een
lange en rijke geschiedenis
`,
DutchLanguage,
},
{
"Dutch 2",
`
TNO verbindt mensen en kennis om innovaties te creëren die de
concurrentiekracht van bedrijven en het welzijn van de samenleving
duurzaam versterken.
`,
DutchLanguage,
},
{
"Dutch 3 (names and English loanwords)",
`
InTraffic is in 2003 opgericht als ‘joint venture’ van het
IT-bedrijf ICT Automatisering en ingenieursbureau Movares. De
filosofie achter InTraffic is dat alleen een gespecialiseerd bedrijf
kan beschikken over een hoge mate van domeinkennis in combinatie met
IT-expertise.
`,
DutchLanguage,
},
}
for _, tt := range strings {
t.Run(string(tt.label), func(t *testing.T) {
// Arrange
var expected = tt.language
// Act
var actual = guessLanguage(tt.input)
// Assert
if actual != expected {
t.Error("Guessed wrong language")
}
})
}
}
// -----------------------------------------------------------------------------
func TestCalculateLetterFrequencies(t *testing.T) {
// Arrange
var input = "Kowloon Tong (九龍塘)"
// Act
var actual = calculateLetterFrequencies(input)
// Assert
if actual['k'] != float64(1*100)/float64(11) ||
actual['n'] != float64(2*100)/float64(11) ||
actual['o'] != float64(4*100)/float64(11) ||
actual['t'] != float64(1*100)/float64(11) {
t.Error("Letter frequency mismatch")
}
}
// -----------------------------------------------------------------------------
func TestConvertStringToBilingualSentence(t *testing.T) {
// Arrange
var input = "You can change trains at 美孚 station"
var expected = BilingualSentence{
"You can change trains at ",
"美孚",
" station",
}
// Act
var actual = convertStringToBilingualSentence(input)
// Assert
if len(actual) != len(expected) {
t.Error("Resulting BilingualSentence does not have expected length")
}
for i := 0; i < 3; i++ {
if actual[i] != expected[i] {
t.Error("Result does not exactly match expected BilingualSentence")
}
}
}
// -----------------------------------------------------------------------------
func TestOnlyAlphabeticCharacters(t *testing.T) {
// Arrange
var input = "Kennedy Town (堅尼地城) – Chai Wan (柴灣)"
var expected = "KennedyTownChaiWan"
// Act
var actual = string(onlyAlphabeticCharacters(input))
// Assert
if actual != expected {
t.Error("Output still contains non-alphabetic characters")
}
}
// -----------------------------------------------------------------------------
func TestIsCharacterChinese(t *testing.T) {
var possiblyChineseCharacters = []struct {
description string
char rune
isCjk bool
}{
{"Uppercase A", 'A', false},
{"Lowercase A", 'a', false},
{"Circled small letter A", 'ⓐ', false},
{"Mathematical double-struck A", '𝔸', false},
{"Hebrew alef", 'א', false},
{"Traditional xué", '學', true},
{"Simplified xué", '学', true},
}
for _, tt := range possiblyChineseCharacters {
t.Run(string(tt.char), func(t *testing.T) {
// Arrange
var expected = tt.isCjk
// Act
var actual = isCharacterChinese(tt.char)
// Assert
if actual != expected {
t.Error(tt.description)
}
})
}
}