2222import org .apache .commons .codec .StringEncoderAbstractTest ;
2323
2424/**
25- * @version $Revision: 1.10 $ $Date: 2004/03/17 19:28:37 $
25+ * @version $Revision: 1.11 $ $Date: 2004/04/18 21:34:16 $
2626 * @author Apache Software Foundation
2727 */
2828public class MetaphoneTest extends StringEncoderAbstractTest {
@@ -40,7 +40,8 @@ public MetaphoneTest(String name) {
4040 public void assertIsMetaphoneEqual (String source , String [] matches ) {
4141 // match source to all matches
4242 for (int i = 0 ; i < matches .length ; i ++) {
43- assertTrue (this .getMetaphone ().isMetaphoneEqual (source , matches [i ]));
43+ assertTrue ("Source: " + source + ", should have same Metaphone as: " + matches [i ],
44+ this .getMetaphone ().isMetaphoneEqual (source , matches [i ]));
4445 }
4546 // match to each other
4647 for (int i = 0 ; i < matches .length ; i ++) {
@@ -374,6 +375,7 @@ public void testIsMetaphoneEqualXalan() {
374375 }
375376
376377 public void testMetaphone () {
378+ assertEquals ("HL" , this .getMetaphone ().metaphone ("howl" ));
377379 assertEquals ("TSTN" , this .getMetaphone ().metaphone ("testing" ));
378380 assertEquals ("0" , this .getMetaphone ().metaphone ("The" ));
379381 assertEquals ("KK" , this .getMetaphone ().metaphone ("quick" ));
@@ -385,6 +387,77 @@ public void testMetaphone() {
385387 assertEquals ("LS" , this .getMetaphone ().metaphone ("lazy" ));
386388 assertEquals ("TKS" , this .getMetaphone ().metaphone ("dogs" ));
387389 }
390+
391+ public void testWordEndingInMB () {
392+ assertEquals ( "KM" , this .getMetaphone ().metaphone ("COMB" ) );
393+ assertEquals ( "TM" , this .getMetaphone ().metaphone ("TOMB" ) );
394+ assertEquals ( "WM" , this .getMetaphone ().metaphone ("WOMB" ) );
395+ }
396+
397+ public void testDiscardOfSCEOrSCIOrSCY () {
398+ assertEquals ( "SNS" , this .getMetaphone ().metaphone ("SCIENCE" ) );
399+ assertEquals ( "SN" , this .getMetaphone ().metaphone ("SCENE" ) );
400+ assertEquals ( "S" , this .getMetaphone ().metaphone ("SCY" ) );
401+ }
402+
403+ public void testWordsWithCIA () {
404+ assertEquals ( "XP" , this .getMetaphone ().metaphone ("CIAPO" ) );
405+ }
406+
407+ public void testTranslateOfSCHAndCH () {
408+ assertEquals ( "SKTL" , this .getMetaphone ().metaphone ("SCHEDULE" ) );
409+ assertEquals ( "SKMT" , this .getMetaphone ().metaphone ("SCHEMATIC" ) );
410+
411+ assertEquals ( "KRKT" , this .getMetaphone ().metaphone ("CHARACTER" ) );
412+ assertEquals ( "TX" , this .getMetaphone ().metaphone ("TEACH" ) );
413+ }
414+
415+ public void testTranslateToJOfDGEOrDGIOrDGY () {
416+ assertEquals ( "TJ" , this .getMetaphone ().metaphone ("DODGY" ) );
417+ assertEquals ( "TJ" , this .getMetaphone ().metaphone ("DODGE" ) );
418+ assertEquals ( "AJMT" , this .getMetaphone ().metaphone ("ADGIEMTI" ) );
419+ }
420+
421+ public void testDiscardOfSilentHAfterG () {
422+ assertEquals ( "KNT" , this .getMetaphone ().metaphone ("GHENT" ) );
423+ assertEquals ( "B" , this .getMetaphone ().metaphone ("BAUGH" ) );
424+ }
425+
426+ public void testDiscardOfSilentGN () {
427+ assertEquals ( "N" , this .getMetaphone ().metaphone ("GNU" ) );
428+ assertEquals ( "SNT" , this .getMetaphone ().metaphone ("SIGNED" ) );
429+ }
430+
431+ public void testPHTOF () {
432+ assertEquals ( "FX" , this .getMetaphone ().metaphone ("PHISH" ) );
433+ }
434+
435+ public void testSHAndSIOAndSIAToX () {
436+ assertEquals ( "XT" , this .getMetaphone ().metaphone ("SHOT" ) );
437+ assertEquals ( "OTXN" , this .getMetaphone ().metaphone ("ODSIAN" ) );
438+ assertEquals ( "PLXN" , this .getMetaphone ().metaphone ("PULSION" ) );
439+ }
440+
441+ public void testTIOAndTIAToX () {
442+ assertEquals ( "OX" , this .getMetaphone ().metaphone ("OTIA" ) );
443+ assertEquals ( "PRXN" , this .getMetaphone ().metaphone ("PORTION" ) );
444+ }
445+
446+ public void testTCH () {
447+ assertEquals ( "RX" , this .getMetaphone ().metaphone ("RETCH" ) );
448+ assertEquals ( "WX" , this .getMetaphone ().metaphone ("WATCH" ) );
449+ }
450+
451+ public void testExceedLength () {
452+ // should be AKSKS, but istruncated by Max Code Length
453+ assertEquals ( "AKSK" , this .getMetaphone ().metaphone ("AXEAXE" ) );
454+ }
455+
456+ public void testSetMaxLengthWithTruncation () {
457+ // should be AKSKS, but istruncated by Max Code Length
458+ this .getMetaphone ().setMaxCodeLen ( 6 );
459+ assertEquals ( "AKSKSK" , this .getMetaphone ().metaphone ("AXEAXEAXE" ) );
460+ }
388461
389462 public void validateFixture (String [][] pairs ) {
390463 if (pairs .length == 0 ) {
0 commit comments