1 16 17 package org.apache.commons.codec.language; 18 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 import org.apache.commons.codec.EncoderException; 22 import org.apache.commons.codec.StringEncoder; 23 import org.apache.commons.codec.StringEncoderAbstractTest; 24 25 31 public class RefinedSoundexTest extends StringEncoderAbstractTest { 32 33 public static Test suite() { 34 return (new TestSuite(RefinedSoundexTest.class)); 35 } 36 37 private RefinedSoundex encoder = null; 38 39 public RefinedSoundexTest(String name) { 40 super(name); 41 } 42 43 46 private RefinedSoundex getEncoder() { 47 return this.encoder; 48 } 49 50 protected StringEncoder makeEncoder() { 51 return new RefinedSoundex(); 52 } 53 54 58 private void setEncoder(RefinedSoundex encoder) { 59 this.encoder = encoder; 60 } 61 62 public void setUp() throws Exception { 63 super.setUp(); 64 this.setEncoder(new RefinedSoundex()); 65 } 66 67 public void tearDown() throws Exception { 68 super.tearDown(); 69 this.setEncoder(null); 70 } 71 72 public void testDifference() throws EncoderException { 73 assertEquals(0, this.getEncoder().difference(null, null)); 75 assertEquals(0, this.getEncoder().difference("", "")); 76 assertEquals(0, this.getEncoder().difference(" ", " ")); 77 assertEquals(6, this.getEncoder().difference("Smith", "Smythe")); 79 assertEquals(3, this.getEncoder().difference("Ann", "Andrew")); 80 assertEquals(1, this.getEncoder().difference("Margaret", "Andrew")); 81 assertEquals(1, this.getEncoder().difference("Janet", "Margaret")); 82 assertEquals(5, this.getEncoder().difference("Green", "Greene")); 85 assertEquals(1, this.getEncoder().difference("Blotchet-Halls", "Greene")); 86 assertEquals(6, this.getEncoder().difference("Smith", "Smythe")); 89 assertEquals(8, this.getEncoder().difference("Smithers", "Smythers")); 90 assertEquals(5, this.getEncoder().difference("Anothers", "Brothers")); 91 } 92 93 public void testEncode() { 94 assertEquals("T6036084", this.getEncoder().encode("testing")); 95 assertEquals("T6036084", this.getEncoder().encode("TESTING")); 96 assertEquals("T60", this.getEncoder().encode("The")); 97 assertEquals("Q503", this.getEncoder().encode("quick")); 98 assertEquals("B1908", this.getEncoder().encode("brown")); 99 assertEquals("F205", this.getEncoder().encode("fox")); 100 assertEquals("J408106", this.getEncoder().encode("jumped")); 101 assertEquals("O0209", this.getEncoder().encode("over")); 102 assertEquals("T60", this.getEncoder().encode("the")); 103 assertEquals("L7050", this.getEncoder().encode("lazy")); 104 assertEquals("D6043", this.getEncoder().encode("dogs")); 105 } 106 107 public void testGetMappingCodeNonLetter() { 108 char code = this.getEncoder().getMappingCode('#'); 109 assertEquals("Code does not equals zero", 0, code); 110 } 111 } | Popular Tags |