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 Caverphone1. 029 * 030 * @version $Id: Caverphone1Test.html 889935 2013-12-11 05:05:13Z ggregory $ 031 * @since 1.5 032 */ 033 public class Caverphone1Test extends StringEncoderAbstractTest { 034 035 @Override 036 protected StringEncoder createStringEncoder() { 037 return new Caverphone1(); 038 } 039 040 /** 041 * Tests example adapted from version 2.0 http://caversham.otago.ac.nz/files/working/ctp150804.pdf 042 * 043 * AT1111 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 testCaverphoneRevisitedCommonCodeAT1111() throws EncoderException { 049 this.checkEncodingVariations("AT1111", 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 @Test 068 public void testEndMb() throws EncoderException { 069 String[][] data = {{"mb", "M11111"}, {"mbmb", "MPM111"}}; 070 this.checkEncodings(data); 071 } 072 073 /** 074 * Tests some examples from version 2.0 http://caversham.otago.ac.nz/files/working/ctp150804.pdf 075 * 076 * @throws EncoderException 077 */ 078 @Test 079 public void testIsCaverphoneEquals() throws EncoderException { 080 Caverphone1 caverphone = new Caverphone1(); 081 Assert.assertFalse("Caverphone encodings should not be equal", caverphone.isEncodeEqual("Peter", "Stevenson")); 082 Assert.assertTrue("Caverphone encodings should be equal", caverphone.isEncodeEqual("Peter", "Peady")); 083 } 084 085 /** 086 * Tests example from http://caversham.otago.ac.nz/files/working/ctp060902.pdf 087 * 088 * @throws EncoderException 089 */ 090 @Test 091 public void testSpecificationV1Examples() throws EncoderException { 092 String[][] data = {{"David", "TFT111"}, {"Whittle", "WTL111"}}; 093 this.checkEncodings(data); 094 } 095 096 /** 097 * Tests examples from http://en.wikipedia.org/wiki/Caverphone 098 * 099 * @throws EncoderException 100 */ 101 @Test 102 public void testWikipediaExamples() throws EncoderException { 103 String[][] data = {{"Lee", "L11111"}, {"Thompson", "TMPSN1"}}; 104 this.checkEncodings(data); 105 } 106 107 }