import java.io.IOException; public class Driver { public static void main(String[] args){ PhonewordLister testLister = null; PrefixTree testTree = null; //first, see if the tree works as expected testTree = new PrefixTree(); testTree.addString("today"); testTree.addString("happy"); testTree.addString("hippo"); testTree.addString("lazed"); if (testTree.contains("today") && testTree.contains("happy") && testTree.contains("hippo") && testTree.contains("lazed") && !testTree.contains("pinot")) System.out.println ("Tree is being constructed correctly through addString()."); else System.out.println ("Tree is *NOT* being constructed correctly through addString()."); //now try to construct lister and get its tree try{ testLister = new PhonewordLister("sgb-words.txt"); } catch(IOException e) {System.out.println(e.getMessage());} catch(Exception e){System.out.println("Wrong IO exception type.");} testTree = testLister.getTree(); //test size if (testTree.getSize() == 5757) System.out.println("Size of tree is correct"); else System.out.println("Size of tree is *NOT* correct" + testTree.getSize()); //test if it's right if (testTree.contains("today") && testTree.contains("happy") && testTree.contains("jazzy") && testTree.contains("lazed") && !testTree.contains("pinot")) System.out.println ("Tree is being constructed correctly from IO."); else System.out.println ("Tree is *NOT* being constructed correctly from IO."); //try a few test cases int count =0; String[] list = testLister.list("32843"); System.out.println("Test: 32843"); if (list.length == 0) count++; list = testLister.list("42662"); System.out.println("Test: 42662"); if (list[0].equals("gamma") && list.length == 1) count++; list = testLister.list("26229"); System.out.println("Test: 26229"); if (list[0].equals("bobby") && list.length == 1) count++; list = testLister.list("52999"); System.out.println("Test: 52999"); if (list.length == 2 && list[0].equals("jazzy") && list[1].equals("lawzy")) count ++; list = testLister.list("10100"); System.out.println("Test: 10100"); if (list.length == 0) count ++; System.out.println("Program passes " + count + " tests out of 5 *WITHOUT* wildcards."); count = 0; list = testLister.list("*2843"); System.out.println("Test: *2843"); if (list.length == 3 && list[1].equals("lathe")) count++; list = testLister.list("4*662"); System.out.println("Test: 4*662"); if (list[2].equals("gonna") && list.length == 3) count++; list = testLister.list("26*29"); System.out.println("Test: 26*29"); if (list[0].equals("borax") && list.length == 3) count++; list = testLister.list("529*9"); System.out.println("Test: 529*9"); if (list.length == 4 && list[2].equals("laxly")) count ++; list = testLister.list("*****"); System.out.println("Test: *****"); if (list.length == 5757 && list[7].equals("huzza")) count++; System.out.println("Program passes " + count + " tests out of 5 *WITH* wildcards."); } }