source: src/unittests/LinkedCellUnitTest.cpp@ d0a719

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d0a719 was f844ef, checked in by Frederik Heber <heber@…>, 14 years ago

Renamed all remaining unit tests in src/unittests to Capitalized naming scheme.

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