View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.codec.language;
19  
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import org.apache.commons.codec.AbstractStringEncoderTest;
24  import org.apache.commons.codec.EncoderException;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests Caverphone2.
29   */
30  class Caverphone2Test extends AbstractStringEncoderTest<Caverphone2> {
31  
32      @Override
33      protected Caverphone2 createStringEncoder() {
34          return new Caverphone2();
35      }
36  
37      /**
38       * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
39       *
40       * AT11111111 words: add, aid, at, art, eat, earth, head, hit, hot, hold, hard, heart, it, out, old
41       *
42       * @throws EncoderException for some failure scenarios     */
43      @Test
44      void testCaverphoneRevisitedCommonCodeAT11111111() throws EncoderException {
45          // @formatter:off
46          checkEncodingVariations("AT11111111",
47              "add",
48              "aid",
49              "at",
50              "art",
51              "eat",
52              "earth",
53              "head",
54              "hit",
55              "hot",
56              "hold",
57              "hard",
58              "heart",
59              "it",
60              "out",
61              "old");
62          // @formatter:on
63      }
64  
65      /**
66       * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
67       *
68       * @throws EncoderException for some failure scenarios     */
69      @Test
70      void testCaverphoneRevisitedExamples() throws EncoderException {
71          checkEncodings(new String[][] {{"Stevenson", "STFNSN1111"}, {"Peter", "PTA1111111"}});
72      }
73  
74      /**
75       * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
76       *
77       * @throws EncoderException for some failure scenarios     */
78      @Test
79      void testCaverphoneRevisitedRandomNameKLN1111111() throws EncoderException {
80          // @formatter:off
81          checkEncodingVariations("KLN1111111",
82              "Cailean",
83              "Calan",
84              "Calen",
85              "Callahan",
86              "Callan",
87              "Callean",
88              "Carleen",
89              "Carlen",
90              "Carlene",
91              "Carlin",
92              "Carline",
93              "Carlyn",
94              "Carlynn",
95              "Carlynne",
96              "Charlean",
97              "Charleen",
98              "Charlene",
99              "Charline",
100             "Cherlyn",
101             "Chirlin",
102             "Clein",
103             "Cleon",
104             "Cline",
105             "Cohleen",
106             "Colan",
107             "Coleen",
108             "Colene",
109             "Colin",
110             "Colleen",
111             "Collen",
112             "Collin",
113             "Colline",
114             "Colon",
115             "Cullan",
116             "Cullen",
117             "Cullin",
118             "Gaelan",
119             "Galan",
120             "Galen",
121             "Garlan",
122             "Garlen",
123             "Gaulin",
124             "Gayleen",
125             "Gaylene",
126             "Giliane",
127             "Gillan",
128             "Gillian",
129             "Glen",
130             "Glenn",
131             "Glyn",
132             "Glynn",
133             "Gollin",
134             "Gorlin",
135             "Kalin",
136             "Karlan",
137             "Karleen",
138             "Karlen",
139             "Karlene",
140             "Karlin",
141             "Karlyn",
142             "Kaylyn",
143             "Keelin",
144             "Kellen",
145             "Kellene",
146             "Kellyann",
147             "Kellyn",
148             "Khalin",
149             "Kilan",
150             "Kilian",
151             "Killen",
152             "Killian",
153             "Killion",
154             "Klein",
155             "Kleon",
156             "Kline",
157             "Koerlin",
158             "Kylen",
159             "Kylynn",
160             "Quillan",
161             "Quillon",
162             "Qulllon",
163             "Xylon");
164         // @formatter:on
165     }
166 
167     /**
168      * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
169      *
170      * @throws EncoderException for some failure scenarios     */
171     @Test
172     void testCaverphoneRevisitedRandomNameTN11111111() throws EncoderException {
173         // @formatter:off
174         checkEncodingVariations("TN11111111",
175             "Dan",
176             "Dane",
177             "Dann",
178             "Darn",
179             "Daune",
180             "Dawn",
181             "Ddene",
182             "Dean",
183             "Deane",
184             "Deanne",
185             "DeeAnn",
186             "Deeann",
187             "Deeanne",
188             "Deeyn",
189             "Den",
190             "Dene",
191             "Denn",
192             "Deonne",
193             "Diahann",
194             "Dian",
195             "Diane",
196             "Diann",
197             "Dianne",
198             "Diannne",
199             "Dine",
200             "Dion",
201             "Dione",
202             "Dionne",
203             "Doane",
204             "Doehne",
205             "Don",
206             "Donn",
207             "Doone",
208             "Dorn",
209             "Down",
210             "Downe",
211             "Duane",
212             "Dun",
213             "Dunn",
214             "Duyne",
215             "Dyan",
216             "Dyane",
217             "Dyann",
218             "Dyanne",
219             "Dyun",
220             "Tan",
221             "Tann",
222             "Teahan",
223             "Ten",
224             "Tenn",
225             "Terhune",
226             "Thain",
227             "Thaine",
228             "Thane",
229             "Thanh",
230             "Thayne",
231             "Theone",
232             "Thin",
233             "Thorn",
234             "Thorne",
235             "Thun",
236             "Thynne",
237             "Tien",
238             "Tine",
239             "Tjon",
240             "Town",
241             "Towne",
242             "Turne",
243             "Tyne");
244         // @formatter:on
245     }
246 
247     /**
248      * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
249      *
250      * @throws EncoderException for some failure scenarios     */
251     @Test
252     void testCaverphoneRevisitedRandomNameTTA1111111() throws EncoderException {
253         // @formatter:off
254         checkEncodingVariations("TTA1111111",
255             "Darda",
256             "Datha",
257             "Dedie",
258             "Deedee",
259             "Deerdre",
260             "Deidre",
261             "Deirdre",
262             "Detta",
263             "Didi",
264             "Didier",
265             "Dido",
266             "Dierdre",
267             "Dieter",
268             "Dita",
269             "Ditter",
270             "Dodi",
271             "Dodie",
272             "Dody",
273             "Doherty",
274             "Dorthea",
275             "Dorthy",
276             "Doti",
277             "Dotti",
278             "Dottie",
279             "Dotty",
280             "Doty",
281             "Doughty",
282             "Douty",
283             "Dowdell",
284             "Duthie",
285             "Tada",
286             "Taddeo",
287             "Tadeo",
288             "Tadio",
289             "Tati",
290             "Teador",
291             "Tedda",
292             "Tedder",
293             "Teddi",
294             "Teddie",
295             "Teddy",
296             "Tedi",
297             "Tedie",
298             "Teeter",
299             "Teodoor",
300             "Teodor",
301             "Terti",
302             "Theda",
303             "Theodor",
304             "Theodore",
305             "Theta",
306             "Thilda",
307             "Thordia",
308             "Tilda",
309             "Tildi",
310             "Tildie",
311             "Tildy",
312             "Tita",
313             "Tito",
314             "Tjader",
315             "Toddie",
316             "Toddy",
317             "Torto",
318             "Tuddor",
319             "Tudor",
320             "Turtle",
321             "Tuttle",
322             "Tutto");
323         // @formatter:on
324     }
325 
326     /**
327      * See https://caversham.otago.ac.nz/files/working/ctp150804.pdf
328      *
329      * @throws EncoderException for some failure scenarios     */
330     @Test
331     void testCaverphoneRevisitedRandomWords() throws EncoderException {
332         checkEncodingVariations("RTA1111111", "rather", "ready", "writer");
333         checkEncoding("SSA1111111", "social");
334         checkEncodingVariations("APA1111111", "able", "appear");
335     }
336 
337     @Test
338     void testEndMb() throws EncoderException {
339         checkEncodings(new String[][] {{"mb", "M111111111"}, {"mbmb", "MPM1111111"}});
340     }
341 
342     // Caverphone Revisited
343     @Test
344     void testIsCaverphoneEquals() throws EncoderException {
345         final Caverphone2 caverphone = new Caverphone2();
346         assertFalse(caverphone.isEncodeEqual("Peter", "Stevenson"), "Caverphone encodings should not be equal");
347         assertTrue(caverphone.isEncodeEqual("Peter", "Peady"), "Caverphone encodings should be equal");
348     }
349 
350     @Test
351     void testSpecificationExamples() throws EncoderException {
352         checkEncodings(new String[][] {
353             {"Peter", "PTA1111111"},
354             {"ready", "RTA1111111"},
355             {"social", "SSA1111111"},
356             {"able", "APA1111111"},
357             {"Tedder", "TTA1111111"},
358             {"Karleen", "KLN1111111"},
359             {"Dyun", "TN11111111"}});
360     }
361 
362 }