T9
T9 Trie Word Completion Algorithm
t9/trie/TrieBuilderTest.java
Go to the documentation of this file.
00001 
00009 package t9.trie;
00010 
00011 import static org.junit.Assert.assertTrue;
00012 import static org.junit.Assert.fail;
00013 
00014 import java.util.TreeSet;
00015 
00016 import org.junit.Test;
00017 
00018 
00025 public class TrieBuilderTest {
00026     
00027     final static Pair[] A_words = new Pair[] {
00028         new Pair("a",5),
00029         new Pair("abandon",2201),
00030         new Pair("ability",783),
00031         new Pair("able",386),
00032         new Pair("abortion",1983),
00033         new Pair("about",179),
00034         new Pair("about",46),
00035         new Pair("above",1599),
00036         new Pair("above",896),
00037         new Pair("abroad",3392),
00038         new Pair("absence",2547),
00039         new Pair("absolute",3192),
00040         new Pair("absolutely",1152),
00041         new Pair("absorb",3145),
00042         new Pair("abstract",4045),
00043         new Pair("abuse",1548),
00044         new Pair("abuse",3778),
00045         new Pair("academic",1473),
00046         new Pair("accelerate",4977),
00047         new Pair("accent",4181),
00048         new Pair("accept",767),
00049         new Pair("acceptable",3445),
00050         new Pair("acceptance",3473),
00051         new Pair("access",1117),
00052         new Pair("access",4416),
00053         new Pair("accessible",4423),
00054         new Pair("accident",1720),
00055         new Pair("accommodate",3753),
00056         new Pair("accompany",2460),
00057         new Pair("accomplish",2366),
00058         new Pair("accomplishment",4351),
00059         new Pair("according",479),
00060         new Pair("account",1075),
00061         new Pair("account",1923),
00062         new Pair("accountability",4855),
00063         new Pair("accounting",3960),
00064         new Pair("accuracy",4111),
00065         new Pair("accurate",2754),
00066         new Pair("accurately",4950),
00067         new Pair("accusation",4924),
00068         new Pair("accuse",2041),
00069         new Pair("achieve",1155),
00070         new Pair("achievement",2038),
00071         new Pair("acid",3265),
00072         new Pair("acknowledge",1664),
00073         new Pair("acquire",2079),
00074         new Pair("acquisition",3893)
00075     };
00076     
00080     @Test
00081     public void testTrieBuilder() {
00082         TreeSet<Pair> words = new TreeSet<Pair>();
00083         for (Pair word : A_words) {
00084             words.add( word );
00085         }
00086         TrieBuilder builder = new TrieBuilder();
00087         TrieNode A_root = builder.buildTrie(words);
00088         TreeSet<Pair> sortedList = builder.listTrie( A_root );
00089         assertTrue(words.equals(sortedList));
00090     }
00091 
00095     @Test
00096     public void testAddLetter() {
00097         TrieBuilder builder = new TrieBuilder();
00098         String repeats = "aaaahhh";
00099         Pair wordPair = new Pair(repeats, 42 );
00100         TrieNode root = builder.addWord( null, wordPair );
00101         TreeSet<Pair> wordList = builder.listTrie(root);
00102         if (wordList != null && wordList.size() == 1) {
00103             Pair elem = wordList.first();
00104             if (elem != null) {
00105                 String testWord = elem.word;
00106                 assertTrue(repeats.equals(testWord));
00107             }
00108             else {
00109                 fail("The word in the tree did not match");
00110             }
00111         }
00112         else {
00113             fail("The word list was either null or the wrong length");
00114         }
00115     }  // testAddLetter
00116     
00117 }
 All Classes Namespaces Files Functions Variables