// By Haw-ren Fang, TA of cmsc420-0401, Spring 2002 import java.io.*; import java.lang.*; public class HashTableDriver1 { public static void putError() { System.out.println("put() failed in test, you got 0/15."); System.exit(1); } public static void main(String args[]) throws Exception { int total = 0; System.out.println("HashTable get()/longestProbe() Test:"); try{ HashTable table = new HashTable(7); // Test put() if (!table.put("sunday", "nobody")) putError(); else if (!table.put("monday", "john")) putError(); else if (!table.put("tuesday", "mary")) putError(); else if (!table.put("wednesday", "joe")) putError(); else if (!table.put( "thursday", "peggy")) putError(); else if (!table.put( "friday", "david")) putError(); else if (!table.put( "saturday", "jerry")) putError(); try { if ((String)table.get("sunday")!="nobody") System.out.println("get() test: 0/5"); else if ((String)table.get("monday")!="john") System.out.println("get() test: 0/5"); else if ((String)table.get("tuesday")!="mary") System.out.println("get() test: 0/5"); else if ((String)table.get("wednesday")!="joe") System.out.println("get() test: 0/5"); else if ((String)table.get("thursday")!="peggy") System.out.println("get() test: 0/5"); else if ((String)table.get("friday")!="david") System.out.println("get() test: 0/5"); else if ((String)table.get("saturday")!="jerry") System.out.println("get() test: 0/5"); else { System.out.println("get() test: 5/5"); total += 5; } } catch (Exception e) { System.out.println("!!get() test: 0/5"); } // Test longestProbe() #1 // System.out.println("longestProbe() = " + table.longestProbe()); if (table.longestProbe() != 7) System.out.println("longestProbe() test #1: 0/5"); else { System.out.println("longestProbe() test #1: 5/5"); total += 5; } // Test longestProbe() #2 table.remove("saturday"); // System.out.println("longestProbe() = " + table.longestProbe()); if (table.longestProbe() != 3) System.out.println("longestProbe() test #2: 0/5"); else { System.out.println("longestProbe() test #2: 5/5"); total += 5; } } catch (Exception e) {} System.out.println("Total: " + total + "/15"); } }