@@ -35,6 +35,21 @@ public class NysiisTest extends StringEncoderAbstractTest {
3535
3636 private final Nysiis fullNysiis = new Nysiis (false );
3737
38+ /**
39+ * Takes an array of String pairs where each pair's first element is the input and the second element the expected
40+ * encoding.
41+ *
42+ * @param testValues
43+ * an array of String pairs where each pair's first element is the input and the second element the
44+ * expected encoding.
45+ * @throws EncoderException
46+ */
47+ private void assertEncodings (String []... testValues ) throws EncoderException {
48+ for (String [] arr : testValues ) {
49+ Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
50+ }
51+ }
52+
3853 @ Override
3954 protected StringEncoder createStringEncoder () {
4055 return new Nysiis ();
@@ -217,19 +232,14 @@ public void testFal() throws EncoderException {
217232 */
218233 @ Test
219234 public void testOthers () throws EncoderException {
220- List <String []> testValues =
221- Arrays .asList (
222- new String [] { "O'Daniel" , "ODANAL" },
223- new String [] { "O'Donnel" , "ODANAL" },
224- new String [] { "Cory" , "CARY" },
225- new String [] { "Corey" , "CARY" },
226- new String [] { "Kory" , "CARY" },
227- //
228- new String [] { "FUZZY" , "FASY" });
229-
230- for (String [] arr : testValues ) {
231- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
232- }
235+ this .assertEncodings (
236+ new String [] { "O'Daniel" , "ODANAL" },
237+ new String [] { "O'Donnel" , "ODANAL" },
238+ new String [] { "Cory" , "CARY" },
239+ new String [] { "Corey" , "CARY" },
240+ new String [] { "Kory" , "CARY" },
241+ //
242+ new String [] { "FUZZY" , "FASY" });
233243 }
234244
235245 /**
@@ -239,17 +249,13 @@ public void testOthers() throws EncoderException {
239249 */
240250 @ Test
241251 public void testRule1 () throws EncoderException {
242- List <String []> testValues =
243- Arrays .asList (
244- new String [] { "MACX" , "MCX" },
245- new String [] { "KNX" , "NX" },
246- new String [] { "KX" , "CX" },
247- new String [] { "PHX" , "FX" },
248- new String [] { "PFX" , "FX" },
249- new String [] { "SCHX" , "SX" });
250- for (String [] arr : testValues ) {
251- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
252- }
252+ this .assertEncodings (
253+ new String [] { "MACX" , "MCX" },
254+ new String [] { "KNX" , "NX" },
255+ new String [] { "KX" , "CX" },
256+ new String [] { "PHX" , "FX" },
257+ new String [] { "PFX" , "FX" },
258+ new String [] { "SCHX" , "SX" });
253259 }
254260
255261 /**
@@ -259,18 +265,14 @@ public void testRule1() throws EncoderException {
259265 */
260266 @ Test
261267 public void testRule2 () throws EncoderException {
262- List <String []> testValues =
263- Arrays .asList (
264- new String [] { "XEE" , "XY" },
265- new String [] { "XIE" , "XY" },
266- new String [] { "XDT" , "XD" },
267- new String [] { "XRT" , "XD" },
268- new String [] { "XRD" , "XD" },
269- new String [] { "XNT" , "XD" },
270- new String [] { "XND" , "XD" });
271- for (String [] arr : testValues ) {
272- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
273- }
268+ this .assertEncodings (
269+ new String [] { "XEE" , "XY" },
270+ new String [] { "XIE" , "XY" },
271+ new String [] { "XDT" , "XD" },
272+ new String [] { "XRT" , "XD" },
273+ new String [] { "XRD" , "XD" },
274+ new String [] { "XNT" , "XD" },
275+ new String [] { "XND" , "XD" });
274276 }
275277
276278 /**
@@ -280,17 +282,13 @@ public void testRule2() throws EncoderException {
280282 */
281283 @ Test
282284 public void testRule4Dot1 () throws EncoderException {
283- List <String []> testValues =
284- Arrays .asList (
285- new String [] { "XEV" , "XAF" },
286- new String [] { "XAX" , "XAX" },
287- new String [] { "XEX" , "XAX" },
288- new String [] { "XIX" , "XAX" },
289- new String [] { "XOX" , "XAX" },
290- new String [] { "XUX" , "XAX" });
291- for (String [] arr : testValues ) {
292- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
293- }
285+ this .assertEncodings (
286+ new String [] { "XEV" , "XAF" },
287+ new String [] { "XAX" , "XAX" },
288+ new String [] { "XEX" , "XAX" },
289+ new String [] { "XIX" , "XAX" },
290+ new String [] { "XOX" , "XAX" },
291+ new String [] { "XUX" , "XAX" });
294292 }
295293
296294 /**
@@ -300,14 +298,10 @@ public void testRule4Dot1() throws EncoderException {
300298 */
301299 @ Test
302300 public void testRule4Dot2 () throws EncoderException {
303- List <String []> testValues =
304- Arrays .asList (
305- new String [] { "XQ" , "XG" },
306- new String [] { "XZ" , "X" },
307- new String [] { "XM" , "XN" });
308- for (String [] arr : testValues ) {
309- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
310- }
301+ this .assertEncodings (
302+ new String [] { "XQ" , "XG" },
303+ new String [] { "XZ" , "X" },
304+ new String [] { "XM" , "XN" });
311305 }
312306
313307 /**
@@ -317,13 +311,9 @@ public void testRule4Dot2() throws EncoderException {
317311 */
318312 @ Test
319313 public void testRule5 () throws EncoderException {
320- List <String []> testValues =
321- Arrays .asList (
322- new String [] { "XS" , "X" },
323- new String [] { "XSS" , "X" });
324- for (String [] arr : testValues ) {
325- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
326- }
314+ this .assertEncodings (
315+ new String [] { "XS" , "X" },
316+ new String [] { "XSS" , "X" });
327317 }
328318
329319 /**
@@ -333,13 +323,9 @@ public void testRule5() throws EncoderException {
333323 */
334324 @ Test
335325 public void testRule6 () throws EncoderException {
336- List <String []> testValues =
337- Arrays .asList (
338- new String [] { "XAY" , "XY" },
339- new String [] { "XAYS" , "XY" }); // Rules 5, 6
340- for (String [] arr : testValues ) {
341- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
342- }
326+ this .assertEncodings (
327+ new String [] { "XAY" , "XY" },
328+ new String [] { "XAYS" , "XY" }); // Rules 5, 6
343329 }
344330
345331 /**
@@ -349,13 +335,9 @@ public void testRule6() throws EncoderException {
349335 */
350336 @ Test
351337 public void testRule7 () throws EncoderException {
352- List <String []> testValues =
353- Arrays .asList (
354- new String [] { "XA" , "X" },
355- new String [] { "XAS" , "X" }); // Rules 5, 7
356- for (String [] arr : testValues ) {
357- Assert .assertEquals ("Problem with " + arr [0 ], arr [1 ], this .fullNysiis .encode (arr [0 ]));
358- }
338+ this .assertEncodings (
339+ new String [] { "XA" , "X" },
340+ new String [] { "XAS" , "X" }); // Rules 5, 7
359341 }
360342 @ Test
361343 public void testSnad () throws EncoderException {
0 commit comments