/************************************************* * ArrayTester * Author: Douglas Wilhelm Harder * * A class for testing our silly Array class * * Copyright (c) 2006 by Douglas Wilhelm Harder. All rights reserved. *************************************************/ #ifndef ARRAY_TESTER_H #define ARRAY_TESTER_H #ifndef nullptr #define nullptr 0 #endif #include "Tester.h" #include "Array.h" #include using namespace std; class ArrayTester:public Tester { public: ArrayTester( Array *obj = 0 ):Tester( obj ) { // empty constructor } }; /**************************************************** * void process() * * Command Tests... * * new the default constructor * new(n) n the constructor with an argument n * delete the destructor * * empty b empty() == b * size n size() == n * get m n get( m ) == n * member n b member( n ) == b * print print the elements in order separated by dashes * * insert n insert( n ) succeeds * insert-overflow n insert( n ) throws an overflow exception * remove n b remove( n ) == b ****************************************************/ void Tester::process() { if ( command == "new(n)" ) { int n; cin >> n; object = new Array( n ); cout << "Okay" << endl; } else if ( command == "empty" ) { bool expected_Boolean; cin >> expected_Boolean; bool actual_Boolean = object->empty(); if ( actual_Boolean == expected_Boolean ) { cout << "Okay" << endl; } else { cout << "Failure in empty(): expecting the value '" << expected_Boolean << "' but got '" << actual_Boolean << "'" << endl; } } else if ( command == "size" ) { int expected_size; cin >> expected_size; int actual_size = object->size(); if ( actual_size == expected_size ) { cout << "Okay" << endl; } else { cout << "Failure in size(): expecting the value '" << expected_size << "' but got '" << actual_size << "'" << endl; } } else if ( command == "get" ) { int n; cin >> n; int expected_get; cin >> expected_get; int actual_get = object->get( n ); if ( actual_get == expected_get ) { cout << "Okay" << endl; } else { cout << "Failure in get(" << n << "): expecting the value '" << expected_get << "' but got '" << actual_get << "'" << endl; } } else if ( command == "member" ) { int n; cin >> n; bool expected_Boolean; cin >> expected_Boolean; int actual_Boolean = object->member( n ); if ( actual_Boolean == expected_Boolean ) { cout << "Okay" << endl; } else { cout << "Failure in member(" << n << "): expecting the value '" << expected_Boolean << "' but got '" << actual_Boolean << "'" << endl; } } else if ( command == "print" ) { object->print(); cout << endl; } else if ( command == "insert" ) { int n; cin >> n; object->insert( n ); cout << "Okay" << endl; } else if ( command == "insert-overflow" ) { int n; cin >> n; try { object->insert( n ); cout << ": Failure in insert(" << n << "): expecting an exception but did not" << endl; } catch ( overflow ) { cout << "Okay" << endl; } } else if ( command == "remove" ) { int n; cin >> n; bool expected_Boolean; cin >> expected_Boolean; int actual_Boolean = object->remove( n ); if ( actual_Boolean == expected_Boolean ) { cout << "Okay" << endl; } else { cout << "Failure in remove(" << n << "): expecting the value '" << expected_Boolean << "' but got '" << actual_Boolean << "'" << endl; } } else { cout << command << ": Command not found." << endl; } } #endif