Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 17849 invoked from network); 7 Nov 2003 22:37:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 7 Nov 2003 22:37:31 -0000 Received: (qmail 91975 invoked by uid 500); 7 Nov 2003 22:37:14 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 91913 invoked by uid 500); 7 Nov 2003 22:37:14 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 91900 invoked by uid 500); 7 Nov 2003 22:37:14 -0000 Received: (qmail 91896 invoked from network); 7 Nov 2003 22:37:14 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 7 Nov 2003 22:37:14 -0000 Received: (qmail 17812 invoked by uid 1643); 7 Nov 2003 22:37:26 -0000 Date: 7 Nov 2003 22:37:26 -0000 Message-ID: <20031107223726.17811.qmail@minotaur.apache.org> From: ggregory@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/codec/src/test/org/apache/commons/codec/language MetaphoneTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N ggregory 2003/11/07 14:37:26 Modified: codec/src/test/org/apache/commons/codec/language MetaphoneTest.java Log: Improve code coverge as reported by clover from ~61% to ~80% with more test data. Revision Changes Path 1.5 +391 -80 jakarta-commons/codec/src/test/org/apache/commons/codec/language/MetaphoneTest.java Index: MetaphoneTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/codec/src/test/org/apache/commons/codec/language/MetaphoneTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MetaphoneTest.java 5 Oct 2003 21:45:49 -0000 1.4 +++ MetaphoneTest.java 7 Nov 2003 22:37:26 -0000 1.5 @@ -2,58 +2,45 @@ * ==================================================================== * * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001-2003 The Apache Software Foundation. All rights - * reserved. - * + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights reserved. + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgement: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgement may appear in the software itself, - * if and wherever such third-party acknowledgements normally appear. - * - * 4. The names "Apache", "The Jakarta Project", "Commons", and "Apache Software - * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache" nor may "Apache" appear in their name without prior - * written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * modification, are permitted provided that the following conditions are met: 1. + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. The end-user documentation + * included with the redistribution, if any, must include the following + * acknowledgement: "This product includes software developed by the Apache + * Software Foundation (http://www.apache.org/)." Alternately, this + * acknowledgement may appear in the software itself, if and wherever such + * third-party acknowledgements normally appear. 4. The names "Apache", "The + * Jakarta Project", "Commons", and "Apache Software Foundation" must not be + * used to endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. 5. Products derived from this software may not be called + * "Apache", "Apache" nor may "Apache" appear in their name without prior + * written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - */ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation. For more information on the + * Apache Software Foundation, please see . + * + */ package org.apache.commons.codec.language; @@ -66,54 +53,378 @@ /** * @version $Revision$ $Date$ * @author Rodney Waldhoff + * @author Gary Gregory */ public class MetaphoneTest extends StringEncoderAbstractTest { + public static Test suite() { + return (new TestSuite(MetaphoneTest.class)); + } + + private Metaphone metaphone = null; + public MetaphoneTest(String name) { super(name); } - public static Test suite() { - return (new TestSuite(MetaphoneTest.class)); + public void assertIsMetaphoneEqual(String source, String[] matches) { + // match source to all matches + for (int i = 0; i < matches.length; i++) { + assertTrue(this.getMetaphone().isMetaphoneEqual(source, matches[i])); + } + // match to each other + for (int i = 0; i < matches.length; i++) { + for (int j = 0; j < matches.length; j++) { + assertTrue(this.getMetaphone().isMetaphoneEqual(matches[i], matches[j])); + } + } + } + + public void assertMetaphoneEqual(String[][] pairs) { + this.validateFixture(pairs); + for (int i = 0; i < pairs.length; i++) { + String name0 = pairs[i][0]; + String name1 = pairs[i][1]; + String failMsg = "Expected match between " + name0 + " and " + name1; + assertTrue(failMsg, this.getMetaphone().isMetaphoneEqual(name0, name1)); + assertTrue(failMsg, this.getMetaphone().isMetaphoneEqual(name1, name0)); + } + } + /** + * @return Returns the metaphone. + */ + private Metaphone getMetaphone() { + return this.metaphone; + } + + protected StringEncoder makeEncoder() { + return new Metaphone(); } - public void setUp() throws Exception { + /** + * @param metaphone + * The metaphone to set. + */ + private void setMetaphone(Metaphone metaphone) { + this.metaphone = metaphone; + } + + public void setUp() throws Exception { super.setUp(); - _metaphone = new Metaphone(); + this.setMetaphone(new Metaphone()); } public void tearDown() throws Exception { super.tearDown(); - _metaphone = null; + this.setMetaphone(null); } - protected StringEncoder makeEncoder() { - return new Metaphone(); + public void testIsMetaphoneEqual1() { + this.assertMetaphoneEqual(new String[][] { { "Case", "case" }, { + "CASE", "Case" }, { + "caSe", "cAsE" }, { + "quick", "cookie" } + }); + } + + /** + * Matches computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqual2() { + this.assertMetaphoneEqual(new String[][] { { "Lawrence", "Lorenza" }, { + "Gary", "Cahra" }, }); + } + + /** + * Initial AE case. + * + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualAero() { + this.assertIsMetaphoneEqual("Aero", new String[] { "Eure" }); + } + + /** + * Initial WH case. + * + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualWhite() { + this.assertIsMetaphoneEqual( + "White", + new String[] { "Wade", "Wait", "Waite", "Wat", "Whit", "Wiatt", "Wit", "Wittie", "Witty", "Wood", "Woodie", "Woody" }); + } + + /** + * Initial A, not followed by an E case. + * + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualAlbert() { + this.assertIsMetaphoneEqual("Albert", new String[] { "Ailbert", "Alberik", "Albert", "Alberto", "Albrecht" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualGary() { + this.assertIsMetaphoneEqual( + "Gary", + new String[] { + "Cahra", + "Cara", + "Carey", + "Cari", + "Caria", + "Carie", + "Caro", + "Carree", + "Carri", + "Carrie", + "Carry", + "Cary", + "Cora", + "Corey", + "Cori", + "Corie", + "Correy", + "Corri", + "Corrie", + "Corry", + "Cory", + "Gray", + "Kara", + "Kare", + "Karee", + "Kari", + "Karia", + "Karie", + "Karrah", + "Karrie", + "Karry", + "Kary", + "Keri", + "Kerri", + "Kerrie", + "Kerry", + "Kira", + "Kiri", + "Kora", + "Kore", + "Kori", + "Korie", + "Korrie", + "Korry" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualJohn() { + this.assertIsMetaphoneEqual( + "John", + new String[] { + "Gena", + "Gene", + "Genia", + "Genna", + "Genni", + "Gennie", + "Genny", + "Giana", + "Gianna", + "Gina", + "Ginni", + "Ginnie", + "Ginny", + "Jaine", + "Jan", + "Jana", + "Jane", + "Janey", + "Jania", + "Janie", + "Janna", + "Jany", + "Jayne", + "Jean", + "Jeana", + "Jeane", + "Jeanie", + "Jeanna", + "Jeanne", + "Jeannie", + "Jen", + "Jena", + "Jeni", + "Jenn", + "Jenna", + "Jennee", + "Jenni", + "Jennie", + "Jenny", + "Jinny", + "Jo Ann", + "Jo-Ann", + "Jo-Anne", + "Joan", + "Joana", + "Joane", + "Joanie", + "Joann", + "Joanna", + "Joanne", + "Joeann", + "Johna", + "Johnna", + "Joni", + "Jonie", + "Juana", + "June", + "Junia", + "Junie" }); + } + + /** + * Initial KN case. + * + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualKnight() { + this.assertIsMetaphoneEqual( + "Knight", + new String[] { + "Hynda", + "Nada", + "Nadia", + "Nady", + "Nat", + "Nata", + "Natty", + "Neda", + "Nedda", + "Nedi", + "Netta", + "Netti", + "Nettie", + "Netty", + "Nita", + "Nydia" }); + } + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualMary() { + this.assertIsMetaphoneEqual( + "Mary", + new String[] { + "Mair", + "Maire", + "Mara", + "Mareah", + "Mari", + "Maria", + "Marie", + "Mary", + "Maura", + "Maure", + "Meara", + "Merrie", + "Merry", + "Mira", + "Moira", + "Mora", + "Moria", + "Moyra", + "Muire", + "Myra", + "Myrah" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualParis() { + this.assertIsMetaphoneEqual("Paris", new String[] { "Pearcy", "Perris", "Piercy", "Pierz", "Pryse" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualPeter() { + this.assertIsMetaphoneEqual( + "Peter", + new String[] { "Peadar", "Peder", "Pedro", "Peter", "Petr", "Peyter", "Pieter", "Pietro", "Piotr" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualRay() { + this.assertIsMetaphoneEqual("Ray", new String[] { "Ray", "Rey", "Roi", "Roy", "Ruy" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualSusan() { + this.assertIsMetaphoneEqual( + "Susan", + new String[] { + "Siusan", + "Sosanna", + "Susan", + "Susana", + "Susann", + "Susanna", + "Susannah", + "Susanne", + "Suzann", + "Suzanna", + "Suzanne", + "Zuzana" }); + } + + /** + * Initial WR case. + * + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualWright() { + this.assertIsMetaphoneEqual("Wright", new String[] { "Rota", "Rudd", "Ryde" }); + } + + /** + * Match data computed from http://www.lanw.com/java/phonetic/default.htm + */ + public void testIsMetaphoneEqualXalan() { + this.assertIsMetaphoneEqual( + "Xalan", + new String[] { "Celene", "Celina", "Celine", "Selena", "Selene", "Selina", "Seline", "Suellen", "Xylina" }); } - - // ------------------------------------------------------------------------ public void testMetaphone() { - assertEquals("TSTN",_metaphone.metaphone("testing")); - assertEquals("0",_metaphone.metaphone("The")); - assertEquals("KK",_metaphone.metaphone("quick")); - assertEquals("BRN",_metaphone.metaphone("brown")); - assertEquals("FKS",_metaphone.metaphone("fox")); - assertEquals("JMPT",_metaphone.metaphone("jumped")); - assertEquals("OFR",_metaphone.metaphone("over")); - assertEquals("0",_metaphone.metaphone("the")); - assertEquals("LS",_metaphone.metaphone("lazy")); - assertEquals("TKS",_metaphone.metaphone("dogs")); - } - - public void testIsMetaphoneEqual() { - assertTrue(_metaphone.isMetaphoneEqual("Case","case")); - assertTrue(_metaphone.isMetaphoneEqual("CASE","Case")); - assertTrue(_metaphone.isMetaphoneEqual("caSe","cAsE")); - - assertTrue(_metaphone.isMetaphoneEqual("cookie","quick")); - assertTrue(_metaphone.isMetaphoneEqual("quick","cookie")); + assertEquals("TSTN", this.getMetaphone().metaphone("testing")); + assertEquals("0", this.getMetaphone().metaphone("The")); + assertEquals("KK", this.getMetaphone().metaphone("quick")); + assertEquals("BRN", this.getMetaphone().metaphone("brown")); + assertEquals("FKS", this.getMetaphone().metaphone("fox")); + assertEquals("JMPT", this.getMetaphone().metaphone("jumped")); + assertEquals("OFR", this.getMetaphone().metaphone("over")); + assertEquals("0", this.getMetaphone().metaphone("the")); + assertEquals("LS", this.getMetaphone().metaphone("lazy")); + assertEquals("TKS", this.getMetaphone().metaphone("dogs")); + } + + public void validateFixture(String[][] pairs) { + if (pairs.length == 0) { + fail("Test fixture is empty"); + } + for (int i = 0; i < pairs.length; i++) { + if (pairs[i].length != 2) { + fail("Error in test fixture in the data array at index " + i); + } + } } - private Metaphone _metaphone = null; } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org