import java.util.*; /** This class tests the symbol table implementation of Assignment 1, CS 146, Spring 2002. */ public class A1 { // to be returned by unsuccessful searches private static int ILLEGAL_VALUE = -1; /** For creating test data @param c a character @return a string consisting of 5 copies of the character, following a special character */ private static String string5(char c) { return "$"+c+c+c+c+c; } /** For creating test data @param n an integer @return a string consisting of the integer, preceded by a special character */ private static String stringn(int n) { return "x"+n; } /** The test program for a single symbol table @param h the table */ private static void test(SymbolTable h) { System.out.println(h.search("x6")); System.out.println(h.search("x10")); System.out.println(h.search("x15")); System.out.println(h.search("$aaaa")); System.out.println(h.search("$aaaaa")); h.draw(); System.out.println(""); h.traverse(); System.out.println(""); Vector v=h.sort(); Iterator it=v.iterator(); while (it.hasNext()) System.out.println( (SymbolTableEntry) it.next()); System.out.println(""); System.out.print("expected successful search time: "); System.out.println(h.successfulSearchTime()); System.out.println(""); System.out.print("expected unsuccessful search time: "); System.out.println(h.unsuccessfulSearchTime()); } /** The main function simply creates symbol tables and invokes the "test" method to test them. @param args is ignored */ public static void main(String[] args) { SymbolTable h=new SymbolTable(32,ILLEGAL_VALUE); SymbolTable k=new SymbolTable(32,ILLEGAL_VALUE); int counter=5; for (int i=1; i<=16; i++) h.insert(stringn(i),i*i*10); test(h); System.out.println(""); System.out.println(""); counter=5; for (char c='a'; c<='p'; c++) { counter+=10; k.insert(string5(c),counter); } for (int i=1; i<=16; i++) k.insert(stringn(i),i*i*10+1); test(k); } };