Skip to content

Commit e8b045b

Browse files
author
Timothy O'Brien
committed
Increased unit test coverage on Metaphone and RefinedSoundex
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130363 13f79535-47bb-0310-9956-ffa450edef68
1 parent ac23124 commit e8b045b

3 files changed

Lines changed: 87 additions & 4 deletions

File tree

src/test/org/apache/commons/codec/language/MetaphoneTest.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import 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
*/
2828
public 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) {

src/test/org/apache/commons/codec/language/RefinedSoundexTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* Tests RefinedSoundex.
2727
*
28-
* @version $Id: RefinedSoundexTest.java,v 1.9 2004/03/21 01:30:11 ggregory Exp $
28+
* @version $Id: RefinedSoundexTest.java,v 1.10 2004/04/18 21:34:16 tobrien Exp $
2929
* @author Apache Software Foundation
3030
*/
3131
public class RefinedSoundexTest extends StringEncoderAbstractTest {
@@ -103,4 +103,9 @@ public void testEncode() {
103103
assertEquals("L7050", this.getEncoder().encode("lazy"));
104104
assertEquals("D6043", this.getEncoder().encode("dogs"));
105105
}
106+
107+
public void testGetMappingCodeNonLetter() {
108+
char code = this.getEncoder().getMappingCode('#');
109+
assertEquals( "Code does not equals zero", 0, (int) code);
110+
}
106111
}

src/test/org/apache/commons/codec/language/SoundexTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* Tests {@link Soundex}
2828
*
29-
* @version $Revision: 1.15 $ $Date: 2004/04/09 22:46:08 $
29+
* @version $Revision: 1.16 $ $Date: 2004/04/18 21:34:16 $
3030
* @author Apache Software Foundation
3131
*/
3232
public class SoundexTest extends StringEncoderAbstractTest {
@@ -208,6 +208,11 @@ public void testEncodeBatch4() {
208208

209209
}
210210

211+
public void testBadCharacters() {
212+
assertEquals("H452", this.getEncoder().encode("HOL>MES"));
213+
214+
}
215+
211216
public void testEncodeIgnoreApostrophes() {
212217
this.encodeAll(new String[] { "OBrien", "'OBrien", "O'Brien", "OB'rien", "OBr'ien", "OBri'en", "OBrie'n", "OBrien'" }, "O165");
213218
}

0 commit comments

Comments
 (0)