/* ** $Id: testcounter.cpp,v 1.1 2003/01/20 20:39:29 phf Exp $ ** ** Copyright (c) 2003 by Peter H. Froehlich . ** Freely distributable for educational purposes. */ #include #include "simplecounter.h" /* ** Simple test driver for a counter implementation called ** "SimpleCounter" and in file "simplecounter". */ int main() { cs14::Counter *c = new cs14::SimpleCounter( -1, 3 ); std::cout << "Initial value and bounds: " << c->get() << " [" << c->lower() << ", " << c->upper() << "]" << std::endl; try { c->dec(); // -1 c->inc(); // 0 c->inc(); // 1 c->inc(); // 2 c->inc(); // 3 } catch ( std::exception &e ) { std::cout << "Unexpected exception (1): " << e.what() << std::endl; } try { c->inc(); // argh } catch ( std::exception &e ) { std::cout << "Expected exception (2): " << e.what() << std::endl; } try { c->set( 10 ); } catch ( std::exception &e ) { std::cout << "Expected exception (3): " << e.what() << std::endl; } try { c->set( -1 ); } catch ( std::exception &e ) { std::cout << "Unexpected exception (4): " << e.what() << std::endl; } try { c->dec(); // argh } catch ( std::exception &e ) { std::cout << "Expected exception (5): " << e.what() << std::endl; } delete c; return 0; }