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 Caverphone1.
29 */
30 class Caverphone1Test extends AbstractStringEncoderTest<Caverphone1> {
31
32 @Override
33 protected Caverphone1 createStringEncoder() {
34 return new Caverphone1();
35 }
36
37 /**
38 * Tests example adapted from version 2.0 https://caversham.otago.ac.nz/files/working/ctp150804.pdf
39 *
40 * AT1111 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 */
44 @Test
45 void testCaverphoneRevisitedCommonCodeAT1111() throws EncoderException {
46 // @formatter:off
47 checkEncodingVariations("AT1111",
48 "add",
49 "aid",
50 "at",
51 "art",
52 "eat",
53 "earth",
54 "head",
55 "hit",
56 "hot",
57 "hold",
58 "hard",
59 "heart",
60 "it",
61 "out",
62 "old");
63 // @formatter:on
64 }
65
66 @Test
67 void testEndMb() throws EncoderException {
68 checkEncodings(new String[][] {{"mb", "M11111"}, {"mbmb", "MPM111"}});
69 }
70
71 /**
72 * Tests some examples from version 2.0 https://caversham.otago.ac.nz/files/working/ctp150804.pdf
73 *
74 * @throws EncoderException for some failure scenarios.
75 */
76 @Test
77 void testIsCaverphoneEquals() throws EncoderException {
78 final Caverphone1 caverphone = new Caverphone1();
79 assertFalse(caverphone.isEncodeEqual("Peter", "Stevenson"), "Caverphone encodings should not be equal");
80 assertTrue(caverphone.isEncodeEqual("Peter", "Peady"), "Caverphone encodings should be equal");
81 }
82
83 /**
84 * Tests example from https://caversham.otago.ac.nz/files/working/ctp060902.pdf
85 *
86 * @throws EncoderException for some failure scenarios.
87 */
88 @Test
89 void testSpecificationV1Examples() throws EncoderException {
90 checkEncodings(new String[][] {{"David", "TFT111"}, {"Whittle", "WTL111"}});
91 }
92
93 /**
94 * Tests examples from https://en.wikipedia.org/wiki/Caverphone
95 *
96 * @throws EncoderException for some failure scenarios.
97 */
98 @Test
99 void testWikipediaExamples() throws EncoderException {
100 checkEncodings(new String[][] {{"Lee", "L11111"}, {"Thompson", "TMPSN1"}});
101 }
102
103 }