001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.codec.language; 019 020 import junit.framework.Assert; 021 022 import org.apache.commons.codec.EncoderException; 023 import org.apache.commons.codec.StringEncoder; 024 import org.apache.commons.codec.StringEncoderAbstractTest; 025 import org.junit.Test; 026 027 /** 028 * Tests Caverphone2. 029 * 030 * @version $Id: Caverphone2Test.html 889935 2013-12-11 05:05:13Z ggregory $ 031 * @since 1.5 032 */ 033 public class Caverphone2Test extends StringEncoderAbstractTest { 034 035 @Override 036 protected StringEncoder createStringEncoder() { 037 return new Caverphone2(); 038 } 039 040 /** 041 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 042 * 043 * AT11111111 words: add, aid, at, art, eat, earth, head, hit, hot, hold, hard, heart, it, out, old 044 * 045 * @throws EncoderException 046 */ 047 @Test 048 public void testCaverphoneRevisitedCommonCodeAT11111111() throws EncoderException { 049 this.checkEncodingVariations("AT11111111", new String[]{ 050 "add", 051 "aid", 052 "at", 053 "art", 054 "eat", 055 "earth", 056 "head", 057 "hit", 058 "hot", 059 "hold", 060 "hard", 061 "heart", 062 "it", 063 "out", 064 "old"}); 065 } 066 067 /** 068 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 069 * 070 * @throws EncoderException 071 */ 072 @Test 073 public void testCaverphoneRevisitedExamples() throws EncoderException { 074 String[][] data = {{"Stevenson", "STFNSN1111"}, {"Peter", "PTA1111111"}}; 075 this.checkEncodings(data); 076 } 077 078 /** 079 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 080 * 081 * @throws EncoderException 082 */ 083 @Test 084 public void testCaverphoneRevisitedRandomNameKLN1111111() throws EncoderException { 085 this.checkEncodingVariations("KLN1111111", new String[]{ 086 "Cailean", 087 "Calan", 088 "Calen", 089 "Callahan", 090 "Callan", 091 "Callean", 092 "Carleen", 093 "Carlen", 094 "Carlene", 095 "Carlin", 096 "Carline", 097 "Carlyn", 098 "Carlynn", 099 "Carlynne", 100 "Charlean", 101 "Charleen", 102 "Charlene", 103 "Charline", 104 "Cherlyn", 105 "Chirlin", 106 "Clein", 107 "Cleon", 108 "Cline", 109 "Cohleen", 110 "Colan", 111 "Coleen", 112 "Colene", 113 "Colin", 114 "Colleen", 115 "Collen", 116 "Collin", 117 "Colline", 118 "Colon", 119 "Cullan", 120 "Cullen", 121 "Cullin", 122 "Gaelan", 123 "Galan", 124 "Galen", 125 "Garlan", 126 "Garlen", 127 "Gaulin", 128 "Gayleen", 129 "Gaylene", 130 "Giliane", 131 "Gillan", 132 "Gillian", 133 "Glen", 134 "Glenn", 135 "Glyn", 136 "Glynn", 137 "Gollin", 138 "Gorlin", 139 "Kalin", 140 "Karlan", 141 "Karleen", 142 "Karlen", 143 "Karlene", 144 "Karlin", 145 "Karlyn", 146 "Kaylyn", 147 "Keelin", 148 "Kellen", 149 "Kellene", 150 "Kellyann", 151 "Kellyn", 152 "Khalin", 153 "Kilan", 154 "Kilian", 155 "Killen", 156 "Killian", 157 "Killion", 158 "Klein", 159 "Kleon", 160 "Kline", 161 "Koerlin", 162 "Kylen", 163 "Kylynn", 164 "Quillan", 165 "Quillon", 166 "Qulllon", 167 "Xylon"}); 168 } 169 170 /** 171 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 172 * 173 * @throws EncoderException 174 */ 175 @Test 176 public void testCaverphoneRevisitedRandomNameTN11111111() throws EncoderException { 177 this.checkEncodingVariations("TN11111111", new String[]{ 178 "Dan", 179 "Dane", 180 "Dann", 181 "Darn", 182 "Daune", 183 "Dawn", 184 "Ddene", 185 "Dean", 186 "Deane", 187 "Deanne", 188 "DeeAnn", 189 "Deeann", 190 "Deeanne", 191 "Deeyn", 192 "Den", 193 "Dene", 194 "Denn", 195 "Deonne", 196 "Diahann", 197 "Dian", 198 "Diane", 199 "Diann", 200 "Dianne", 201 "Diannne", 202 "Dine", 203 "Dion", 204 "Dione", 205 "Dionne", 206 "Doane", 207 "Doehne", 208 "Don", 209 "Donn", 210 "Doone", 211 "Dorn", 212 "Down", 213 "Downe", 214 "Duane", 215 "Dun", 216 "Dunn", 217 "Duyne", 218 "Dyan", 219 "Dyane", 220 "Dyann", 221 "Dyanne", 222 "Dyun", 223 "Tan", 224 "Tann", 225 "Teahan", 226 "Ten", 227 "Tenn", 228 "Terhune", 229 "Thain", 230 "Thaine", 231 "Thane", 232 "Thanh", 233 "Thayne", 234 "Theone", 235 "Thin", 236 "Thorn", 237 "Thorne", 238 "Thun", 239 "Thynne", 240 "Tien", 241 "Tine", 242 "Tjon", 243 "Town", 244 "Towne", 245 "Turne", 246 "Tyne"}); 247 } 248 249 /** 250 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 251 * 252 * @throws EncoderException 253 */ 254 @Test 255 public void testCaverphoneRevisitedRandomNameTTA1111111() throws EncoderException { 256 this.checkEncodingVariations("TTA1111111", new String[]{ 257 "Darda", 258 "Datha", 259 "Dedie", 260 "Deedee", 261 "Deerdre", 262 "Deidre", 263 "Deirdre", 264 "Detta", 265 "Didi", 266 "Didier", 267 "Dido", 268 "Dierdre", 269 "Dieter", 270 "Dita", 271 "Ditter", 272 "Dodi", 273 "Dodie", 274 "Dody", 275 "Doherty", 276 "Dorthea", 277 "Dorthy", 278 "Doti", 279 "Dotti", 280 "Dottie", 281 "Dotty", 282 "Doty", 283 "Doughty", 284 "Douty", 285 "Dowdell", 286 "Duthie", 287 "Tada", 288 "Taddeo", 289 "Tadeo", 290 "Tadio", 291 "Tati", 292 "Teador", 293 "Tedda", 294 "Tedder", 295 "Teddi", 296 "Teddie", 297 "Teddy", 298 "Tedi", 299 "Tedie", 300 "Teeter", 301 "Teodoor", 302 "Teodor", 303 "Terti", 304 "Theda", 305 "Theodor", 306 "Theodore", 307 "Theta", 308 "Thilda", 309 "Thordia", 310 "Tilda", 311 "Tildi", 312 "Tildie", 313 "Tildy", 314 "Tita", 315 "Tito", 316 "Tjader", 317 "Toddie", 318 "Toddy", 319 "Torto", 320 "Tuddor", 321 "Tudor", 322 "Turtle", 323 "Tuttle", 324 "Tutto"}); 325 } 326 327 /** 328 * See http://caversham.otago.ac.nz/files/working/ctp150804.pdf 329 * 330 * @throws EncoderException 331 */ 332 @Test 333 public void testCaverphoneRevisitedRandomWords() throws EncoderException { 334 this.checkEncodingVariations("RTA1111111", new String[]{"rather", "ready", "writer"}); 335 this.checkEncoding("SSA1111111", "social"); 336 this.checkEncodingVariations("APA1111111", new String[]{"able", "appear"}); 337 } 338 339 @Test 340 public void testEndMb() throws EncoderException { 341 String[][] data = {{"mb", "M111111111"}, {"mbmb", "MPM1111111"}}; 342 this.checkEncodings(data); 343 } 344 345 // Caverphone Revisited 346 @Test 347 public void testIsCaverphoneEquals() throws EncoderException { 348 Caverphone2 caverphone = new Caverphone2(); 349 Assert.assertFalse("Caverphone encodings should not be equal", caverphone.isEncodeEqual("Peter", "Stevenson")); 350 Assert.assertTrue("Caverphone encodings should be equal", caverphone.isEncodeEqual("Peter", "Peady")); 351 } 352 353 @Test 354 public void testSpecificationExamples() throws EncoderException { 355 String[][] data = { 356 {"Peter", "PTA1111111"}, 357 {"ready", "RTA1111111"}, 358 {"social", "SSA1111111"}, 359 {"able", "APA1111111"}, 360 {"Tedder", "TTA1111111"}, 361 {"Karleen", "KLN1111111"}, 362 {"Dyun", "TN11111111"}}; 363 this.checkEncodings(data); 364 } 365 366 }