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 018package org.apache.commons.codec.language; 019 020import org.junit.Assert; 021 022import org.apache.commons.codec.EncoderException; 023import org.apache.commons.codec.StringEncoderAbstractTest; 024import org.junit.Test; 025 026/** 027 * Tests Caverphone1. 028 * 029 * @version $Id: Caverphone1Test.html 891688 2013-12-24 20:49:46Z ggregory $ 030 * @since 1.5 031 */ 032public class Caverphone1Test extends StringEncoderAbstractTest<Caverphone1> { 033 034 @Override 035 protected Caverphone1 createStringEncoder() { 036 return new Caverphone1(); 037 } 038 039 /** 040 * Tests example adapted from version 2.0 http://caversham.otago.ac.nz/files/working/ctp150804.pdf 041 * 042 * AT1111 words: add, aid, at, art, eat, earth, head, hit, hot, hold, hard, heart, it, out, old 043 * 044 * @throws EncoderException 045 */ 046 @Test 047 public void testCaverphoneRevisitedCommonCodeAT1111() throws EncoderException { 048 this.checkEncodingVariations("AT1111", new String[]{ 049 "add", 050 "aid", 051 "at", 052 "art", 053 "eat", 054 "earth", 055 "head", 056 "hit", 057 "hot", 058 "hold", 059 "hard", 060 "heart", 061 "it", 062 "out", 063 "old"}); 064 } 065 066 @Test 067 public void testEndMb() throws EncoderException { 068 final String[][] data = {{"mb", "M11111"}, {"mbmb", "MPM111"}}; 069 this.checkEncodings(data); 070 } 071 072 /** 073 * Tests some examples from version 2.0 http://caversham.otago.ac.nz/files/working/ctp150804.pdf 074 * 075 * @throws EncoderException 076 */ 077 @Test 078 public void testIsCaverphoneEquals() throws EncoderException { 079 final Caverphone1 caverphone = new Caverphone1(); 080 Assert.assertFalse("Caverphone encodings should not be equal", caverphone.isEncodeEqual("Peter", "Stevenson")); 081 Assert.assertTrue("Caverphone encodings should be equal", caverphone.isEncodeEqual("Peter", "Peady")); 082 } 083 084 /** 085 * Tests example from http://caversham.otago.ac.nz/files/working/ctp060902.pdf 086 * 087 * @throws EncoderException 088 */ 089 @Test 090 public void testSpecificationV1Examples() throws EncoderException { 091 final String[][] data = {{"David", "TFT111"}, {"Whittle", "WTL111"}}; 092 this.checkEncodings(data); 093 } 094 095 /** 096 * Tests examples from http://en.wikipedia.org/wiki/Caverphone 097 * 098 * @throws EncoderException 099 */ 100 @Test 101 public void testWikipediaExamples() throws EncoderException { 102 final String[][] data = {{"Lee", "L11111"}, {"Thompson", "TMPSN1"}}; 103 this.checkEncodings(data); 104 } 105 106}