/* Homework6Test.java */ import dict.*; /** * Initializes a hash table, then stocks it with random SimpleBoards. * @author Daniel C. Silverstein **/ public class Homework6Test { /** * Generates a random 8 x 8 SimpleBoard. **/ private static SimpleBoard randomBoard() { SimpleBoard board = new SimpleBoard(); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { double fval = Math.random() * 12; int value = (int) fval; board.setElementAt(x, y, value); } } return board; } /** * Empties the given table, then inserts the given number of boards * into the table. * @param table is the hash table to be initialized. * @param numBoards is the number of random boards to place in the table. **/ public static void initTable(HashTableChained table, int numBoards) { table.makeEmpty(); for (int i = 0; i < numBoards; i++) { table.insertItem(randomBoard(), new Integer(i)); } } public static void main(String[] args) { int numBoards; if (args.length == 0) { numBoards = 100; } else { numBoards = Integer.parseInt(args[0]); } HashTableChained table = new HashTableChained(numBoards); initTable(table, numBoards); // To test your hash function, add a method to your HashTableChained class // that counts the number of collisions. Call this method from here. } }