// File: p5main3.cpp // // Tests ZoomTable functionality. // #include #include #include "ZoomTable.H" using namespace std ; void PrintNode(Node* ptr) { if (ptr == NULL) { cout << "NULL!!! " ; } else { cout << "(" << ptr->row() << "," << ptr->col() << ")=" << ptr->get() << "\n" ; } } int main() { ZoomTable Z(5,7,0) ; Node *ptr ; int ZTerrorCount=0, OtherErrorCount=0 ; //------ same old, same old // After these insertions and deletions, the ZoomTable // should look like the diagram in the project description. Z.insert(0,5,41) ; Z.insert(0,6,42) ; Z.insert(0,4,43) ; Z.insert(0,0,44) ; Z.remove(0,5) ; Z.insert(1,3,45) ; Z.insert(1,4,46) ; Z.insert(4,6,47) ; Z.insert(2,1,48) ; Z.insert(2,4,49) ; Z.insert(3,5,27) ; Z.insert(2,5,50) ; Z.insert(3,0,51) ; Z.insert(4,0,52) ; Z.insert(3,3,17) ; Z.insert(1,6,54) ; Z.insert(4,4,37) ; Z.insert(3,3,56) ; ptr = Z.find(2,4) ; Z.remove(ptr) ; ptr = Z.find(3,5) ; ptr->set(49) ; Z.insert(4,4,55) ; //------ Check iterator ++ return value ZTRowIterator RowIt1, RowIt2, RowIt3 ; ZTColIterator ColIt1, ColIt2, ColIt3 ; RowIt1 = RowIt2 = Z.RowBegin(2) ; RowIt3 = RowIt1++ ; if (RowIt2 != RowIt3) { cout << "ZTRowIterator::operator++ did not return correct value!\n" ; } ColIt1 = ColIt2 = Z.ColBegin(2) ; ColIt3 = ColIt1++ ; if (ColIt2 != ColIt3) { cout << "ZTColIterator::operator++ did not return correct value!\n" ; } //------ do some bad things that try { cout << "Testing ZoomTable::insert()\n" ; Z.insert(10, 1, 1) ; // row index too large } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::insert()\n" ; Z.insert(1,7,1) ; // column index too large } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::find()\n" ; Z.find(5,2) ; // row index too large } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::find()\n" ; Z.find(2,19) ; // column index too large } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::remove()\n" ; Z.remove(-1,4) ; // row index too small } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::remove()\n" ; Z.remove(2, -3) ; // column index too small } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::at()\n" ; Z.at(7,8) ; // row and column indices too large } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::at()\n" ; Z.at(-1,-5) ; // row and column indices too small } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::FirstInRow()\n" ; Z.FirstInRow(7) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::FirstInCol()\n" ; Z.FirstInCol(-23) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::RowBegin()\n" ; Z.RowBegin(-4) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::RowEnd()\n" ; Z.RowEnd(1002) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::ColBegin()\n" ; Z.ColBegin(256) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } try { cout << "Testing ZoomTable::ColEnd()\n" ; Z.ColEnd(-44) ; } catch (ZTerror &e) { cout << e.desc << endl ; cout << " Valid row index: 0 to " << e.max_row << "\n" ; cout << " Valid column index: 0 to " << e.max_col << "\n" ; cout << " Offending indices: bad_row=" << e.bad_row << ", bad_col=" << e.bad_col << "\n\n" ; ZTerrorCount++ ; } catch (...) { cout << "Some other exception thrown\n\n" ; OtherErrorCount++ ; } cout << "Number of ZTerror exceptions caught = " << ZTerrorCount << "\n" ; cout << "Number of other exceptions caught = " << OtherErrorCount << "\n" ; }