1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.codec.language;
19
20 import org.apache.commons.codec.EncoderException;
21 import org.apache.commons.codec.StringEncoderAbstractTest;
22 import org.junit.Assert;
23 import org.junit.Test;
24
25
26
27
28
29
30
31 public class NysiisTest extends StringEncoderAbstractTest<Nysiis> {
32
33 private final Nysiis fullNysiis = new Nysiis(false);
34
35
36
37
38
39
40
41
42
43
44 private void assertEncodings(final String[]... testValues) throws EncoderException {
45 for (final String[] arr : testValues) {
46 Assert.assertEquals("Problem with " + arr[0], arr[1], this.fullNysiis.encode(arr[0]));
47 }
48 }
49
50 @Override
51 protected Nysiis createStringEncoder() {
52 return new Nysiis();
53 }
54
55 private void encodeAll(final String[] strings, final String expectedEncoding) {
56 for (final String string : strings) {
57 Assert.assertEquals("Problem with " + string, expectedEncoding, getStringEncoder().encode(string));
58 }
59 }
60
61 @Test
62 public void testBran() {
63 encodeAll(new String[] { "Brian", "Brown", "Brun" }, "BRAN");
64 }
65
66 @Test
67 public void testCap() {
68 this.encodeAll(new String[] { "Capp", "Cope", "Copp", "Kipp" }, "CAP");
69 }
70
71 @Test
72 public void testDad() {
73
74
75 this.encodeAll(new String[] { "Dent" }, "DAD");
76 }
77
78 @Test
79 public void testDan() {
80 this.encodeAll(new String[] { "Dane", "Dean", "Dionne" }, "DAN");
81 }
82
83
84
85
86
87
88
89 @Test
90 public void testDropBy() throws EncoderException {
91
92
93
94
95 this.assertEncodings(
96
97 new String[] { "MACINTOSH", "MCANT" },
98
99
100 new String[] { "KNUTH", "NAT" },
101
102
103
104
105
106 new String[] { "KOEHN", "CAN" },
107
108 new String[] { "PHILLIPSON", "FALAPSAN" },
109
110 new String[] { "PFEISTER", "FASTAR" },
111
112 new String[] { "SCHOENHOEFT", "SANAFT" },
113
114 new String[] { "MCKEE", "MCY" },
115 new String[] { "MACKIE", "MCY" },
116 new String[] { "HEITSCHMIDT", "HATSNAD" },
117 new String[] { "BART", "BAD" },
118 new String[] { "HURD", "HAD" },
119 new String[] { "HUNT", "HAD" },
120 new String[] { "WESTERLUND", "WASTARLAD" },
121
122
123 new String[] { "CASSTEVENS", "CASTAFAN" },
124 new String[] { "VASQUEZ", "VASG" },
125 new String[] { "FRAZIER", "FRASAR" },
126 new String[] { "BOWMAN", "BANAN" },
127 new String[] { "MCKNIGHT", "MCNAGT" },
128 new String[] { "RICKERT", "RACAD" },
129
130
131
132 new String[] { "DEUTSCH", "DAT" },
133 new String[] { "WESTPHAL", "WASTFAL" },
134
135
136 new String[] { "SHRIVER", "SRAVAR" },
137
138 new String[] { "KUHL", "CAL" },
139 new String[] { "RAWSON", "RASAN" },
140
141 new String[] { "JILES", "JAL" },
142
143 new String[] { "CARRAWAY", "CARY" },
144 new String[] { "YAMADA", "YANAD" });
145 }
146
147 @Test
148 public void testFal() {
149 this.encodeAll(new String[] { "Phil" }, "FAL");
150 }
151
152
153
154
155
156
157 @Test
158 public void testOthers() throws EncoderException {
159 this.assertEncodings(
160 new String[] { "O'Daniel", "ODANAL" },
161 new String[] { "O'Donnel", "ODANAL" },
162 new String[] { "Cory", "CARY" },
163 new String[] { "Corey", "CARY" },
164 new String[] { "Kory", "CARY" },
165
166 new String[] { "FUZZY", "FASY" });
167 }
168
169
170
171
172
173
174 @Test
175 public void testRule1() throws EncoderException {
176 this.assertEncodings(
177 new String[] { "MACX", "MCX" },
178 new String[] { "KNX", "NX" },
179 new String[] { "KX", "CX" },
180 new String[] { "PHX", "FX" },
181 new String[] { "PFX", "FX" },
182 new String[] { "SCHX", "SX" });
183 }
184
185
186
187
188
189
190 @Test
191 public void testRule2() throws EncoderException {
192 this.assertEncodings(
193 new String[] { "XEE", "XY" },
194 new String[] { "XIE", "XY" },
195 new String[] { "XDT", "XD" },
196 new String[] { "XRT", "XD" },
197 new String[] { "XRD", "XD" },
198 new String[] { "XNT", "XD" },
199 new String[] { "XND", "XD" });
200 }
201
202
203
204
205
206
207 @Test
208 public void testRule4Dot1() throws EncoderException {
209 this.assertEncodings(
210 new String[] { "XEV", "XAF" },
211 new String[] { "XAX", "XAX" },
212 new String[] { "XEX", "XAX" },
213 new String[] { "XIX", "XAX" },
214 new String[] { "XOX", "XAX" },
215 new String[] { "XUX", "XAX" });
216 }
217
218
219
220
221
222
223 @Test
224 public void testRule4Dot2() throws EncoderException {
225 this.assertEncodings(
226 new String[] { "XQ", "XG" },
227 new String[] { "XZ", "X" },
228 new String[] { "XM", "XN" });
229 }
230
231
232
233
234
235
236 @Test
237 public void testRule5() throws EncoderException {
238 this.assertEncodings(
239 new String[] { "XS", "X" },
240 new String[] { "XSS", "X" });
241 }
242
243
244
245
246
247
248 @Test
249 public void testRule6() throws EncoderException {
250 this.assertEncodings(
251 new String[] { "XAY", "XY" },
252 new String[] { "XAYS", "XY" });
253 }
254
255
256
257
258
259
260 @Test
261 public void testRule7() throws EncoderException {
262 this.assertEncodings(
263 new String[] { "XA", "X" },
264 new String[] { "XAS", "X" });
265 }
266 @Test
267 public void testSnad() {
268
269
270 this.encodeAll(new String[] { "Schmidt" }, "SNAD");
271 }
272
273 @Test
274 public void testSnat() {
275 this.encodeAll(new String[] { "Smith", "Schmit" }, "SNAT");
276 }
277
278 @Test
279 public void testSpecialBranches() {
280 this.encodeAll(new String[] { "Kobwick" }, "CABWAC");
281 this.encodeAll(new String[] { "Kocher" }, "CACAR");
282 this.encodeAll(new String[] { "Fesca" }, "FASC");
283 this.encodeAll(new String[] { "Shom" }, "SAN");
284 this.encodeAll(new String[] { "Ohlo" }, "OL");
285 this.encodeAll(new String[] { "Uhu" }, "UH");
286 this.encodeAll(new String[] { "Um" }, "UN");
287 }
288
289 @Test
290 public void testTranan() {
291 this.encodeAll(new String[] { "Trueman", "Truman" }, "TRANAN");
292 }
293
294 @Test
295 public void testTrueVariant() {
296 final Nysiis encoder = new Nysiis(true);
297
298 final String encoded = encoder.encode("WESTERLUND");
299 Assert.assertTrue(encoded.length() <= 6);
300 Assert.assertEquals("WASTAR", encoded);
301 }
302
303 }