001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.codec.language;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021: import org.apache.commons.codec.EncoderException;
022: import org.apache.commons.codec.StringEncoder;
023: import org.apache.commons.codec.StringEncoderAbstractTest;
024:
025: /**
026: * Tests RefinedSoundex.
027: *
028: * @version $Id: RefinedSoundexTest.java,v 1.11 2004/05/24 00:17:24 ggregory Exp $
029: * @author Apache Software Foundation
030: */
031: public class RefinedSoundexTest extends StringEncoderAbstractTest {
032:
033: public static Test suite() {
034: return (new TestSuite(RefinedSoundexTest.class));
035: }
036:
037: private RefinedSoundex encoder = null;
038:
039: public RefinedSoundexTest(String name) {
040: super (name);
041: }
042:
043: /**
044: * @return Returns the encoder.
045: */
046: private RefinedSoundex getEncoder() {
047: return this .encoder;
048: }
049:
050: protected StringEncoder makeEncoder() {
051: return new RefinedSoundex();
052: }
053:
054: /**
055: * @param encoder
056: * The encoder to set.
057: */
058: private void setEncoder(RefinedSoundex encoder) {
059: this .encoder = encoder;
060: }
061:
062: public void setUp() throws Exception {
063: super .setUp();
064: this .setEncoder(new RefinedSoundex());
065: }
066:
067: public void tearDown() throws Exception {
068: super .tearDown();
069: this .setEncoder(null);
070: }
071:
072: public void testDifference() throws EncoderException {
073: // Edge cases
074: assertEquals(0, this .getEncoder().difference(null, null));
075: assertEquals(0, this .getEncoder().difference("", ""));
076: assertEquals(0, this .getEncoder().difference(" ", " "));
077: // Normal cases
078: assertEquals(6, this .getEncoder().difference("Smith", "Smythe"));
079: assertEquals(3, this .getEncoder().difference("Ann", "Andrew"));
080: assertEquals(1, this .getEncoder().difference("Margaret",
081: "Andrew"));
082: assertEquals(1, this .getEncoder().difference("Janet",
083: "Margaret"));
084: // Examples from
085: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp
086: assertEquals(5, this .getEncoder().difference("Green", "Greene"));
087: assertEquals(1, this .getEncoder().difference("Blotchet-Halls",
088: "Greene"));
089: // Examples from
090: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_3o6w.asp
091: assertEquals(6, this .getEncoder().difference("Smith", "Smythe"));
092: assertEquals(8, this .getEncoder().difference("Smithers",
093: "Smythers"));
094: assertEquals(5, this .getEncoder().difference("Anothers",
095: "Brothers"));
096: }
097:
098: public void testEncode() {
099: assertEquals("T6036084", this .getEncoder().encode("testing"));
100: assertEquals("T6036084", this .getEncoder().encode("TESTING"));
101: assertEquals("T60", this .getEncoder().encode("The"));
102: assertEquals("Q503", this .getEncoder().encode("quick"));
103: assertEquals("B1908", this .getEncoder().encode("brown"));
104: assertEquals("F205", this .getEncoder().encode("fox"));
105: assertEquals("J408106", this .getEncoder().encode("jumped"));
106: assertEquals("O0209", this .getEncoder().encode("over"));
107: assertEquals("T60", this .getEncoder().encode("the"));
108: assertEquals("L7050", this .getEncoder().encode("lazy"));
109: assertEquals("D6043", this .getEncoder().encode("dogs"));
110: }
111:
112: public void testGetMappingCodeNonLetter() {
113: char code = this .getEncoder().getMappingCode('#');
114: assertEquals("Code does not equals zero", 0, code);
115: }
116: }
|