Changeset 4f9e47
- Timestamp:
- Apr 9, 2010, 1:41:52 PM (15 years ago)
- Branches:
- 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
- Children:
- ffe885
- Parents:
- a3696f
- Location:
- src/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/LinkedCellUnitTest.cpp
ra3696f r4f9e47 51 51 // construct molecule (water molecule) 52 52 TestMolecule = new molecule(tafel); 53 Walker = new atom(); 54 Walker->type = hydrogen; 55 Walker->node->Init(0., 0., 0. ); 56 TestMolecule->AddAtom(Walker); 53 for (double x=0.5;x<3;x+=1.) 54 for (double y=0.5;y<3;y+=1.) 55 for (double z=0.5;z<3;z+=1.) { 56 Walker = new atom(); 57 Walker->type = hydrogen; 58 Walker->node->Init(x, y, z ); 59 TestMolecule->AddAtom(Walker); 60 } 61 62 // construct linked cell 63 LC = new LinkedCell (TestMolecule, 1.); 57 64 58 65 // check that TestMolecule was correctly constructed 59 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 1);66 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 ); 60 67 Walker = TestMolecule->start->next; 61 68 CPPUNIT_ASSERT( TestMolecule->end != Walker ); 62 63 // construct linked cell64 LC = new LinkedCell (TestMolecule, 1.);65 69 }; 66 70 … … 76 80 77 81 82 /** UnitTest for LinkedCell::CheckBounds(). 83 */ 84 void LinkedCellTest::CheckBoundsTest() 85 { 86 // check for within bounds 87 LC->n[0] = LC->n[1] = LC->n[2] = 0; 88 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() ); 89 LC->n[0] = LC->n[1] = LC->n[2] = 1; 90 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() ); 91 LC->n[0] = LC->n[1] = LC->n[2] = 2; 92 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() ); 93 94 // check for out of bounds 95 cout << "The following test is supposed to fail and produce an ERROR." << endl; 96 LC->n[0] = 404040; 97 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() ); 98 cout << "The following test is supposed to fail and produce an ERROR." << endl; 99 LC->n[0] = 0; 100 LC->n[1] = 5000; 101 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() ); 102 cout << "The following test is supposed to fail and produce an ERROR." << endl; 103 LC->n[1] = 0; 104 LC->n[2] = -70; 105 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() ); 106 cout << "The following test is supposed to fail and produce an ERROR." << endl; 107 LC->n[0] = LC->n[1] = LC->n[2] = 3; 108 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() ); 109 }; 110 111 78 112 /** UnitTest for LinkedCell::GetCurrentCell(). 113 * Note that CheckBounds() is used and has to be tested already. 79 114 */ 80 115 void LinkedCellTest::GetCurrentCellTest() 81 116 { 82 CPPUNIT_ASSERT_EQUAL( true, true ); 117 // within bounds 118 LC->n[0] = LC->n[1] = LC->n[2] = 0; 119 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0 * 3*3 + 0 * 3 + 0], LC->GetCurrentCell() ); 120 LC->n[0] = LC->n[1] = LC->n[2] = 1; 121 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[1 * 3*3 + 1 * 3 + 1], LC->GetCurrentCell() ); 122 LC->n[0] = LC->n[1] = LC->n[2] = 2; 123 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetCurrentCell() ); 124 125 // out of bounds 126 LC->n[0] = LC->n[1] = LC->n[2] = 3; 127 cout << "The following test is supposed to fail and produce an ERROR." << endl; 128 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() ); 129 LC->n[0] = LC->n[1] = LC->n[2] = -1; 130 cout << "The following test is supposed to fail and produce an ERROR." << endl; 131 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() ); 83 132 }; 84 133 … … 87 136 void LinkedCellTest::GetRelativeToCurrentCellTest() 88 137 { 89 CPPUNIT_ASSERT_EQUAL( true, true ); 138 int offset[3]; 139 140 // offset to (0,0,0) always 141 offset[0] = offset[1] = offset[2] = 0; 142 LC->n[0] = LC->n[1] = LC->n[2] = 0; 143 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) ); 144 offset[0] = offset[1] = offset[2] = -1; 145 LC->n[0] = LC->n[1] = LC->n[2] = 1; 146 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) ); 147 offset[0] = offset[1] = offset[2] = -2; 148 LC->n[0] = LC->n[1] = LC->n[2] = 2; 149 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) ); 150 151 // offset to (0,0,0) - 1.*(x/y/z) out of bounds 152 offset[0] = offset[1] = offset[2] = 0; 153 offset[0] = -1; 154 LC->n[0] = LC->n[1] = LC->n[2] = 0; 155 cout << "The following test is supposed to fail and produce an ERROR." << endl; 156 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) ); 157 offset[0] = offset[1] = offset[2] = 0; 158 offset[1] = -1; 159 LC->n[0] = LC->n[1] = LC->n[2] = 0; 160 cout << "The following test is supposed to fail and produce an ERROR." << endl; 161 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) ); 162 offset[0] = offset[1] = offset[2] = 0; 163 offset[2] = -1; 164 LC->n[0] = LC->n[1] = LC->n[2] = 0; 165 cout << "The following test is supposed to fail and produce an ERROR." << endl; 166 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) ); 167 168 // out of bounds 169 offset[0] = offset[1] = offset[2] = -5054932; 170 LC->n[0] = LC->n[1] = LC->n[2] = 1; 171 cout << "The following test is supposed to fail and produce an ERROR." << endl; 172 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) ); 173 offset[0] = offset[1] = offset[2] = 192345; 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 178 // index is out of bounds, offset points within 179 offset[0] = offset[1] = offset[2] = -2; 180 LC->n[0] = LC->n[1] = LC->n[2] = 4; 181 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetRelativeToCurrentCell(offset) ); 182 183 // index is within bounds, offset points out 184 offset[0] = offset[1] = offset[2] = 2; 185 LC->n[0] = LC->n[1] = LC->n[2] = 2; 186 cout << "The following test is supposed to fail and produce an ERROR." << endl; 187 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) ); 90 188 }; 91 189 … … 95 193 void LinkedCellTest::SetIndexToNodeTest() 96 194 { 97 CPPUNIT_ASSERT_EQUAL( true, true ); 195 // check all atoms 196 atom *Walker = TestMolecule->start; 197 while (Walker->next != TestMolecule->end) { 198 Walker = Walker->next; 199 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) ); 200 } 201 202 // check internal vectors, returns false, because this atom is not in LC-list! 203 Walker = new atom(); 204 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 205 strcpy(Walker->Name, "test"); 206 Walker->x.Init(1,1,1); 207 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 208 delete(Walker); 209 210 // check out of bounds vectors 211 Walker = new atom(); 212 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 213 strcpy(Walker->Name, "test"); 214 Walker->x.Init(0,-1,0); 215 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 216 delete(Walker); 98 217 }; 99 218 … … 103 222 void LinkedCellTest::SetIndexToVectorTest() 104 223 { 105 CPPUNIT_ASSERT_EQUAL( true, true ); 106 }; 107 108 109 /** UnitTest for LinkedCell::CheckBounds(). 110 */ 111 void LinkedCellTest::CheckBoundsTest() 112 { 113 CPPUNIT_ASSERT_EQUAL( true, true ); 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.) { 230 tester.Init(x,y,z); 231 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); 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.) { 237 tester.Init(x,y,z); 238 cout << "Tester is at " << tester << "." << endl; 239 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); 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) { 245 tester.Init(x,y,z); 246 cout << "The following test is supposed to fail and produce an ERROR." << endl; 247 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); 248 } 249 // check nonsense vectors 250 tester.Init(-423598,3245978,29349); 251 cout << "The following test is supposed to fail and produce an ERROR." << endl; 252 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); 114 253 }; 115 254 … … 119 258 void LinkedCellTest::GetNeighbourBoundsTest() 120 259 { 121 CPPUNIT_ASSERT_EQUAL( true, true ); 260 Vector tester; 261 int lower[NDIM], upper[NDIM]; 262 263 tester.Init(0.5,0.5,0.5); 264 LC->SetIndexToVector(&tester); 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]); 122 270 }; 123 271 … … 127 275 void LinkedCellTest::GetallNeighboursTest() 128 276 { 129 CPPUNIT_ASSERT_EQUAL( true, true ); 277 Vector tester; 278 LinkedCell::LinkedNodes *ListOfPoints = NULL; 279 atom *Walker = NULL; 280 size_t size = 0; 281 282 // get all atoms 283 tester.Init(1.5,1.5,1.5); 284 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 285 ListOfPoints = LC->GetallNeighbours(); 286 size = ListOfPoints->size(); 287 CPPUNIT_ASSERT_EQUAL( (size_t)27, size ); 288 Walker = TestMolecule->start; 289 Walker = TestMolecule->start; 290 while (Walker->next != TestMolecule->end) { 291 Walker = Walker->next; 292 ListOfPoints->remove(Walker); 293 size--; 294 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); 295 } 296 CPPUNIT_ASSERT_EQUAL( (size_t)0, size ); 297 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() ); 298 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() ); 299 delete(ListOfPoints); 300 301 // get all atoms in one corner 302 tester.Init(0.5, 0.5, 0.5); 303 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 304 ListOfPoints = LC->GetallNeighbours(); 305 size=ListOfPoints->size(); 306 CPPUNIT_ASSERT_EQUAL( (size_t)8, size ); 307 Walker = TestMolecule->start; 308 while (Walker->next != TestMolecule->end) { 309 Walker = Walker->next; 310 if ((Walker->x.x[0] <2) && (Walker->x.x[1] <2) && (Walker->x.x[2] <2)) { 311 ListOfPoints->remove(Walker); 312 size--; 313 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); 314 } 315 } 316 CPPUNIT_ASSERT_EQUAL( (size_t)0, size ); 317 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() ); 318 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() ); 319 delete(ListOfPoints); 320 321 // get all atoms from one corner 322 tester.Init(0.5, 0.5, 0.5); 323 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 324 ListOfPoints = LC->GetallNeighbours(3); 325 size=ListOfPoints->size(); 326 CPPUNIT_ASSERT_EQUAL( (size_t)27, size ); 327 Walker = TestMolecule->start; 328 while (Walker->next != TestMolecule->end) { 329 Walker = Walker->next; 330 ListOfPoints->remove(Walker); 331 size--; 332 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); 333 } 334 CPPUNIT_ASSERT_EQUAL( (size_t)0, size ); 335 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() ); 336 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() ); 337 delete(ListOfPoints); 130 338 }; 131 339 … … 135 343 void LinkedCellTest::GetPointsInsideSphereTest() 136 344 { 137 CPPUNIT_ASSERT_EQUAL( true, true ); 345 Vector tester; 346 LinkedCell::LinkedNodes *ListOfPoints = NULL; 347 atom *Walker = NULL; 348 size_t size = 0; 349 350 // get all points around central arom with radius 1. 351 tester.Init(1.5,1.5,1.5); 352 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 353 ListOfPoints = LC->GetPointsInsideSphere(1., &tester); 354 size = ListOfPoints->size(); 355 CPPUNIT_ASSERT_EQUAL( (size_t)7, size ); 356 Walker = TestMolecule->start; 357 while (Walker->next != TestMolecule->end) { 358 Walker = Walker->next; 359 if ((Walker->x.DistanceSquared(&tester) - 1.) < MYEPSILON ) { 360 ListOfPoints->remove(Walker); 361 size--; 362 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); 363 } 364 } 365 CPPUNIT_ASSERT_EQUAL( (size_t)0, size ); 366 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() ); 367 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() ); 368 delete(ListOfPoints); 138 369 }; 139 370 -
src/unittests/LinkedCellUnitTest.hpp
ra3696f r4f9e47 22 22 { 23 23 CPPUNIT_TEST_SUITE( LinkedCellTest) ; 24 CPPUNIT_TEST ( CheckBoundsTest ); 24 25 CPPUNIT_TEST ( GetCurrentCellTest ); 25 26 CPPUNIT_TEST ( GetRelativeToCurrentCellTest ); 26 27 CPPUNIT_TEST ( SetIndexToNodeTest ); 27 28 CPPUNIT_TEST ( SetIndexToVectorTest ); 28 CPPUNIT_TEST ( CheckBoundsTest );29 29 CPPUNIT_TEST ( GetNeighbourBoundsTest ); 30 CPPUNIT_TEST ( Get NeighbourBoundsTest );30 CPPUNIT_TEST ( GetallNeighboursTest ); 31 31 CPPUNIT_TEST ( GetPointsInsideSphereTest ); 32 32 CPPUNIT_TEST_SUITE_END();
Note:
See TracChangeset
for help on using the changeset viewer.