Skip to content

Commit f1994bd

Browse files
committed
1 parent c1f8d1f commit f1994bd

1 file changed

Lines changed: 64 additions & 9 deletions

File tree

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

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,36 @@
1717

1818
package org.apache.commons.codec.language;
1919

20+
import junit.framework.Assert;
21+
2022
import org.apache.commons.codec.StringEncoder;
2123
import org.apache.commons.codec.StringEncoderAbstractTest;
2224

2325
public class ColognePhoneticTest extends StringEncoderAbstractTest {
2426

27+
private ColognePhonetic colognePhonetic = new ColognePhonetic();
28+
2529
public ColognePhoneticTest(String name) {
2630
super(name);
2731
}
2832

33+
public void checkEncoding(String expected, String source) {
34+
Assert.assertEquals("Source: " + source, expected, this.colognePhonetic.encode(source));
35+
}
36+
2937
protected StringEncoder createEncoder() {
3038
return new ColognePhonetic();
3139
}
3240

3341
public void testAabjoe() {
34-
assertEquals("01", new ColognePhonetic().encode("Aabjoe"));
42+
this.checkEncoding("01", "Aabjoe");
3543
}
3644

37-
public void testBorderCases() {
38-
ColognePhonetic koellePhon = new ColognePhonetic();
45+
public void testAaclan() {
46+
this.checkEncoding("0856", "Aaclan");
47+
}
3948

49+
public void testEdgeCases() {
4050
String[][] data = {
4151
{"a", "0"},
4252
{"e", "0"},
@@ -69,21 +79,66 @@ public void testBorderCases() {
6979
{"r", "7"}};
7080

7181
for (int i = 0; i < data.length; i++) {
72-
assertEquals("Failed to correctly convert element of index: " + i, data[i][1], koellePhon.colognePhonetic(data[i][0]));
82+
Assert.assertEquals("Failed to correctly convert element of index: " + i, data[i][1],
83+
this.colognePhonetic.colognePhonetic(data[i][0]));
7384
}
7485
}
7586

7687
public void testExamples() {
77-
ColognePhonetic koellePhon = new ColognePhonetic();
7888
String[][] data = {{"Müller-Lüdenscheidt", "65752682"}, {"Breschnew", "17863"}, {"Wikipedia", "3412"}};
7989
for (int i = 0; i < data.length; i++) {
80-
assertEquals(data[i][1], koellePhon.colognePhonetic(data[i][0]));
90+
this.checkEncoding(data[i][1], data[i][0]);
8191
}
8292
}
8393

94+
public void testHyphen() {
95+
this.checkEncoding("174845214", "bergisch-gladbach");
96+
}
97+
8498
public void testIsCologneEquals() {
85-
ColognePhonetic koellePhon = new ColognePhonetic();
86-
assertFalse("Cologne-phonetic encodings should not be equal", koellePhon.isCologneEqual("Meyer", "Müller"));
87-
assertTrue("Cologne-phonetic encodings should be equal", koellePhon.isCologneEqual("Meyer", "Mayr"));
99+
Assert.assertFalse("Cologne-phonetic encodings should not be equal", this.colognePhonetic.isCologneEqual("Meyer", "Müller"));
100+
Assert.assertTrue("Cologne-phonetic encodings should be equal", this.colognePhonetic.isCologneEqual("Meyer", "Mayr"));
101+
}
102+
103+
public void testIsCologneEqualsPhpData() {
104+
String[][] data = {
105+
{"house", "house"},
106+
{"House", "house"},
107+
{"Haus", "house"},
108+
{"ganz", "Gans"},
109+
{"ganz", "Gänse"},
110+
{"Miyagi", "Miyako"}};
111+
for (int i = 0; i < data.length; i++) {
112+
this.colognePhonetic.isCologneEqual(data[i][1], data[i][0]);
113+
}
114+
}
115+
116+
/**
117+
* Test data from http://repo.magdev.de/src/Text_ColognePhonetic-0.2.2/test/Text_ColognePhoneticTest.php
118+
*/
119+
public void testPhpData() {
120+
String[][] data = {
121+
{"peter", "127"},
122+
{"pharma", "376"},
123+
{"bergisch-gladbach", "174845214"},
124+
{"mönchengladbach", "664645214"},
125+
// {"deutsch", "288"}, // Probably a bug
126+
{"deutz", "28"},
127+
// {"hamburg", "6174"},
128+
// {"hannover", "637"},
129+
// {"christstollen", "4788256"},
130+
{"Xanthippe", "48621"},
131+
{"Zacharias", "8478"},
132+
// {"Holzbau", "581"},
133+
// {"matsch", "688"},
134+
{"matz", "68"},
135+
{"Arbeitsamt", "071862"},
136+
{"Eberhard", "01772"},
137+
{"Eberhardt", "01772"},
138+
// {"heithabu", "21"},
139+
{"Müller-Lüdenscheidt", "65752682"},};
140+
for (int i = 0; i < data.length; i++) {
141+
this.checkEncoding(data[i][1], data[i][0]);
142+
}
88143
}
89144
}

0 commit comments

Comments
 (0)