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 checkEncodingVariations("AT1111", new String[]{
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 }
63
64 @Test
65 void testEndMb() throws EncoderException {
66 final String[][] data = {{"mb", "M11111"}, {"mbmb", "MPM111"}};
67 checkEncodings(data);
68 }
69
70 /**
71 * Tests some examples from version 2.0 https://caversham.otago.ac.nz/files/working/ctp150804.pdf
72 *
73 * @throws EncoderException for some failure scenarios.
74 */
75 @Test
76 void testIsCaverphoneEquals() throws EncoderException {
77 final Caverphone1 caverphone = new Caverphone1();
78 assertFalse(caverphone.isEncodeEqual("Peter", "Stevenson"), "Caverphone encodings should not be equal");
79 assertTrue(caverphone.isEncodeEqual("Peter", "Peady"), "Caverphone encodings should be equal");
80 }
81
82 /**
83 * Tests example from https://caversham.otago.ac.nz/files/working/ctp060902.pdf
84 *
85 * @throws EncoderException for some failure scenarios.
86 */
87 @Test
88 void testSpecificationV1Examples() throws EncoderException {
89 final String[][] data = {{"David", "TFT111"}, {"Whittle", "WTL111"}};
90 checkEncodings(data);
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 final String[][] data = {{"Lee", "L11111"}, {"Thompson", "TMPSN1"}};
101 checkEncodings(data);
102 }
103
104 }