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