| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [8c5327] | 8 | /*
 | 
|---|
 | 9 |  * stackclassunittest.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Oct 27, 2009
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [8c5327] | 20 | using namespace std;
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 23 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 24 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | #include "stackclassunittest.hpp"
 | 
|---|
| [952f38] | 27 | #include "Helpers/Log.hpp"
 | 
|---|
| [8c5327] | 28 | 
 | 
|---|
| [9b6b2f] | 29 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 30 | #include "UnitTestMain.hpp"
 | 
|---|
 | 31 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 32 | 
 | 
|---|
| [8c5327] | 33 | enum { testdimension=3 };
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | /********************************************** Test classes **************************************/
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | // Registers the fixture into the 'registry'
 | 
|---|
 | 38 | CPPUNIT_TEST_SUITE_REGISTRATION( StackClassTest );
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | void StackClassTest::setUp()
 | 
|---|
 | 42 | {
 | 
|---|
 | 43 |   Stack = new StackClass<int *>(testdimension);
 | 
|---|
 | 44 | };
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | void StackClassTest::tearDown()
 | 
|---|
 | 48 | {
 | 
|---|
 | 49 |   Stack->ClearStack();
 | 
|---|
 | 50 |   delete(Stack);
 | 
|---|
| [e6fdbe] | 51 |   logger::purgeInstance();
 | 
|---|
| [8c5327] | 52 | };
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | /** UnitTest for StackClass<T> implementation
 | 
|---|
 | 55 |  *
 | 
|---|
 | 56 |  */
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | void StackClassTest::TestImplementation()
 | 
|---|
 | 59 | {
 | 
|---|
 | 60 |   int testfield[testdimension] = {0,1,2};
 | 
|---|
| [e138de] | 61 |   //Log() << Verbose(1) << "Testing the snake stack..." << endl;
 | 
|---|
| [8c5327] | 62 |   for (int i=0;i<testdimension;i++) {
 | 
|---|
| [e138de] | 63 |     //Log() << Verbose(2) << "Filling " << i << "th element of stack." << endl;
 | 
|---|
| [8c5327] | 64 |     Stack->Push(&testfield[i]);
 | 
|---|
 | 65 |   }
 | 
|---|
| [e138de] | 66 |   //Log() << Verbose(0) << endl;
 | 
|---|
| [8c5327] | 67 |   //Output(out);
 | 
|---|
 | 68 |   CPPUNIT_ASSERT_EQUAL(true, Stack->IsFull());
 | 
|---|
 | 69 |   CPPUNIT_ASSERT_EQUAL(false, Stack->IsEmpty());
 | 
|---|
 | 70 |   CPPUNIT_ASSERT_EQUAL((testdimension) % (int)testdimension, Stack->ItemCount());
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 |   CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[1]) );
 | 
|---|
 | 73 |   CPPUNIT_ASSERT_EQUAL((testdimension-1) % (int)testdimension, Stack->ItemCount());
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |   CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[2]) );
 | 
|---|
 | 76 |   CPPUNIT_ASSERT_EQUAL((testdimension-2) % (int)testdimension, Stack->ItemCount());
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 |   CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[0]) );
 | 
|---|
 | 79 |   CPPUNIT_ASSERT_EQUAL((testdimension-3) % (int)testdimension, Stack->ItemCount());
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |   Stack->ClearStack();
 | 
|---|
 | 82 |   CPPUNIT_ASSERT_EQUAL(false, Stack->IsFull());
 | 
|---|
 | 83 |   CPPUNIT_ASSERT_EQUAL(true, Stack->IsEmpty());
 | 
|---|
 | 84 |   CPPUNIT_ASSERT_EQUAL(0, Stack->ItemCount());
 | 
|---|
 | 85 | };
 | 
|---|