/**
*
*
* @description Assignment 13 Dictionaries and Hash table
* implementations.
*/
#include < cassert >
#include < iostream >
#include "KeyValuePair.hpp"
#include "Employee.hpp"
#include "HashDictionary.hpp"
using namespace std ;
/** main
* The main entry point for this program. Execution of this program
* will begin with this main function.
*
* @param argc The command line argument count which is the number of
* command line arguments provided by user when they started
* the program.
* @param argv The command line arguments, an array of character
* arrays.
*
* @returns An int value indicating program exit status. Usually 0
* is returned to indicate normal exit and a non-zero value
* is returned to indicate an error condition.
*/
int main ( int argc , char ** argv )
{
// -----------------------------------------------------------------------
cout << "----- testing Employee record and KeyValuePair class -----------" << endl ;
KeyValuePair < int , string > pair ( 42 , "blue" );
cout << "test key: " << pair . key () << endl ;
assert ( pair . key () == 42 );
cout << "test value: " << pair . value () << endl ;
assert ( pair . value () == "blue" );
int id = 3 ;
Employee e ( id , "Derek Harter" , "1234 Main Street, Commerce TX" , 12345.67 );
cout << e << endl ;
assert ( e . getId () == 3 );
assert ( e . getName () == "Derek Harter" );
cout << endl ;
// -----------------------------------------------------------------------
cout << "-------------- testing quadratic probing -----------------------" << endl ;
const int TABLE_SIZE = 7 ;
HashDictionary < int , Employee > dict ( TABLE_SIZE , EMPTY_EMPLOYEE_ID );
cout << "Newly created hash dictionary should be empty, size: " << dict . size () << endl ;
assert ( dict . size () == 0 );
int probeIndex = 0 ;
//cout << "probe index: " << probeIndex
// << " returned probe value: " << dict.probe(id, probeIndex)
// << endl;
//assert(dict.probe(id, probeIndex) == 2);
probeIndex = 1 ;
//cout << "probe index: " << probeIndex
// << " returned probe value: " << dict.probe(id, probeIndex)
// << endl;
//assert(dict.probe(id, probeIndex) == 5);
probeIndex = 5 ;
//cout << "probe index: " << probeIndex
// << " returned probe value: " << dict.probe(id, probeIndex)
// << endl;
//assert(dict.probe(id, probeIndex) == 37);
cout << endl ;
// -----------------------------------------------------------------------
cout << "-------------- testing mid-square hashing ----------------------" << endl ;
// the following asserts will only work for 32 bit ints, leave asserts
// commented out if you have 64 bit asserts
cout << "Assuming 32 bit (4 byte) ints for these tests: " << sizeof ( int ) << endl ;
assert ( sizeof ( int ) == 4 );
//id = 3918;
//cout << "hash key: " << id
// << " returned hash value: " << dict.hash(id)
// << endl;
//assert(dict.hash(id) == 1);
//id = 48517;
//cout << "hash key: " << id
// << " returned hash value: " << dict.hash(id)
// << endl;
//assert(dict.hash(id) == 6);
//id = 913478;
//cout << "hash key: " << id
// << " returned hash value: " << dict.hash(id)
// << endl;
//assert(dict.hash(id) == 5);
//id = 8372915;
//cout << "hash key: " << id
// << " returned hash value: " << dict.hash(id)
// << endl;