|
17 | 17 |
|
18 | 18 | package org.apache.commons.codec.language; |
19 | 19 |
|
| 20 | +import junit.framework.Assert; |
| 21 | + |
20 | 22 | import org.apache.commons.codec.StringEncoder; |
21 | 23 | import org.apache.commons.codec.StringEncoderAbstractTest; |
22 | 24 |
|
23 | 25 | public class ColognePhoneticTest extends StringEncoderAbstractTest { |
24 | 26 |
|
| 27 | + private ColognePhonetic colognePhonetic = new ColognePhonetic(); |
| 28 | + |
25 | 29 | public ColognePhoneticTest(String name) { |
26 | 30 | super(name); |
27 | 31 | } |
28 | 32 |
|
| 33 | + public void checkEncoding(String expected, String source) { |
| 34 | + Assert.assertEquals("Source: " + source, expected, this.colognePhonetic.encode(source)); |
| 35 | + } |
| 36 | + |
29 | 37 | protected StringEncoder createEncoder() { |
30 | 38 | return new ColognePhonetic(); |
31 | 39 | } |
32 | 40 |
|
33 | 41 | public void testAabjoe() { |
34 | | - assertEquals("01", new ColognePhonetic().encode("Aabjoe")); |
| 42 | + this.checkEncoding("01", "Aabjoe"); |
35 | 43 | } |
36 | 44 |
|
37 | | - public void testBorderCases() { |
38 | | - ColognePhonetic koellePhon = new ColognePhonetic(); |
| 45 | + public void testAaclan() { |
| 46 | + this.checkEncoding("0856", "Aaclan"); |
| 47 | + } |
39 | 48 |
|
| 49 | + public void testEdgeCases() { |
40 | 50 | String[][] data = { |
41 | 51 | {"a", "0"}, |
42 | 52 | {"e", "0"}, |
@@ -69,21 +79,66 @@ public void testBorderCases() { |
69 | 79 | {"r", "7"}}; |
70 | 80 |
|
71 | 81 | 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])); |
73 | 84 | } |
74 | 85 | } |
75 | 86 |
|
76 | 87 | public void testExamples() { |
77 | | - ColognePhonetic koellePhon = new ColognePhonetic(); |
78 | 88 | String[][] data = {{"Müller-Lüdenscheidt", "65752682"}, {"Breschnew", "17863"}, {"Wikipedia", "3412"}}; |
79 | 89 | 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]); |
81 | 91 | } |
82 | 92 | } |
83 | 93 |
|
| 94 | + public void testHyphen() { |
| 95 | + this.checkEncoding("174845214", "bergisch-gladbach"); |
| 96 | + } |
| 97 | + |
84 | 98 | 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 | + } |
88 | 143 | } |
89 | 144 | } |
0 commit comments