/* * stackclassunittest.cpp * * Created on: Oct 27, 2009 * Author: heber */ using namespace std; #include #include #include #include "stackclassunittest.hpp" #include "log.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ enum { testdimension=3 }; /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( StackClassTest ); void StackClassTest::setUp() { Stack = new StackClass(testdimension); }; void StackClassTest::tearDown() { Stack->ClearStack(); delete(Stack); logger::purgeInstance(); }; /** UnitTest for StackClass implementation * */ void StackClassTest::TestImplementation() { int testfield[testdimension] = {0,1,2}; //Log() << Verbose(1) << "Testing the snake stack..." << endl; for (int i=0;iPush(&testfield[i]); } //Log() << Verbose(0) << endl; //Output(out); CPPUNIT_ASSERT_EQUAL(true, Stack->IsFull()); CPPUNIT_ASSERT_EQUAL(false, Stack->IsEmpty()); CPPUNIT_ASSERT_EQUAL((testdimension) % (int)testdimension, Stack->ItemCount()); CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[1]) ); CPPUNIT_ASSERT_EQUAL((testdimension-1) % (int)testdimension, Stack->ItemCount()); CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[2]) ); CPPUNIT_ASSERT_EQUAL((testdimension-2) % (int)testdimension, Stack->ItemCount()); CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[0]) ); CPPUNIT_ASSERT_EQUAL((testdimension-3) % (int)testdimension, Stack->ItemCount()); Stack->ClearStack(); CPPUNIT_ASSERT_EQUAL(false, Stack->IsFull()); CPPUNIT_ASSERT_EQUAL(true, Stack->IsEmpty()); CPPUNIT_ASSERT_EQUAL(0, Stack->ItemCount()); };