| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /* | 
|---|
| 9 | * LinkedCellUnitTest.cpp | 
|---|
| 10 | * | 
|---|
| 11 | *  Created on: Nov 14, 2011 | 
|---|
| 12 | *      Author: heber | 
|---|
| 13 | */ | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 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 "Atom/TesselPoint.hpp" | 
|---|
| 27 | #include "CodePatterns/Assert.hpp" | 
|---|
| 28 | #include "LinkedCell/LinkedCell.hpp" | 
|---|
| 29 |  | 
|---|
| 30 | #include "LinkedCellUnitTest.hpp" | 
|---|
| 31 |  | 
|---|
| 32 | #ifdef HAVE_TESTRUNNER | 
|---|
| 33 | #include "UnitTestMain.hpp" | 
|---|
| 34 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 35 |  | 
|---|
| 36 | /********************************************** Test classes **************************************/ | 
|---|
| 37 |  | 
|---|
| 38 | // Registers the fixture into the 'registry' | 
|---|
| 39 | CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCelltest ); | 
|---|
| 40 |  | 
|---|
| 41 |  | 
|---|
| 42 | void LinkedCelltest::setUp() | 
|---|
| 43 | { | 
|---|
| 44 | // failing asserts should be thrown | 
|---|
| 45 | ASSERT_DO(Assert::Throw); | 
|---|
| 46 |  | 
|---|
| 47 | // this must not compile as default cstor is private | 
|---|
| 48 | //cell = new LinkedCell(); | 
|---|
| 49 |  | 
|---|
| 50 | indices[0] = indices[1] = indices[2] = 0; | 
|---|
| 51 | cell = new LinkedCell::LinkedCell(indices); | 
|---|
| 52 | CPPUNIT_ASSERT(cell != NULL); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | void LinkedCelltest::tearDown() | 
|---|
| 57 | { | 
|---|
| 58 | delete cell; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | /** UnitTest for list capabilities. | 
|---|
| 62 | */ | 
|---|
| 63 | void LinkedCelltest::ListTest() | 
|---|
| 64 | { | 
|---|
| 65 | TesselPoint *Walker = new TesselPoint; | 
|---|
| 66 |  | 
|---|
| 67 | // add a point | 
|---|
| 68 | cell->insert(Walker); | 
|---|
| 69 | CPPUNIT_ASSERT_EQUAL((size_t)1, cell->size()); | 
|---|
| 70 |  | 
|---|
| 71 | // remove point | 
|---|
| 72 | LinkedCell::LinkedCell::iterator iter = cell->begin(); | 
|---|
| 73 | const TesselPoint *OtherWalker = *iter; | 
|---|
| 74 | CPPUNIT_ASSERT(Walker == OtherWalker); | 
|---|
| 75 | cell->erase(iter); | 
|---|
| 76 | CPPUNIT_ASSERT_EQUAL((size_t)0, cell->size()); | 
|---|
| 77 |  | 
|---|
| 78 | delete Walker; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | std::ostream & operator<<(std::ostream &ost, const LinkedCell::tripleIndex& indices) | 
|---|
| 82 | { | 
|---|
| 83 | ost << indices[0] << "," << indices[1] << "," << indices[2]; | 
|---|
| 84 | return ost; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | /** UnitTest for LinkedCell::addPoint() and LinkedCell::deletePoint() | 
|---|
| 88 | */ | 
|---|
| 89 | void LinkedCelltest::adddeletePointTest() | 
|---|
| 90 | { | 
|---|
| 91 | TesselPoint *Walker = new TesselPoint; | 
|---|
| 92 |  | 
|---|
| 93 | // add a point | 
|---|
| 94 | cell->addPoint(Walker); | 
|---|
| 95 | CPPUNIT_ASSERT_EQUAL((size_t)1, cell->size()); | 
|---|
| 96 | CPPUNIT_ASSERT(Walker == *(cell->begin())); | 
|---|
| 97 |  | 
|---|
| 98 | // remove point | 
|---|
| 99 | cell->deletePoint(Walker); | 
|---|
| 100 | CPPUNIT_ASSERT_EQUAL((size_t)0, cell->size()); | 
|---|
| 101 |  | 
|---|
| 102 | delete Walker; | 
|---|
| 103 |  | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | /** UnitTest for LinkedCell::getIndices(). | 
|---|
| 107 | */ | 
|---|
| 108 | void LinkedCelltest::IndexTest() | 
|---|
| 109 | { | 
|---|
| 110 | // check reference returned | 
|---|
| 111 | const LinkedCell::tripleIndex &returnedindices = cell->getIndices(); | 
|---|
| 112 | CPPUNIT_ASSERT_EQUAL(indices, returnedindices); | 
|---|
| 113 |  | 
|---|
| 114 | // check each index | 
|---|
| 115 | for(size_t i=0;i<3;++i) | 
|---|
| 116 | CPPUNIT_ASSERT_EQUAL( indices[i], cell->getIndex(i) ); | 
|---|
| 117 | } | 
|---|