1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * LinkedCellUnitTest.cpp
|
---|
25 | *
|
---|
26 | * Created on: Nov 14, 2011
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | #include <cppunit/CompilerOutputter.h>
|
---|
38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
40 |
|
---|
41 | #include "Atom/TesselPoint.hpp"
|
---|
42 | #include "CodePatterns/Assert.hpp"
|
---|
43 | #include "LinkedCell/LinkedCell.hpp"
|
---|
44 |
|
---|
45 | #include "LinkedCellUnitTest.hpp"
|
---|
46 |
|
---|
47 | #ifdef HAVE_TESTRUNNER
|
---|
48 | #include "UnitTestMain.hpp"
|
---|
49 | #endif /*HAVE_TESTRUNNER*/
|
---|
50 |
|
---|
51 | /********************************************** Test classes **************************************/
|
---|
52 |
|
---|
53 | // Registers the fixture into the 'registry'
|
---|
54 | CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCelltest );
|
---|
55 |
|
---|
56 |
|
---|
57 | void LinkedCelltest::setUp()
|
---|
58 | {
|
---|
59 | // failing asserts should be thrown
|
---|
60 | ASSERT_DO(Assert::Throw);
|
---|
61 |
|
---|
62 | // this must not compile as default cstor is private
|
---|
63 | //cell = new LinkedCell();
|
---|
64 |
|
---|
65 | indices[0] = indices[1] = indices[2] = 0;
|
---|
66 | cell = new LinkedCell::LinkedCell(indices);
|
---|
67 | CPPUNIT_ASSERT(cell != NULL);
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | void LinkedCelltest::tearDown()
|
---|
72 | {
|
---|
73 | delete cell;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** UnitTest for list capabilities.
|
---|
77 | */
|
---|
78 | void LinkedCelltest::ListTest()
|
---|
79 | {
|
---|
80 | TesselPoint *Walker = new TesselPoint;
|
---|
81 |
|
---|
82 | // add a point
|
---|
83 | cell->insert(Walker);
|
---|
84 | CPPUNIT_ASSERT_EQUAL((size_t)1, cell->size());
|
---|
85 |
|
---|
86 | // remove point
|
---|
87 | LinkedCell::LinkedCell::iterator iter = cell->begin();
|
---|
88 | const TesselPoint *OtherWalker = *iter;
|
---|
89 | CPPUNIT_ASSERT(Walker == OtherWalker);
|
---|
90 | cell->erase(iter);
|
---|
91 | CPPUNIT_ASSERT_EQUAL((size_t)0, cell->size());
|
---|
92 |
|
---|
93 | delete Walker;
|
---|
94 | }
|
---|
95 |
|
---|
96 | std::ostream & operator<<(std::ostream &ost, const LinkedCell::tripleIndex& indices)
|
---|
97 | {
|
---|
98 | ost << indices[0] << "," << indices[1] << "," << indices[2];
|
---|
99 | return ost;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /** UnitTest for LinkedCell::addPoint() and LinkedCell::deletePoint()
|
---|
103 | */
|
---|
104 | void LinkedCelltest::adddeletePointTest()
|
---|
105 | {
|
---|
106 | TesselPoint *Walker = new TesselPoint;
|
---|
107 |
|
---|
108 | // add a point
|
---|
109 | cell->addPoint(Walker);
|
---|
110 | CPPUNIT_ASSERT_EQUAL((size_t)1, cell->size());
|
---|
111 | CPPUNIT_ASSERT(Walker == *(cell->begin()));
|
---|
112 |
|
---|
113 | // remove point
|
---|
114 | cell->deletePoint(Walker);
|
---|
115 | CPPUNIT_ASSERT_EQUAL((size_t)0, cell->size());
|
---|
116 |
|
---|
117 | delete Walker;
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | /** UnitTest for LinkedCell::getIndices().
|
---|
122 | */
|
---|
123 | void LinkedCelltest::IndexTest()
|
---|
124 | {
|
---|
125 | // check reference returned
|
---|
126 | const LinkedCell::tripleIndex &returnedindices = cell->getIndices();
|
---|
127 | CPPUNIT_ASSERT_EQUAL(indices, returnedindices);
|
---|
128 |
|
---|
129 | // check each index
|
---|
130 | for(size_t i=0;i<3;++i)
|
---|
131 | CPPUNIT_ASSERT_EQUAL( indices[i], cell->getIndex(i) );
|
---|
132 | }
|
---|