| 1 | /*
 | 
|---|
| 2 |  * LinkedCellUnitTest.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Apr 9, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | using namespace std;
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
| 11 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
| 12 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
| 13 | 
 | 
|---|
| 14 | #include <iostream>
 | 
|---|
| 15 | #include <stdio.h>
 | 
|---|
| 16 | #include <cstring>
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include "atom.hpp"
 | 
|---|
| 19 | #include "element.hpp"
 | 
|---|
| 20 | #include "linkedcell.hpp"
 | 
|---|
| 21 | #include "molecule.hpp"
 | 
|---|
| 22 | #include "periodentafel.hpp"
 | 
|---|
| 23 | #include "LinkedCellUnitTest.hpp"
 | 
|---|
| 24 | #include "World.hpp"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #ifdef HAVE_TESTRUNNER
 | 
|---|
| 27 | #include "UnitTestMain.hpp"
 | 
|---|
| 28 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
| 29 | 
 | 
|---|
| 30 | /********************************************** Test classes **************************************/
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // Registers the fixture into the 'registry'
 | 
|---|
| 33 | CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCellTest );
 | 
|---|
| 34 | 
 | 
|---|
| 35 | 
 | 
|---|
| 36 | void LinkedCellTest::setUp()
 | 
|---|
| 37 | {
 | 
|---|
| 38 |   atom *Walker = NULL;
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   // init private all pointers to zero
 | 
|---|
| 41 |   TestMolecule = NULL;
 | 
|---|
| 42 |   hydrogen = NULL;
 | 
|---|
| 43 |   tafel = NULL;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   // construct element
 | 
|---|
| 46 |   hydrogen = new element;
 | 
|---|
| 47 |   hydrogen->Z = 1;
 | 
|---|
| 48 |   hydrogen->CovalentRadius = 0.23;
 | 
|---|
| 49 |   strcpy(hydrogen->name, "hydrogen");
 | 
|---|
| 50 |   strcpy(hydrogen->symbol, "H");
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   // construct periodentafel
 | 
|---|
| 53 |   tafel = World::getInstance().getPeriode();
 | 
|---|
| 54 |   tafel->AddElement(hydrogen);
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   // construct molecule (water molecule)
 | 
|---|
| 57 |   TestMolecule = World::getInstance().createMolecule();
 | 
|---|
| 58 |   for (double x=0.5;x<3;x+=1.)
 | 
|---|
| 59 |     for (double y=0.5;y<3;y+=1.)
 | 
|---|
| 60 |       for (double z=0.5;z<3;z+=1.) {
 | 
|---|
| 61 |         Walker = World::getInstance().createAtom();
 | 
|---|
| 62 |         Walker->type = hydrogen;
 | 
|---|
| 63 |         *Walker->node = Vector(x, y, z );
 | 
|---|
| 64 |         TestMolecule->AddAtom(Walker);
 | 
|---|
| 65 |       }
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   // construct linked cell
 | 
|---|
| 68 |   LC = new LinkedCell (TestMolecule, 1.);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |   // check that TestMolecule was correctly constructed
 | 
|---|
| 71 |   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 );
 | 
|---|
| 72 |   Walker = TestMolecule->start->next;
 | 
|---|
| 73 |   CPPUNIT_ASSERT( TestMolecule->end != Walker );
 | 
|---|
| 74 | };
 | 
|---|
| 75 | 
 | 
|---|
| 76 | 
 | 
|---|
| 77 | void LinkedCellTest::tearDown()
 | 
|---|
| 78 | {
 | 
|---|
| 79 |   delete(LC);
 | 
|---|
| 80 |   World::purgeInstance();
 | 
|---|
| 81 |   MemoryUsageObserver::purgeInstance();
 | 
|---|
| 82 | };
 | 
|---|
| 83 | 
 | 
|---|
| 84 | 
 | 
|---|
| 85 | /** UnitTest for LinkedCell::CheckBounds().
 | 
|---|
| 86 |  */
 | 
|---|
| 87 | void LinkedCellTest::CheckBoundsTest()
 | 
|---|
| 88 | {
 | 
|---|
| 89 |   // check for within bounds
 | 
|---|
| 90 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 91 |   CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
 | 
|---|
| 92 |   LC->n[0] = LC->n[1] = LC->n[2] = 1;
 | 
|---|
| 93 |   CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
 | 
|---|
| 94 |   LC->n[0] = LC->n[1] = LC->n[2] = 2;
 | 
|---|
| 95 |   CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   // check for out of bounds
 | 
|---|
| 98 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 99 |   LC->n[0] = 404040;
 | 
|---|
| 100 |   CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
 | 
|---|
| 101 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 102 |   LC->n[0] = 0;
 | 
|---|
| 103 |   LC->n[1] = 5000;
 | 
|---|
| 104 |   CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
 | 
|---|
| 105 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 106 |   LC->n[1] = 0;
 | 
|---|
| 107 |   LC->n[2] = -70;
 | 
|---|
| 108 |   CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
 | 
|---|
| 109 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 110 |   LC->n[0] = LC->n[1] = LC->n[2] = 3;
 | 
|---|
| 111 |   CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
 | 
|---|
| 112 | };
 | 
|---|
| 113 | 
 | 
|---|
| 114 | 
 | 
|---|
| 115 | /** UnitTest for LinkedCell::GetCurrentCell().
 | 
|---|
| 116 |  * Note that CheckBounds() is used and has to be tested already.
 | 
|---|
| 117 |  */
 | 
|---|
| 118 | void LinkedCellTest::GetCurrentCellTest()
 | 
|---|
| 119 | {
 | 
|---|
| 120 |   // within bounds
 | 
|---|
| 121 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 122 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0 * 3*3 + 0 * 3 + 0], LC->GetCurrentCell() );
 | 
|---|
| 123 |   LC->n[0] = LC->n[1] = LC->n[2] = 1;
 | 
|---|
| 124 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[1 * 3*3 + 1 * 3 + 1], LC->GetCurrentCell() );
 | 
|---|
| 125 |   LC->n[0] = LC->n[1] = LC->n[2] = 2;
 | 
|---|
| 126 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetCurrentCell() );
 | 
|---|
| 127 | 
 | 
|---|
| 128 |   // out of bounds
 | 
|---|
| 129 |   LC->n[0] = LC->n[1] = LC->n[2] = 3;
 | 
|---|
| 130 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 131 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
 | 
|---|
| 132 |   LC->n[0] = LC->n[1] = LC->n[2] = -1;
 | 
|---|
| 133 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 134 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
 | 
|---|
| 135 | };
 | 
|---|
| 136 | 
 | 
|---|
| 137 | /** UnitTest for LinkedCell::GetRelativeToCurrentCell().
 | 
|---|
| 138 |  */
 | 
|---|
| 139 | void LinkedCellTest::GetRelativeToCurrentCellTest()
 | 
|---|
| 140 | {
 | 
|---|
| 141 |   int offset[3];
 | 
|---|
| 142 | 
 | 
|---|
| 143 |   // offset to (0,0,0) always
 | 
|---|
| 144 |   offset[0] = offset[1] = offset[2] = 0;
 | 
|---|
| 145 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 146 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 147 |   offset[0] = offset[1] = offset[2] = -1;
 | 
|---|
| 148 |   LC->n[0] = LC->n[1] = LC->n[2] = 1;
 | 
|---|
| 149 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 150 |   offset[0] = offset[1] = offset[2] = -2;
 | 
|---|
| 151 |   LC->n[0] = LC->n[1] = LC->n[2] = 2;
 | 
|---|
| 152 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 153 | 
 | 
|---|
| 154 |   // offset to (0,0,0) - 1.*(x/y/z) out of bounds
 | 
|---|
| 155 |   offset[0] = offset[1] = offset[2] = 0;
 | 
|---|
| 156 |   offset[0] = -1;
 | 
|---|
| 157 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 158 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 159 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 160 |   offset[0] = offset[1] = offset[2] = 0;
 | 
|---|
| 161 |   offset[1] = -1;
 | 
|---|
| 162 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 163 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 164 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 165 |   offset[0] = offset[1] = offset[2] = 0;
 | 
|---|
| 166 |   offset[2] = -1;
 | 
|---|
| 167 |   LC->n[0] = LC->n[1] = LC->n[2] = 0;
 | 
|---|
| 168 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 169 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 170 | 
 | 
|---|
| 171 |   // out of bounds
 | 
|---|
| 172 |   offset[0] = offset[1] = offset[2] = -5054932;
 | 
|---|
| 173 |   LC->n[0] = LC->n[1] = LC->n[2] = 1;
 | 
|---|
| 174 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 175 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 176 |   offset[0] = offset[1] = offset[2] = 192345;
 | 
|---|
| 177 |   LC->n[0] = LC->n[1] = LC->n[2] = 1;
 | 
|---|
| 178 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 179 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 180 | 
 | 
|---|
| 181 |   // index is out of bounds, offset points within
 | 
|---|
| 182 |   offset[0] = offset[1] = offset[2] = -2;
 | 
|---|
| 183 |   LC->n[0] = LC->n[1] = LC->n[2] = 4;
 | 
|---|
| 184 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 185 | 
 | 
|---|
| 186 |   // index is within bounds, offset points out
 | 
|---|
| 187 |   offset[0] = offset[1] = offset[2] = 2;
 | 
|---|
| 188 |   LC->n[0] = LC->n[1] = LC->n[2] = 2;
 | 
|---|
| 189 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 190 |   CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
 | 
|---|
| 191 | };
 | 
|---|
| 192 | 
 | 
|---|
| 193 | 
 | 
|---|
| 194 | /** UnitTest for LinkedCell::SetIndexToNode().
 | 
|---|
| 195 |  */
 | 
|---|
| 196 | void LinkedCellTest::SetIndexToNodeTest()
 | 
|---|
| 197 | {
 | 
|---|
| 198 |   // check all atoms
 | 
|---|
| 199 |   atom *Walker = TestMolecule->start;
 | 
|---|
| 200 |   while (Walker->next != TestMolecule->end) {
 | 
|---|
| 201 |     Walker = Walker->next;
 | 
|---|
| 202 |     CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) );
 | 
|---|
| 203 |   }
 | 
|---|
| 204 | 
 | 
|---|
| 205 |   // check internal vectors, returns false, because this atom is not in LC-list!
 | 
|---|
| 206 |   Walker = World::getInstance().createAtom();
 | 
|---|
| 207 |   Walker->setName("test");
 | 
|---|
| 208 |   Walker->x= Vector(1,1,1);
 | 
|---|
| 209 |   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
 | 
|---|
| 210 |   World::getInstance().destroyAtom(Walker);
 | 
|---|
| 211 | 
 | 
|---|
| 212 |   // check out of bounds vectors
 | 
|---|
| 213 |   Walker = World::getInstance().createAtom();
 | 
|---|
| 214 |   Walker->setName("test");
 | 
|---|
| 215 |   Walker->x = Vector(0,-1,0);
 | 
|---|
| 216 |   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
 | 
|---|
| 217 |   World::getInstance().destroyAtom(Walker);
 | 
|---|
| 218 | };
 | 
|---|
| 219 | 
 | 
|---|
| 220 | 
 | 
|---|
| 221 | /** UnitTest for LinkedCell::SetIndexToVector().
 | 
|---|
| 222 |  */
 | 
|---|
| 223 | void LinkedCellTest::SetIndexToVectorTest()
 | 
|---|
| 224 | {
 | 
|---|
| 225 |   Vector tester;
 | 
|---|
| 226 | 
 | 
|---|
| 227 |   // check center of each cell
 | 
|---|
| 228 |   for (double x=0.5;x<3;x+=1.)
 | 
|---|
| 229 |     for (double y=0.5;y<3;y+=1.)
 | 
|---|
| 230 |       for (double z=0.5;z<3;z+=1.) {
 | 
|---|
| 231 |         tester = Vector(x,y,z);
 | 
|---|
| 232 |         CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 233 |       }
 | 
|---|
| 234 |   // check corners of each cell
 | 
|---|
| 235 |   for (double x=1.;x<4;x+=1.)
 | 
|---|
| 236 |     for (double y=1.;y<4;y+=1.)
 | 
|---|
| 237 |       for (double z=1.;z<4;z+=1.) {
 | 
|---|
| 238 |         tester= Vector(x,y,z);
 | 
|---|
| 239 |         cout << "Tester is at " << tester << "." << endl;
 | 
|---|
| 240 |         CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 241 |       }
 | 
|---|
| 242 |   // check out of bounds
 | 
|---|
| 243 |   for (double x=0.5-1e-10;x<5;x+=3.1)
 | 
|---|
| 244 |     for (double y=0.5-1e-10;y<5;y+=3.1)
 | 
|---|
| 245 |       for (double z=0.5-1e-10;z<5;z+=3.1) {
 | 
|---|
| 246 |         tester = Vector(x,y,z);
 | 
|---|
| 247 |         cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 248 |         CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
 | 
|---|
| 249 |       }
 | 
|---|
| 250 |   // check nonsense vectors
 | 
|---|
| 251 |   tester= Vector(-423598,3245978,29349);
 | 
|---|
| 252 |   cout << "The following test is supposed to fail and produce an ERROR." << endl;
 | 
|---|
| 253 |   CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
 | 
|---|
| 254 | };
 | 
|---|
| 255 | 
 | 
|---|
| 256 | 
 | 
|---|
| 257 | /** UnitTest for LinkedCell::GetNeighbourBounds().
 | 
|---|
| 258 |  */
 | 
|---|
| 259 | void LinkedCellTest::GetNeighbourBoundsTest()
 | 
|---|
| 260 | {
 | 
|---|
| 261 |   Vector tester;
 | 
|---|
| 262 |   int lower[NDIM], upper[NDIM];
 | 
|---|
| 263 | 
 | 
|---|
| 264 |   tester= Vector(0.5,0.5,0.5);
 | 
|---|
| 265 |   LC->SetIndexToVector(&tester);
 | 
|---|
| 266 |   LC->GetNeighbourBounds(lower, upper);
 | 
|---|
| 267 |   for (int i=0;i<NDIM;i++)
 | 
|---|
| 268 |     CPPUNIT_ASSERT_EQUAL( 0, lower[i]);
 | 
|---|
| 269 |   for (int i=0;i<NDIM;i++)
 | 
|---|
| 270 |     CPPUNIT_ASSERT_EQUAL( 1, upper[i]);
 | 
|---|
| 271 | };
 | 
|---|
| 272 | 
 | 
|---|
| 273 | 
 | 
|---|
| 274 | /** UnitTest for LinkedCell::GetallNeighbours().
 | 
|---|
| 275 |  */
 | 
|---|
| 276 | void LinkedCellTest::GetallNeighboursTest()
 | 
|---|
| 277 | {
 | 
|---|
| 278 |   Vector tester;
 | 
|---|
| 279 |   LinkedCell::LinkedNodes *ListOfPoints = NULL;
 | 
|---|
| 280 |   atom *Walker = NULL;
 | 
|---|
| 281 |   size_t size = 0;
 | 
|---|
| 282 | 
 | 
|---|
| 283 |   // get all atoms
 | 
|---|
| 284 |   tester= Vector(1.5,1.5,1.5);
 | 
|---|
| 285 |   CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 286 |   ListOfPoints = LC->GetallNeighbours();
 | 
|---|
| 287 |   size = ListOfPoints->size();
 | 
|---|
| 288 |   CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
 | 
|---|
| 289 |   Walker = TestMolecule->start;
 | 
|---|
| 290 |   Walker = TestMolecule->start;
 | 
|---|
| 291 |   while (Walker->next != TestMolecule->end) {
 | 
|---|
| 292 |     Walker = Walker->next;
 | 
|---|
| 293 |     ListOfPoints->remove(Walker);
 | 
|---|
| 294 |     size--;
 | 
|---|
| 295 |     CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
 | 
|---|
| 296 |   }
 | 
|---|
| 297 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
 | 
|---|
| 298 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
 | 
|---|
| 299 |   CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
 | 
|---|
| 300 |   delete(ListOfPoints);
 | 
|---|
| 301 | 
 | 
|---|
| 302 |   // get all atoms in one corner
 | 
|---|
| 303 |   tester= Vector(0.5, 0.5, 0.5);
 | 
|---|
| 304 |   CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 305 |   ListOfPoints = LC->GetallNeighbours();
 | 
|---|
| 306 |   size=ListOfPoints->size();
 | 
|---|
| 307 |   CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
 | 
|---|
| 308 |   Walker = TestMolecule->start;
 | 
|---|
| 309 |   while (Walker->next != TestMolecule->end) {
 | 
|---|
| 310 |     Walker = Walker->next;
 | 
|---|
| 311 |     if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) {
 | 
|---|
| 312 |       ListOfPoints->remove(Walker);
 | 
|---|
| 313 |       size--;
 | 
|---|
| 314 |       CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
 | 
|---|
| 315 |     }
 | 
|---|
| 316 |   }
 | 
|---|
| 317 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
 | 
|---|
| 318 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
 | 
|---|
| 319 |   CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
 | 
|---|
| 320 |   delete(ListOfPoints);
 | 
|---|
| 321 | 
 | 
|---|
| 322 |   // get all atoms from one corner
 | 
|---|
| 323 |   tester = Vector(0.5, 0.5, 0.5);
 | 
|---|
| 324 |   CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 325 |   ListOfPoints = LC->GetallNeighbours(3);
 | 
|---|
| 326 |   size=ListOfPoints->size();
 | 
|---|
| 327 |   CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
 | 
|---|
| 328 |   Walker = TestMolecule->start;
 | 
|---|
| 329 |   while (Walker->next != TestMolecule->end) {
 | 
|---|
| 330 |     Walker = Walker->next;
 | 
|---|
| 331 |     ListOfPoints->remove(Walker);
 | 
|---|
| 332 |     size--;
 | 
|---|
| 333 |     CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
 | 
|---|
| 334 |   }
 | 
|---|
| 335 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
 | 
|---|
| 336 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
 | 
|---|
| 337 |   CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
 | 
|---|
| 338 |   delete(ListOfPoints);
 | 
|---|
| 339 | };
 | 
|---|
| 340 | 
 | 
|---|
| 341 | 
 | 
|---|
| 342 | /** UnitTest for LinkedCell::GetPointsInsideSphere().
 | 
|---|
| 343 |  */
 | 
|---|
| 344 | void LinkedCellTest::GetPointsInsideSphereTest()
 | 
|---|
| 345 | {
 | 
|---|
| 346 |   Vector tester;
 | 
|---|
| 347 |   LinkedCell::LinkedNodes *ListOfPoints = NULL;
 | 
|---|
| 348 |   atom *Walker = NULL;
 | 
|---|
| 349 |   size_t size = 0;
 | 
|---|
| 350 | 
 | 
|---|
| 351 |   // get all points around central arom with radius 1.
 | 
|---|
| 352 |   tester= Vector(1.5,1.5,1.5);
 | 
|---|
| 353 |   CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
 | 
|---|
| 354 |   ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
 | 
|---|
| 355 |   size = ListOfPoints->size();
 | 
|---|
| 356 |   CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
 | 
|---|
| 357 |   Walker = TestMolecule->start;
 | 
|---|
| 358 |   while (Walker->next != TestMolecule->end) {
 | 
|---|
| 359 |     Walker = Walker->next;
 | 
|---|
| 360 |     if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
 | 
|---|
| 361 |       ListOfPoints->remove(Walker);
 | 
|---|
| 362 |       size--;
 | 
|---|
| 363 |       CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
 | 
|---|
| 364 |     }
 | 
|---|
| 365 |   }
 | 
|---|
| 366 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
 | 
|---|
| 367 |   CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
 | 
|---|
| 368 |   CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
 | 
|---|
| 369 |   delete(ListOfPoints);
 | 
|---|
| 370 | };
 | 
|---|