#include #include #include "queue.h" using namespace std; int main(int argc, char **argv) { Queue q; // test empty assert(q.is_empty()); cout << "is_empty empty passed" << endl; // test push and peek q.push(42); assert (q.peek() == 42); cout << "1st push and peek passed" << endl; // test empty not empty assert(!q.is_empty()); cout << "is_empty not empty passed" << endl; // test pop int ret; q.pop(ret); assert(ret == 42); cout << "pop returned the correct value - passed" << endl; assert(q.is_empty()); cout << "after the pop the queue should be empty again - passed" << endl; // test pushing a few things, popping them off and checking them as we go q.push(1); q.push(2); q.push(3); // test size assert(q.size() == 3); cout << "size test passed" << endl; // test popping each one off q.pop(ret); assert(ret == 3); assert(q.size() == 2); q.pop(ret); assert(ret == 2); assert(q.size() == 1); q.pop(ret); assert(ret == 1); assert(q.size() == 0); cout << "popping 3 on passed" << endl; // pop on an empty queue test assert(q.pop(ret) == false); cout << "pop empty queue passed" << endl; // put 1 - 10 on and pop them all off - just to iterate through for (int i = 1; i <= 10; i++) q.push(i); // bring them off while (q.pop(ret)) cout << ret << " "; // put 1 - 10 on again for (int i = 1; i <= 10; i++) { q.push_back(i); } // 28/4/2008 - test the iterator cout << endl << "iterator test" << endl; Queue::iterator i = q.begin(); for (; i != q.end(); i++) cout << *i << " "; cout << "test overrunning the iterator" << endl; try { i++; cout << "Overrun: " << *i << endl; } catch (...) { cout << "something horrible happened" << endl; } cout << endl << "All done" << endl; return 0; }