Changeset 3aa8a5 for src/Graph/unittests
- Timestamp:
- Dec 3, 2012, 9:50:01 AM (12 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:
- 4694df
- Parents:
- 5197e5
- git-author:
- Frederik Heber <heber@…> (09/21/12 16:22:50)
- git-committer:
- Frederik Heber <heber@…> (12/03/12 09:50:01)
- Location:
- src/Graph/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/unittests/AdjacencyListUnitTest.cpp
r5197e5 r3aa8a5 65 65 CPPUNIT_TEST_SUITE_REGISTRATION( AdjacencyListTest ); 66 66 67 staticstd::string adjacencyfile ="\67 const std::string adjacencyfile ="\ 68 68 1 2\n\ 69 69 2 1 3\n\ … … 77 77 10 9\n"; 78 78 79 staticstd::string wrongadjacencyfile1 ="\79 const std::string wrongadjacencyfile1 ="\ 80 80 1 2\n\ 81 81 2 1\n\ … … 88 88 10 9\n"; 89 89 90 staticstd::string wrongadjacencyfile2 ="\90 const std::string wrongadjacencyfile2 ="\ 91 91 1 2\n\ 92 92 2 1 3\n\ … … 99 99 9 8 10\n\ 100 100 10 9 11\n\ 101 11 10 ";102 103 staticstd::string wrongadjacencyfile3 ="\101 11 10\n"; 102 103 const std::string wrongadjacencyfile3 ="\ 104 104 1 2\n\ 105 105 2 1 3\n\ … … 111 111 8 7 9\n\ 112 112 9 8 10\n\ 113 10 9 11\n\ 114 11 10"; 113 10 9\n"; 115 114 116 115 // set up and tear down … … 167 166 { 168 167 std::stringstream input; 169 AdjacencyList fileChecker(input);170 fileChecker.CreateMap(atomIds, fileChecker.ExternalAtomBondMap);168 AdjacencyList FileAdjacency(input); 169 AdjacencyList WorldAdjacency(atomIds); 171 170 172 171 // check size (it's 8*2 + 2*1 = 18 keys) 173 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );174 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );172 CPPUNIT_ASSERT_EQUAL( (size_t)18, WorldAdjacency.atombondmap.size() ); 173 CPPUNIT_ASSERT_EQUAL( (size_t)0, FileAdjacency.atombondmap.size() ); 175 174 176 175 // check equality 177 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );176 CPPUNIT_ASSERT( comparisonMap.size() == WorldAdjacency.atombondmap.size() ); 178 177 // std::cout << "comparisonMap: " << comparisonMap << std::endl; 179 // std::cout << " fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;180 CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );178 // std::cout << "WorldAdjacency.atombondmap: " << WorldAdjacency.atombondmap << std::endl; 179 CPPUNIT_ASSERT( comparisonMap == WorldAdjacency.atombondmap ); 181 180 182 181 // check non-equality: more 183 182 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) ); 184 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );183 CPPUNIT_ASSERT( comparisonMap != WorldAdjacency.atombondmap ); 185 184 comparisonMap.erase((atomId_t)10); 186 185 187 186 // check non-equality: less 188 187 comparisonMap.erase((atomId_t)9); 189 CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );188 CPPUNIT_ASSERT( comparisonMap != WorldAdjacency.atombondmap ); 190 189 } 191 190 … … 196 195 { 197 196 std::stringstream input(adjacencyfile); 198 AdjacencyList fileChecker(input); 199 std::vector<atomId_t> noids; 200 fileChecker.CreateMap(noids, fileChecker.ExternalAtomBondMap); 197 AdjacencyList FileAdjacency(input); 198 AdjacencyList WorldAdjacency; 201 199 202 200 // check size (it's 8*2 + 2*1 = 18 keys) 203 CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );204 CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );201 CPPUNIT_ASSERT_EQUAL( (size_t)0, WorldAdjacency.atombondmap.size() ); 202 CPPUNIT_ASSERT_EQUAL( (size_t)18, FileAdjacency.atombondmap.size() ); 205 203 206 204 // check equality 207 CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );208 CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );205 CPPUNIT_ASSERT( comparisonMap.size() == FileAdjacency.atombondmap.size() ); 206 CPPUNIT_ASSERT( comparisonMap == FileAdjacency.atombondmap ); 209 207 210 208 // check non-equality: more 211 209 comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) ); 212 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );210 CPPUNIT_ASSERT( comparisonMap != FileAdjacency.atombondmap ); 213 211 comparisonMap.erase((atomId_t)10); 214 212 215 213 // check non-equality: less 216 214 comparisonMap.erase((atomId_t)9); 217 CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );218 } 219 220 /** Unit tests for AdjacencyList:: CompareInternalExternalMap().221 * 222 */ 223 void AdjacencyListTest:: CompareInternalExternalMapTest()215 CPPUNIT_ASSERT( comparisonMap != FileAdjacency.atombondmap ); 216 } 217 218 /** Unit tests for AdjacencyList::StoreToFile(). 219 * 220 */ 221 void AdjacencyListTest::StoreToFileTest() 224 222 { 225 223 std::stringstream input(adjacencyfile); 226 AdjacencyList fileChecker(input); 224 AdjacencyList FileAdjacency(input); 225 226 // check size (it's 8*2 + 2*1 = 18 keys) 227 CPPUNIT_ASSERT_EQUAL( (size_t)18, FileAdjacency.atombondmap.size() ); 228 229 // store to file 230 std::stringstream output; 231 FileAdjacency.StoreToFile(output); 232 CPPUNIT_ASSERT_EQUAL( input.str(), output.str() ); 233 } 234 235 /** Unit tests for AdjacencyList::operator<(). 236 * 237 */ 238 void AdjacencyListTest::operatorGreaterLessTest() 239 { 240 std::stringstream input(adjacencyfile); 241 AdjacencyList FileAdjacency(input); 242 AdjacencyList WorldAdjacency; 243 244 // assert empty set is subset of some filled set (empty sets should always return true) 245 CPPUNIT_ASSERT( FileAdjacency.atombondmap.size() != WorldAdjacency.atombondmap.size() ); 246 CPPUNIT_ASSERT( FileAdjacency.atombondmap != WorldAdjacency.atombondmap ); 247 CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency ); 248 CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) ); 249 250 // parse in external map 251 WorldAdjacency.CreateMap(atomIds); 252 253 // assert equality after parsing 254 CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap.size(), WorldAdjacency.atombondmap.size() ); 255 CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap, WorldAdjacency.atombondmap ); 256 CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency ); 257 CPPUNIT_ASSERT( WorldAdjacency > FileAdjacency ); 258 259 // remove one entry from the world 260 WorldAdjacency.atombondmap.erase((atomId_t)9); 261 CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency ); 262 CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) ); 263 } 264 265 /** Unit tests for AdjacencyList::operator==(). 266 * 267 */ 268 void AdjacencyListTest::operatorEqualTest() 269 { 270 std::stringstream input(adjacencyfile); 271 AdjacencyList FileAdjacency(input); 272 AdjacencyList WorldAdjacency; 227 273 228 274 // assert equality before parsing (empty sets should always return true) 229 CPPUNIT_ASSERT( fileChecker.ExternalAtomBondMap.size() != fileChecker.InternalAtomBondMap.size() );230 CPPUNIT_ASSERT( fileChecker.ExternalAtomBondMap != fileChecker.InternalAtomBondMap );231 CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap());275 CPPUNIT_ASSERT( FileAdjacency.atombondmap.size() != WorldAdjacency.atombondmap.size() ); 276 CPPUNIT_ASSERT( FileAdjacency.atombondmap != WorldAdjacency.atombondmap ); 277 CPPUNIT_ASSERT( WorldAdjacency != FileAdjacency ); 232 278 233 279 // parse in external map 234 fileChecker.CreateMap(atomIds, fileChecker.ExternalAtomBondMap);280 WorldAdjacency.CreateMap(atomIds); 235 281 236 282 // assert equality after parsing 237 CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap.size(), fileChecker.InternalAtomBondMap.size() );238 CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap, fileChecker.InternalAtomBondMap );239 CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap());283 CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap.size(), WorldAdjacency.atombondmap.size() ); 284 CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap, WorldAdjacency.atombondmap ); 285 CPPUNIT_ASSERT( WorldAdjacency == FileAdjacency ); 240 286 } 241 287 … … 245 291 void AdjacencyListTest::CheckAgainstSubsetTest() 246 292 { 293 AdjacencyList WorldAdjacency(atomIds); 247 294 { 248 295 // parse right 249 296 std::stringstream input(adjacencyfile); 250 AdjacencyList fileChecker(input);251 CPPUNIT_ASSERT( fileChecker.CheckAgainstSubset(atomIds) );297 AdjacencyList FileAdjacency(input); 298 CPPUNIT_ASSERT( (WorldAdjacency > FileAdjacency) && (WorldAdjacency < FileAdjacency) ); 252 299 } 253 300 { 254 301 // parse wrong1 (more atoms in the world than in file, hence wrong) 255 302 std::stringstream input(wrongadjacencyfile1); 256 AdjacencyList fileChecker(input);257 CPPUNIT_ASSERT( ! fileChecker.CheckAgainstSubset(atomIds) );303 AdjacencyList FileAdjacency(input); 304 CPPUNIT_ASSERT( !(WorldAdjacency < FileAdjacency) && (WorldAdjacency > FileAdjacency) ); 258 305 } 259 306 { … … 262 309 std::remove_copy_if(atomIds.begin(), atomIds.end(), std::back_inserter(validids), boost::lambda::_1 == (atomId_t)2); 263 310 CPPUNIT_ASSERT_EQUAL( (size_t)ATOM_COUNT-1, validids.size() ); 311 AdjacencyList RestrictedWorldAdjacency(validids); 264 312 // parse wrong1 (more atoms in the world than in file, hence wrong) 265 313 std::stringstream input(wrongadjacencyfile1); 266 AdjacencyList fileChecker(input);267 CPPUNIT_ASSERT( fileChecker.CheckAgainstSubset(validids));314 AdjacencyList FileAdjacency(input); 315 CPPUNIT_ASSERT( RestrictedWorldAdjacency == FileAdjacency ); 268 316 } 269 317 { 270 318 // parse wrong2 (there is no atom 10, but present in file. hence true) 271 319 std::stringstream input(wrongadjacencyfile2); 272 AdjacencyList fileChecker(input);273 CPPUNIT_ASSERT( ! fileChecker.CheckAgainstSubset(atomIds) );274 } 275 { 276 // parse wrong3 (6 is not connected)320 AdjacencyList FileAdjacency(input); 321 CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) && (WorldAdjacency < FileAdjacency) ); 322 } 323 { 324 // parse wrong3 (6 is skipped in connection, hence neither is subset) 277 325 std::stringstream input(wrongadjacencyfile3); 278 AdjacencyList fileChecker(input); 279 CPPUNIT_ASSERT( !fileChecker.CheckAgainstSubset(atomIds) ); 280 } 281 } 326 AdjacencyList FileAdjacency(input); 327 // WorldAdjacency.StoreToFile((std::ostream &)std::cout); 328 // FileAdjacency.StoreToFile((std::ostream &)std::cout); 329 CPPUNIT_ASSERT( WorldAdjacency != FileAdjacency ); 330 } 331 } -
src/Graph/unittests/AdjacencyListUnitTest.hpp
r5197e5 r3aa8a5 32 32 CPPUNIT_TEST ( CreateMapTest ); 33 33 CPPUNIT_TEST ( ParseIntoMapTest ); 34 CPPUNIT_TEST ( CompareInternalExternalMapTest ); 34 CPPUNIT_TEST ( StoreToFileTest ); 35 CPPUNIT_TEST ( operatorGreaterLessTest ); 36 CPPUNIT_TEST ( operatorEqualTest ); 35 37 CPPUNIT_TEST ( CheckAgainstSubsetTest ); 36 38 CPPUNIT_TEST_SUITE_END(); … … 42 44 void CreateMapTest(); 43 45 void ParseIntoMapTest(); 44 void CompareInternalExternalMapTest(); 46 void StoreToFileTest(); 47 void operatorGreaterLessTest(); 48 void operatorEqualTest(); 45 49 void CheckAgainstSubsetTest(); 46 50
Note:
See TracChangeset
for help on using the changeset viewer.