Class HashTableTest

java.lang.Object
  |
  +--HashTableTest

public class HashTableTest
extends java.lang.Object

Class HashTableTest exercises the HashTable class using a simple integer-valued hash table entry. Tests are run in the following phases:


     Phase 1: Test the constructor, building tables of sizes 1, 5, 500, and
              the default size; confirm the size of each table.  Also check
		that exceptions HashEntryTypeInvalid and HashIndexInvalid are
		thrown when they should be.

     Phase 2: Test the enter method, lookup, and delete methods on table of
              size 1.

     Phase 3: Test enter method by filling up a table of size 5, including
              check of the TableFull exception.

     Phase 4: Test the lookup method on the full table of size 5, expecting
              O(N) performance on lookups given full table.

     Phase 5: Test the delete method on table of size 5, removing each entry.

     Phase 6: Repeat phases 3 through 5 to exercise the somewhat tricky
              implementation of delete that uses active/inactive flags.

     Phase 7: Successively test the enter, lookup, and delete methods on the
              the same table of size 5, with 0 through 7 entries.  Expect
              O(N) performance on lookups since entries are all marked as
              inactive instead of being null.

     Phase 8: Rerun phase 7 on a new table of size 5, expecting O(c)
              performance on early lookups.

     Phase 9: Test enter and lookup on a larger more sparsely populated
              table, expecting O(c) performance.
                                                                       


Inner Class Summary
protected static class HashTableTest.IntEntry
          Inner class IntEntry is a very simple implementation of HashTableEntry with a single Integer field.
 
Field Summary
protected static HashTable table1
          Testing tables
protected static HashTable table5
          Testing tables
protected static HashTable table500
          Testing tables
protected static HashTable tableDefault
          Testing tables
 
Constructor Summary
HashTableTest()
           
 
Method Summary
protected static void dumpMultiLookupResults(HashTable table, java.lang.Integer key, int n)
          Dump the result of what is expected to be a n-value lookup.
protected static void dumpSingleLookupResults(HashTable table, java.lang.Integer key)
          Dump the result of what is expected to be a single-value lookup.
static void main(java.lang.String[] args)
          Allocate a HashTable and test the HashTable methods.
static void phase1()
          Construct tables of sizes 1, 5, 500, and the default size; confirm the size of each table.
static void phase2()
          Test enter, lookup, and delete on table of size 1.
protected static void phase3(HashTable table)
          Test enter method by filling up a table of size 5, including check of the TableFull exception.
protected static void phase4(HashTable table)
          Test the lookup method on the full table of size 5, expecting O(N) performance on lookups given full table.
protected static void phase5(HashTable table)
          Test the delete method on table of size 5, removing each entry.
protected static void phase6(HashTable table)
          Repeat phases 3 through 5 to exercise the somewhat tricky implementation of delete that uses active/inactive flags.
protected static void phase7(HashTable table)
          Successively test the enter, lookup, and delete methods on the the same table of size 5, with 0 through 7 entries.
protected static void phase9(HashTable table)
          Test enter and lookup on a larger more sparsely populated table, expecting O(c) performance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table1

protected static HashTable table1
Testing tables

table5

protected static HashTable table5
Testing tables

table500

protected static HashTable table500
Testing tables

tableDefault

protected static HashTable tableDefault
Testing tables
Constructor Detail

HashTableTest

public HashTableTest()
Method Detail

main

public static void main(java.lang.String[] args)
                 throws HashEntryTypeInvalid,
                        HashTableFull,
                        HashIndexInvalid
Allocate a HashTable and test the HashTable methods.

phase1

public static void phase1()
                   throws HashTableFull,
                          HashIndexInvalid
Construct tables of sizes 1, 5, 500, and the default size; confirm the size of each table. Also check that exceptions HashEntryTypeInvalid and HashIndexInvalid are thrown when they should be.

phase2

public static void phase2()
                   throws HashEntryTypeInvalid,
                          HashTableFull,
                          HashIndexInvalid
Test enter, lookup, and delete on table of size 1.

phase3

protected static void phase3(HashTable table)
Test enter method by filling up a table of size 5, including check of the TableFull exception.

phase4

protected static void phase4(HashTable table)
Test the lookup method on the full table of size 5, expecting O(N) performance on lookups given full table.

phase5

protected static void phase5(HashTable table)
Test the delete method on table of size 5, removing each entry.

phase6

protected static void phase6(HashTable table)
Repeat phases 3 through 5 to exercise the somewhat tricky implementation of delete that uses active/inactive flags.

phase7

protected static void phase7(HashTable table)
Successively test the enter, lookup, and delete methods on the the same table of size 5, with 0 through 7 entries. Expect O(N) performance on lookups since entries are all marked as inactive instead of being null.

phase9

protected static void phase9(HashTable table)
                      throws HashEntryTypeInvalid,
                             HashTableFull,
                             HashIndexInvalid
Test enter and lookup on a larger more sparsely populated table, expecting O(c) performance.

dumpSingleLookupResults

protected static void dumpSingleLookupResults(HashTable table,
                                              java.lang.Integer key)
Dump the result of what is expected to be a single-value lookup.

dumpMultiLookupResults

protected static void dumpMultiLookupResults(HashTable table,
                                             java.lang.Integer key,
                                             int n)
Dump the result of what is expected to be a n-value lookup.