/* Spring 2004 CSCI 2720 Prog. Proj. #5 part I */ /* --------------------------------------------------------------------- */ /* testxch.cc */ /* tests basic operations for Xchain and Xchain */ /* hash table classes */ /* --------------------------------------------------------------------- */ /* The outputs are self-explanatory, that is, the outputs of the various member functions should match exactly the outputs predicted by the text directed to cout. Note that this is not an exhaustive test of all the functionality required by the project, or even of the interfaces to all of the public member functions. However the functions used are representative. NOTE ALSO: the class Cstring for C-style strings must be defined in xchain.cc and the (modified) olist.cc must be #included from xchain.cc, so that to compile all that is needed is the command "g++ testxch.cc". */ #include "xchain.cc" int main( ) { Xchain HTint; int i; cout << "should be: 1 1 1 0 1 0 1" << endl; cout << " "; cout << HTint.Insert(9); cout << ' ' << HTint.Insert(5); cout << ' ' << HTint.Insert(13); cout << ' ' << HTint.Insert(2 + 3); cout << ' ' << HTint.Insert(98 - 5); cout << ' ' << HTint.Insert(65 / 5); cout << ' ' << HTint.Insert(28 % 11) << endl; for ( i = 0; i < 50; i++ ) HTint.Insert(101 + i); cout << "should be: 0 0 1 0 0 1 0" << endl; cout << " "; cout << HTint.Remove(29); cout << ' ' << HTint.Remove(15); cout << ' ' << HTint.Remove(5); cout << ' ' << HTint.Remove(25); cout << ' ' << HTint.Remove(95); cout << ' ' << HTint.Remove(13); cout << ' ' << HTint.Remove(5) << endl; cout << "should be: 0 0 1 0 1 0 1" << endl; cout << " "; cout << HTint.Find(29); cout << ' ' << HTint.Find(13); cout << ' ' << HTint.Find(93); cout << ' ' << HTint.Find(5); cout << ' ' << HTint.Find(9); cout << ' ' << HTint.Find(45); cout << ' ' << HTint.Find(6) << endl; Xchain HTstr; char *osstr1 = "can we tell well"; char *osstr2 = "If not, then we can tell so"; char *st1 = osstr1 + 12; char *st2 = osstr2 + 25; cout << "should be: 1 0 1 1 1 1 1 1 1 1 0 0" << endl; cout << " "; cout << HTstr.Insert("far!"); for ( i = 0; i < 25; i++ ) HTstr.Insert(osstr2 + i); cout << ' ' << HTstr.Remove("It"); cout << ' ' << HTstr.Insert("well"); cout << ' ' << HTstr.Insert(st2); cout << ' ' << HTstr.Insert("works"); cout << ' ' << HTstr.Find("so"); cout << ' ' << HTstr.Insert("It"); cout << ' ' << HTstr.Find(st1); cout << ' ' << HTstr.Find("well"); cout << ' ' << HTstr.Remove(st1); cout << ' ' << HTstr.Find("well"); cout << ' ' << HTstr.Insert("so") << endl; return 0; } // end of main( )