You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2011/02/28 18:10:16 UTC
svn commit: r1075426 [3/3] - in
/commons/proper/codec/trunk/src/test/org/apache/commons/codec: ./ language/
Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java?rev=1075426&r1=1075425&r2=1075426&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java Mon Feb 28 17:10:15 2011
@@ -998,8 +998,6 @@ public class DoubleMetaphoneTest extends
"wundeews", "windows" }, {
"yeild", "yield" }, };
- private DoubleMetaphone doubleMetaphone = null;
-
public DoubleMetaphoneTest(String name) {
super(name);
}
@@ -1051,25 +1049,11 @@ public class DoubleMetaphoneTest extends
}
private DoubleMetaphone getDoubleMetaphone() {
- return this.doubleMetaphone;
- }
-
- protected StringEncoder createEncoder() {
- return new Metaphone();
- }
-
- private void setDoubleMetaphone(DoubleMetaphone doubleMetaphone) {
- this.doubleMetaphone = doubleMetaphone;
- }
-
- public void setUp() throws Exception {
- super.setUp();
- this.setDoubleMetaphone(new DoubleMetaphone());
+ return (DoubleMetaphone) this.getStringEncoder();
}
- public void tearDown() throws Exception {
- super.tearDown();
- this.setDoubleMetaphone(null);
+ protected StringEncoder createStringEncoder() {
+ return new DoubleMetaphone();
}
public void testDoubleMetaphone() {
Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/MetaphoneTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/MetaphoneTest.java?rev=1075426&r1=1075425&r2=1075426&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/MetaphoneTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/MetaphoneTest.java Mon Feb 28 17:10:15 2011
@@ -26,8 +26,6 @@ import org.apache.commons.codec.StringEn
*/
public class MetaphoneTest extends StringEncoderAbstractTest {
- private Metaphone metaphone = null;
-
public MetaphoneTest(String name) {
super(name);
}
@@ -56,35 +54,18 @@ public class MetaphoneTest extends Strin
assertTrue(failMsg, this.getMetaphone().isMetaphoneEqual(name1, name0));
}
}
+
/**
* @return Returns the metaphone.
*/
private Metaphone getMetaphone() {
- return this.metaphone;
+ return (Metaphone) this.getStringEncoder();
}
- protected StringEncoder createEncoder() {
+ protected StringEncoder createStringEncoder() {
return new Metaphone();
}
- /**
- * @param metaphone
- * The metaphone to set.
- */
- private void setMetaphone(Metaphone metaphone) {
- this.metaphone = metaphone;
- }
-
- public void setUp() throws Exception {
- super.setUp();
- this.setMetaphone(new Metaphone());
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- this.setMetaphone(null);
- }
-
public void testIsMetaphoneEqual1() {
this.assertMetaphoneEqual(new String[][] { { "Case", "case" }, {
"CASE", "Case" }, {
Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/RefinedSoundexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/RefinedSoundexTest.java?rev=1075426&r1=1075425&r2=1075426&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/RefinedSoundexTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/RefinedSoundexTest.java Mon Feb 28 17:10:15 2011
@@ -29,81 +29,61 @@ import org.apache.commons.codec.StringEn
*/
public class RefinedSoundexTest extends StringEncoderAbstractTest {
- private RefinedSoundex encoder = null;
-
public RefinedSoundexTest(String name) {
super(name);
}
- /**
- * @return Returns the encoder.
- */
- private RefinedSoundex getEncoder() {
- return this.encoder;
- }
-
- protected StringEncoder createEncoder() {
+ protected StringEncoder createStringEncoder() {
return new RefinedSoundex();
}
/**
- * @param encoder
- * The encoder to set.
+ * @return Returns the encoder.
*/
- private void setEncoder(RefinedSoundex encoder) {
- this.encoder = encoder;
- }
-
- public void setUp() throws Exception {
- super.setUp();
- this.setEncoder(new RefinedSoundex());
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- this.setEncoder(null);
+ private RefinedSoundex getRefinedSoundex() {
+ return (RefinedSoundex)this.getStringEncoder();
}
public void testDifference() throws EncoderException {
// Edge cases
- assertEquals(0, this.getEncoder().difference(null, null));
- assertEquals(0, this.getEncoder().difference("", ""));
- assertEquals(0, this.getEncoder().difference(" ", " "));
+ assertEquals(0, this.getRefinedSoundex().difference(null, null));
+ assertEquals(0, this.getRefinedSoundex().difference("", ""));
+ assertEquals(0, this.getRefinedSoundex().difference(" ", " "));
// Normal cases
- assertEquals(6, this.getEncoder().difference("Smith", "Smythe"));
- assertEquals(3, this.getEncoder().difference("Ann", "Andrew"));
- assertEquals(1, this.getEncoder().difference("Margaret", "Andrew"));
- assertEquals(1, this.getEncoder().difference("Janet", "Margaret"));
+ assertEquals(6, this.getRefinedSoundex().difference("Smith", "Smythe"));
+ assertEquals(3, this.getRefinedSoundex().difference("Ann", "Andrew"));
+ assertEquals(1, this.getRefinedSoundex().difference("Margaret", "Andrew"));
+ assertEquals(1, this.getRefinedSoundex().difference("Janet", "Margaret"));
// Examples from
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp
- assertEquals(5, this.getEncoder().difference("Green", "Greene"));
- assertEquals(1, this.getEncoder().difference("Blotchet-Halls", "Greene"));
+ assertEquals(5, this.getRefinedSoundex().difference("Green", "Greene"));
+ assertEquals(1, this.getRefinedSoundex().difference("Blotchet-Halls", "Greene"));
// Examples from
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_3o6w.asp
- assertEquals(6, this.getEncoder().difference("Smith", "Smythe"));
- assertEquals(8, this.getEncoder().difference("Smithers", "Smythers"));
- assertEquals(5, this.getEncoder().difference("Anothers", "Brothers"));
+ assertEquals(6, this.getRefinedSoundex().difference("Smith", "Smythe"));
+ assertEquals(8, this.getRefinedSoundex().difference("Smithers", "Smythers"));
+ assertEquals(5, this.getRefinedSoundex().difference("Anothers", "Brothers"));
}
public void testEncode() {
- assertEquals("T6036084", this.getEncoder().encode("testing"));
- assertEquals("T6036084", this.getEncoder().encode("TESTING"));
- assertEquals("T60", this.getEncoder().encode("The"));
- assertEquals("Q503", this.getEncoder().encode("quick"));
- assertEquals("B1908", this.getEncoder().encode("brown"));
- assertEquals("F205", this.getEncoder().encode("fox"));
- assertEquals("J408106", this.getEncoder().encode("jumped"));
- assertEquals("O0209", this.getEncoder().encode("over"));
- assertEquals("T60", this.getEncoder().encode("the"));
- assertEquals("L7050", this.getEncoder().encode("lazy"));
- assertEquals("D6043", this.getEncoder().encode("dogs"));
+ assertEquals("T6036084", this.getRefinedSoundex().encode("testing"));
+ assertEquals("T6036084", this.getRefinedSoundex().encode("TESTING"));
+ assertEquals("T60", this.getRefinedSoundex().encode("The"));
+ assertEquals("Q503", this.getRefinedSoundex().encode("quick"));
+ assertEquals("B1908", this.getRefinedSoundex().encode("brown"));
+ assertEquals("F205", this.getRefinedSoundex().encode("fox"));
+ assertEquals("J408106", this.getRefinedSoundex().encode("jumped"));
+ assertEquals("O0209", this.getRefinedSoundex().encode("over"));
+ assertEquals("T60", this.getRefinedSoundex().encode("the"));
+ assertEquals("L7050", this.getRefinedSoundex().encode("lazy"));
+ assertEquals("D6043", this.getRefinedSoundex().encode("dogs"));
// Testing CODEC-56
assertEquals("D6043", RefinedSoundex.US_ENGLISH.encode("dogs"));
}
public void testGetMappingCodeNonLetter() {
- char code = this.getEncoder().getMappingCode('#');
+ char code = this.getRefinedSoundex().getMappingCode('#');
assertEquals("Code does not equals zero", 0, code);
}
Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/SoundexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/SoundexTest.java?rev=1075426&r1=1075425&r2=1075426&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/SoundexTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/SoundexTest.java Mon Feb 28 17:10:15 2011
@@ -16,288 +16,266 @@
*/
// (FYI: Formatted and sorted with Eclipse)
+
package org.apache.commons.codec.language;
+import junit.framework.Assert;
+
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;
import org.apache.commons.codec.StringEncoderAbstractTest;
/**
* Tests {@link Soundex}
- *
+ *
* @author Apache Software Foundation
* @version $Id$
*/
public class SoundexTest extends StringEncoderAbstractTest {
- private Soundex encoder = null;
-
public SoundexTest(String name) {
super(name);
}
- void encodeAll(String[] strings, String expectedEncoding) {
- for (int i = 0; i < strings.length; i++) {
- assertEquals(expectedEncoding, this.getEncoder().encode(strings[i]));
- }
+ protected StringEncoder createStringEncoder() {
+ return new Soundex();
}
/**
- * @return Returns the _encoder.
+ * @return Returns the encoder.
*/
- public Soundex getEncoder() {
- return this.encoder;
+ public Soundex getSoundexEncoder() {
+ return (Soundex)this.getStringEncoder();
}
- protected StringEncoder createEncoder() {
- return new Soundex();
+ public void testB650() throws EncoderException {
+ this.checkEncodingVariations("B650", (new String[]{
+ "BARHAM",
+ "BARONE",
+ "BARRON",
+ "BERNA",
+ "BIRNEY",
+ "BIRNIE",
+ "BOOROM",
+ "BOREN",
+ "BORN",
+ "BOURN",
+ "BOURNE",
+ "BOWRON",
+ "BRAIN",
+ "BRAME",
+ "BRANN",
+ "BRAUN",
+ "BREEN",
+ "BRIEN",
+ "BRIM",
+ "BRIMM",
+ "BRINN",
+ "BRION",
+ "BROOM",
+ "BROOME",
+ "BROWN",
+ "BROWNE",
+ "BRUEN",
+ "BRUHN",
+ "BRUIN",
+ "BRUMM",
+ "BRUN",
+ "BRUNO",
+ "BRYAN",
+ "BURIAN",
+ "BURN",
+ "BURNEY",
+ "BYRAM",
+ "BYRNE",
+ "BYRON",
+ "BYRUM"}));
}
- /**
- * @param encoder
- * The encoder to set.
- */
- public void setEncoder(Soundex encoder) {
- this.encoder = encoder;
- }
+ public void testBadCharacters() {
+ Assert.assertEquals("H452", this.getSoundexEncoder().encode("HOL>MES"));
- public void setUp() throws Exception {
- super.setUp();
- this.setEncoder(new Soundex());
- }
-
- public void tearDown() throws Exception {
- super.tearDown();
- this.setEncoder(null);
- }
-
- public void testB650() {
- this.encodeAll(
- new String[] {
- "BARHAM",
- "BARONE",
- "BARRON",
- "BERNA",
- "BIRNEY",
- "BIRNIE",
- "BOOROM",
- "BOREN",
- "BORN",
- "BOURN",
- "BOURNE",
- "BOWRON",
- "BRAIN",
- "BRAME",
- "BRANN",
- "BRAUN",
- "BREEN",
- "BRIEN",
- "BRIM",
- "BRIMM",
- "BRINN",
- "BRION",
- "BROOM",
- "BROOME",
- "BROWN",
- "BROWNE",
- "BRUEN",
- "BRUHN",
- "BRUIN",
- "BRUMM",
- "BRUN",
- "BRUNO",
- "BRYAN",
- "BURIAN",
- "BURN",
- "BURNEY",
- "BYRAM",
- "BYRNE",
- "BYRON",
- "BYRUM" },
- "B650");
}
public void testDifference() throws EncoderException {
// Edge cases
- assertEquals(0, this.getEncoder().difference(null, null));
- assertEquals(0, this.getEncoder().difference("", ""));
- assertEquals(0, this.getEncoder().difference(" ", " "));
+ Assert.assertEquals(0, this.getSoundexEncoder().difference(null, null));
+ Assert.assertEquals(0, this.getSoundexEncoder().difference("", ""));
+ Assert.assertEquals(0, this.getSoundexEncoder().difference(" ", " "));
// Normal cases
- assertEquals(4, this.getEncoder().difference("Smith", "Smythe"));
- assertEquals(2, this.getEncoder().difference("Ann", "Andrew"));
- assertEquals(1, this.getEncoder().difference("Margaret", "Andrew"));
- assertEquals(0, this.getEncoder().difference("Janet", "Margaret"));
+ Assert.assertEquals(4, this.getSoundexEncoder().difference("Smith", "Smythe"));
+ Assert.assertEquals(2, this.getSoundexEncoder().difference("Ann", "Andrew"));
+ Assert.assertEquals(1, this.getSoundexEncoder().difference("Margaret", "Andrew"));
+ Assert.assertEquals(0, this.getSoundexEncoder().difference("Janet", "Margaret"));
// Examples from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp
- assertEquals(4, this.getEncoder().difference("Green", "Greene"));
- assertEquals(0, this.getEncoder().difference("Blotchet-Halls", "Greene"));
+ Assert.assertEquals(4, this.getSoundexEncoder().difference("Green", "Greene"));
+ Assert.assertEquals(0, this.getSoundexEncoder().difference("Blotchet-Halls", "Greene"));
// Examples from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_3o6w.asp
- assertEquals(4, this.getEncoder().difference("Smith", "Smythe"));
- assertEquals(4, this.getEncoder().difference("Smithers", "Smythers"));
- assertEquals(2, this.getEncoder().difference("Anothers", "Brothers"));
+ Assert.assertEquals(4, this.getSoundexEncoder().difference("Smith", "Smythe"));
+ Assert.assertEquals(4, this.getSoundexEncoder().difference("Smithers", "Smythers"));
+ Assert.assertEquals(2, this.getSoundexEncoder().difference("Anothers", "Brothers"));
}
public void testEncodeBasic() {
- assertEquals("T235", this.getEncoder().encode("testing"));
- assertEquals("T000", this.getEncoder().encode("The"));
- assertEquals("Q200", this.getEncoder().encode("quick"));
- assertEquals("B650", this.getEncoder().encode("brown"));
- assertEquals("F200", this.getEncoder().encode("fox"));
- assertEquals("J513", this.getEncoder().encode("jumped"));
- assertEquals("O160", this.getEncoder().encode("over"));
- assertEquals("T000", this.getEncoder().encode("the"));
- assertEquals("L200", this.getEncoder().encode("lazy"));
- assertEquals("D200", this.getEncoder().encode("dogs"));
+ Assert.assertEquals("T235", this.getSoundexEncoder().encode("testing"));
+ Assert.assertEquals("T000", this.getSoundexEncoder().encode("The"));
+ Assert.assertEquals("Q200", this.getSoundexEncoder().encode("quick"));
+ Assert.assertEquals("B650", this.getSoundexEncoder().encode("brown"));
+ Assert.assertEquals("F200", this.getSoundexEncoder().encode("fox"));
+ Assert.assertEquals("J513", this.getSoundexEncoder().encode("jumped"));
+ Assert.assertEquals("O160", this.getSoundexEncoder().encode("over"));
+ Assert.assertEquals("T000", this.getSoundexEncoder().encode("the"));
+ Assert.assertEquals("L200", this.getSoundexEncoder().encode("lazy"));
+ Assert.assertEquals("D200", this.getSoundexEncoder().encode("dogs"));
}
/**
- * Examples from
- * http://www.bradandkathy.com/genealogy/overviewofsoundex.html
+ * Examples from http://www.bradandkathy.com/genealogy/overviewofsoundex.html
*/
public void testEncodeBatch2() {
- assertEquals("A462", this.getEncoder().encode("Allricht"));
- assertEquals("E166", this.getEncoder().encode("Eberhard"));
- assertEquals("E521", this.getEncoder().encode("Engebrethson"));
- assertEquals("H512", this.getEncoder().encode("Heimbach"));
- assertEquals("H524", this.getEncoder().encode("Hanselmann"));
- assertEquals("H431", this.getEncoder().encode("Hildebrand"));
- assertEquals("K152", this.getEncoder().encode("Kavanagh"));
- assertEquals("L530", this.getEncoder().encode("Lind"));
- assertEquals("L222", this.getEncoder().encode("Lukaschowsky"));
- assertEquals("M235", this.getEncoder().encode("McDonnell"));
- assertEquals("M200", this.getEncoder().encode("McGee"));
- assertEquals("O155", this.getEncoder().encode("Opnian"));
- assertEquals("O155", this.getEncoder().encode("Oppenheimer"));
- assertEquals("R355", this.getEncoder().encode("Riedemanas"));
- assertEquals("Z300", this.getEncoder().encode("Zita"));
- assertEquals("Z325", this.getEncoder().encode("Zitzmeinn"));
+ Assert.assertEquals("A462", this.getSoundexEncoder().encode("Allricht"));
+ Assert.assertEquals("E166", this.getSoundexEncoder().encode("Eberhard"));
+ Assert.assertEquals("E521", this.getSoundexEncoder().encode("Engebrethson"));
+ Assert.assertEquals("H512", this.getSoundexEncoder().encode("Heimbach"));
+ Assert.assertEquals("H524", this.getSoundexEncoder().encode("Hanselmann"));
+ Assert.assertEquals("H431", this.getSoundexEncoder().encode("Hildebrand"));
+ Assert.assertEquals("K152", this.getSoundexEncoder().encode("Kavanagh"));
+ Assert.assertEquals("L530", this.getSoundexEncoder().encode("Lind"));
+ Assert.assertEquals("L222", this.getSoundexEncoder().encode("Lukaschowsky"));
+ Assert.assertEquals("M235", this.getSoundexEncoder().encode("McDonnell"));
+ Assert.assertEquals("M200", this.getSoundexEncoder().encode("McGee"));
+ Assert.assertEquals("O155", this.getSoundexEncoder().encode("Opnian"));
+ Assert.assertEquals("O155", this.getSoundexEncoder().encode("Oppenheimer"));
+ Assert.assertEquals("R355", this.getSoundexEncoder().encode("Riedemanas"));
+ Assert.assertEquals("Z300", this.getSoundexEncoder().encode("Zita"));
+ Assert.assertEquals("Z325", this.getSoundexEncoder().encode("Zitzmeinn"));
}
/**
- * Examples from
- * http://www.archives.gov/research_room/genealogy/census/soundex.html
+ * Examples from http://www.archives.gov/research_room/genealogy/census/soundex.html
*/
public void testEncodeBatch3() {
- assertEquals("W252", this.getEncoder().encode("Washington"));
- assertEquals("L000", this.getEncoder().encode("Lee"));
- assertEquals("G362", this.getEncoder().encode("Gutierrez"));
- assertEquals("P236", this.getEncoder().encode("Pfister"));
- assertEquals("J250", this.getEncoder().encode("Jackson"));
- assertEquals("T522", this.getEncoder().encode("Tymczak"));
+ Assert.assertEquals("W252", this.getSoundexEncoder().encode("Washington"));
+ Assert.assertEquals("L000", this.getSoundexEncoder().encode("Lee"));
+ Assert.assertEquals("G362", this.getSoundexEncoder().encode("Gutierrez"));
+ Assert.assertEquals("P236", this.getSoundexEncoder().encode("Pfister"));
+ Assert.assertEquals("J250", this.getSoundexEncoder().encode("Jackson"));
+ Assert.assertEquals("T522", this.getSoundexEncoder().encode("Tymczak"));
// For VanDeusen: D-250 (D, 2 for the S, 5 for the N, 0 added) is also
// possible.
- assertEquals("V532", this.getEncoder().encode("VanDeusen"));
+ Assert.assertEquals("V532", this.getSoundexEncoder().encode("VanDeusen"));
}
/**
* Examples from: http://www.myatt.demon.co.uk/sxalg.htm
*/
public void testEncodeBatch4() {
- assertEquals("H452", this.getEncoder().encode("HOLMES"));
- assertEquals("A355", this.getEncoder().encode("ADOMOMI"));
- assertEquals("V536", this.getEncoder().encode("VONDERLEHR"));
- assertEquals("B400", this.getEncoder().encode("BALL"));
- assertEquals("S000", this.getEncoder().encode("SHAW"));
- assertEquals("J250", this.getEncoder().encode("JACKSON"));
- assertEquals("S545", this.getEncoder().encode("SCANLON"));
- assertEquals("S532", this.getEncoder().encode("SAINTJOHN"));
-
- }
-
- public void testBadCharacters() {
- assertEquals("H452", this.getEncoder().encode("HOL>MES"));
+ Assert.assertEquals("H452", this.getSoundexEncoder().encode("HOLMES"));
+ Assert.assertEquals("A355", this.getSoundexEncoder().encode("ADOMOMI"));
+ Assert.assertEquals("V536", this.getSoundexEncoder().encode("VONDERLEHR"));
+ Assert.assertEquals("B400", this.getSoundexEncoder().encode("BALL"));
+ Assert.assertEquals("S000", this.getSoundexEncoder().encode("SHAW"));
+ Assert.assertEquals("J250", this.getSoundexEncoder().encode("JACKSON"));
+ Assert.assertEquals("S545", this.getSoundexEncoder().encode("SCANLON"));
+ Assert.assertEquals("S532", this.getSoundexEncoder().encode("SAINTJOHN"));
}
- public void testEncodeIgnoreApostrophes() {
- this.encodeAll(new String[] { "OBrien", "'OBrien", "O'Brien", "OB'rien", "OBr'ien", "OBri'en", "OBrie'n", "OBrien'" }, "O165");
+ public void testEncodeIgnoreApostrophes() throws EncoderException {
+ this.checkEncodingVariations("O165", (new String[]{
+ "OBrien",
+ "'OBrien",
+ "O'Brien",
+ "OB'rien",
+ "OBr'ien",
+ "OBri'en",
+ "OBrie'n",
+ "OBrien'"}));
}
/**
* Test data from http://www.myatt.demon.co.uk/sxalg.htm
+ *
+ * @throws EncoderException
*/
- public void testEncodeIgnoreHyphens() {
- this.encodeAll(
- new String[] {
- "KINGSMITH",
- "-KINGSMITH",
- "K-INGSMITH",
- "KI-NGSMITH",
- "KIN-GSMITH",
- "KING-SMITH",
- "KINGS-MITH",
- "KINGSM-ITH",
- "KINGSMI-TH",
- "KINGSMIT-H",
- "KINGSMITH-" },
- "K525");
+ public void testEncodeIgnoreHyphens() throws EncoderException {
+ this.checkEncodingVariations("K525", (new String[]{
+ "KINGSMITH",
+ "-KINGSMITH",
+ "K-INGSMITH",
+ "KI-NGSMITH",
+ "KIN-GSMITH",
+ "KING-SMITH",
+ "KINGS-MITH",
+ "KINGSM-ITH",
+ "KINGSMI-TH",
+ "KINGSMIT-H",
+ "KINGSMITH-"}));
}
public void testEncodeIgnoreTrimmable() {
- assertEquals("W252", this.getEncoder().encode(" \t\n\r Washington \t\n\r "));
+ Assert.assertEquals("W252", this.getSoundexEncoder().encode(" \t\n\r Washington \t\n\r "));
}
/**
- * Consonants from the same code group separated by W or H are treated as
- * one.
+ * Consonants from the same code group separated by W or H are treated as one.
*/
public void testHWRuleEx1() {
// From
// http://www.archives.gov/research_room/genealogy/census/soundex.html:
// Ashcraft is coded A-261 (A, 2 for the S, C ignored, 6 for the R, 1
// for the F). It is not coded A-226.
- assertEquals("A261", this.getEncoder().encode("Ashcraft"));
+ Assert.assertEquals("A261", this.getSoundexEncoder().encode("Ashcraft"));
}
/**
- * Consonants from the same code group separated by W or H are treated as
- * one.
- *
+ * Consonants from the same code group separated by W or H are treated as one.
+ *
* Test data from http://www.myatt.demon.co.uk/sxalg.htm
*/
public void testHWRuleEx2() {
- assertEquals("B312", this.getEncoder().encode("BOOTHDAVIS"));
- assertEquals("B312", this.getEncoder().encode("BOOTH-DAVIS"));
+ Assert.assertEquals("B312", this.getSoundexEncoder().encode("BOOTHDAVIS"));
+ Assert.assertEquals("B312", this.getSoundexEncoder().encode("BOOTH-DAVIS"));
}
/**
- * Consonants from the same code group separated by W or H are treated as
- * one.
+ * Consonants from the same code group separated by W or H are treated as one.
+ *
+ * @throws EncoderException
*/
- public void testHWRuleEx3() {
- assertEquals("S460", this.getEncoder().encode("Sgler"));
- assertEquals("S460", this.getEncoder().encode("Swhgler"));
+ public void testHWRuleEx3() throws EncoderException {
+ Assert.assertEquals("S460", this.getSoundexEncoder().encode("Sgler"));
+ Assert.assertEquals("S460", this.getSoundexEncoder().encode("Swhgler"));
// Also S460:
- this.encodeAll(
- new String[] {
- "SAILOR",
- "SALYER",
- "SAYLOR",
- "SCHALLER",
- "SCHELLER",
- "SCHILLER",
- "SCHOOLER",
- "SCHULER",
- "SCHUYLER",
- "SEILER",
- "SEYLER",
- "SHOLAR",
- "SHULER",
- "SILAR",
- "SILER",
- "SILLER" },
- "S460");
+ this.checkEncodingVariations("S460", (new String[]{
+ "SAILOR",
+ "SALYER",
+ "SAYLOR",
+ "SCHALLER",
+ "SCHELLER",
+ "SCHILLER",
+ "SCHOOLER",
+ "SCHULER",
+ "SCHUYLER",
+ "SEILER",
+ "SEYLER",
+ "SHOLAR",
+ "SHULER",
+ "SILAR",
+ "SILER",
+ "SILLER"}));
}
public void testMaxLength() throws Exception {
Soundex soundex = new Soundex();
soundex.setMaxLength(soundex.getMaxLength());
- assertEquals("S460", this.getEncoder().encode("Sgler"));
+ Assert.assertEquals("S460", this.getSoundexEncoder().encode("Sgler"));
}
public void testMaxLengthLessThan3Fix() throws Exception {
Soundex soundex = new Soundex();
soundex.setMaxLength(2);
- assertEquals("S460", soundex.encode("SCHELLER"));
+ Assert.assertEquals("S460", soundex.encode("SCHELLER"));
}
/**
@@ -305,102 +283,104 @@ public class SoundexTest extends StringE
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_3o6w.asp
*/
public void testMsSqlServer1() {
- assertEquals("S530", this.getEncoder().encode("Smith"));
- assertEquals("S530", this.getEncoder().encode("Smythe"));
+ Assert.assertEquals("S530", this.getSoundexEncoder().encode("Smith"));
+ Assert.assertEquals("S530", this.getSoundexEncoder().encode("Smythe"));
}
/**
* Examples for MS SQLServer from
- * http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q100/3/65.asp&NoWebContent=1
+ * http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support
+ * /kb/articles/Q100/3/65.asp&NoWebContent=1
+ *
+ * @throws EncoderException
*/
- public void testMsSqlServer2() {
- this.encodeAll(new String[]{"Erickson", "Erickson", "Erikson", "Ericson", "Ericksen", "Ericsen"}, "E625");
+ public void testMsSqlServer2() throws EncoderException {
+ this.checkEncodingVariations("E625", (new String[]{"Erickson", "Erickson", "Erikson", "Ericson", "Ericksen", "Ericsen"}));
}
+
/**
- * Examples for MS SQLServer from
- * http://databases.about.com/library/weekly/aa042901a.htm
+ * Examples for MS SQLServer from http://databases.about.com/library/weekly/aa042901a.htm
*/
public void testMsSqlServer3() {
- assertEquals("A500", this.getEncoder().encode("Ann"));
- assertEquals("A536", this.getEncoder().encode("Andrew"));
- assertEquals("J530", this.getEncoder().encode("Janet"));
- assertEquals("M626", this.getEncoder().encode("Margaret"));
- assertEquals("S315", this.getEncoder().encode("Steven"));
- assertEquals("M240", this.getEncoder().encode("Michael"));
- assertEquals("R163", this.getEncoder().encode("Robert"));
- assertEquals("L600", this.getEncoder().encode("Laura"));
- assertEquals("A500", this.getEncoder().encode("Anne"));
+ Assert.assertEquals("A500", this.getSoundexEncoder().encode("Ann"));
+ Assert.assertEquals("A536", this.getSoundexEncoder().encode("Andrew"));
+ Assert.assertEquals("J530", this.getSoundexEncoder().encode("Janet"));
+ Assert.assertEquals("M626", this.getSoundexEncoder().encode("Margaret"));
+ Assert.assertEquals("S315", this.getSoundexEncoder().encode("Steven"));
+ Assert.assertEquals("M240", this.getSoundexEncoder().encode("Michael"));
+ Assert.assertEquals("R163", this.getSoundexEncoder().encode("Robert"));
+ Assert.assertEquals("L600", this.getSoundexEncoder().encode("Laura"));
+ Assert.assertEquals("A500", this.getSoundexEncoder().encode("Anne"));
+ }
+
+ /**
+ * https://issues.apache.org/jira/browse/CODEC-54 https://issues.apache.org/jira/browse/CODEC-56
+ */
+ public void testNewInstance() {
+ Assert.assertEquals("W452", new Soundex().soundex("Williams"));
+ }
+
+ public void testNewInstance2() {
+ Assert.assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING.toCharArray()).soundex("Williams"));
+ }
+
+ public void testNewInstance3() {
+ Assert.assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING).soundex("Williams"));
+ }
+
+ public void testSoundexUtilsConstructable() {
+ new SoundexUtils();
+ }
+
+ public void testSoundexUtilsNullBehaviour() {
+ Assert.assertEquals(null, SoundexUtils.clean(null));
+ Assert.assertEquals("", SoundexUtils.clean(""));
+ Assert.assertEquals(0, SoundexUtils.differenceEncoded(null, ""));
+ Assert.assertEquals(0, SoundexUtils.differenceEncoded("", null));
+ }
+
+ /**
+ * https://issues.apache.org/jira/browse/CODEC-54 https://issues.apache.org/jira/browse/CODEC-56
+ */
+ public void testUsEnglishStatic() {
+ Assert.assertEquals("W452", Soundex.US_ENGLISH.soundex("Williams"));
}
/**
* Fancy characters are not mapped by the default US mapping.
- *
+ *
* http://issues.apache.org/bugzilla/show_bug.cgi?id=29080
*/
- public void testUsMappingOWithDiaeresis() {
- assertEquals("O000", this.getEncoder().encode("o"));
- if ( Character.isLetter('ö') ) {
+ public void testUsMappingEWithAcute() {
+ Assert.assertEquals("E000", this.getSoundexEncoder().encode("e"));
+ if (Character.isLetter('é')) {
try {
- assertEquals("Ö000", this.getEncoder().encode("ö"));
- fail("Expected IllegalArgumentException not thrown");
+ Assert.assertEquals("É000", this.getSoundexEncoder().encode("é"));
+ Assert.fail("Expected IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
// expected
}
} else {
- assertEquals("", this.getEncoder().encode("ö"));
+ Assert.assertEquals("", this.getSoundexEncoder().encode("é"));
}
}
/**
* Fancy characters are not mapped by the default US mapping.
- *
+ *
* http://issues.apache.org/bugzilla/show_bug.cgi?id=29080
*/
- public void testUsMappingEWithAcute() {
- assertEquals("E000", this.getEncoder().encode("e"));
- if ( Character.isLetter('é') ) {
+ public void testUsMappingOWithDiaeresis() {
+ Assert.assertEquals("O000", this.getSoundexEncoder().encode("o"));
+ if (Character.isLetter('ö')) {
try {
- assertEquals("É000", this.getEncoder().encode("é"));
- fail("Expected IllegalArgumentException not thrown");
+ Assert.assertEquals("Ö000", this.getSoundexEncoder().encode("ö"));
+ Assert.fail("Expected IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
// expected
}
} else {
- assertEquals("", this.getEncoder().encode("é"));
+ Assert.assertEquals("", this.getSoundexEncoder().encode("ö"));
}
}
-
- /**
- * https://issues.apache.org/jira/browse/CODEC-54
- * https://issues.apache.org/jira/browse/CODEC-56
- */
- public void testUsEnglishStatic() {
- assertEquals("W452", Soundex.US_ENGLISH.soundex("Williams"));
- }
-
- /**
- * https://issues.apache.org/jira/browse/CODEC-54
- * https://issues.apache.org/jira/browse/CODEC-56
- */
- public void testNewInstance() {
- assertEquals("W452", new Soundex().soundex("Williams"));
- }
-
- public void testNewInstance2() {
- assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING.toCharArray()).soundex("Williams"));
- }
-
- public void testNewInstance3() {
- assertEquals("W452", new Soundex(Soundex.US_ENGLISH_MAPPING_STRING).soundex("Williams"));
- }
-
- public void testSoundexUtilsNullBehaviour() {
- assertEquals(null, SoundexUtils.clean(null));
- assertEquals("", SoundexUtils.clean(""));
- assertEquals(0, SoundexUtils.differenceEncoded(null, ""));
- assertEquals(0, SoundexUtils.differenceEncoded("", null));
- }
- public void testSoundexUtilsConstructable() {
- new SoundexUtils();
- }
}