- 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
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Graph/AdjacencyList.cpp
r5197e5 r3aa8a5 55 55 * \param File file to parser 56 56 */ 57 AdjacencyList::AdjacencyList(std::istream &File) : 58 NonMatchNumber(0) 59 { 60 bool status = ParseIntoMap(File, InternalAtomBondMap); 57 AdjacencyList::AdjacencyList(std::istream &File) 58 { 59 bool status = ParseFromFile(File); 60 ASSERT( status, 61 "AdjacencyList::AdjacencyList() - File's contents was nor parsable"); 61 62 if (!status) // remove map if failed to parse 62 InternalAtomBondMap.clear(); 63 atombondmap.clear(); 64 } 65 66 /** Constructor of class AdjacencyList. 67 * 68 * \param File file to parser 69 */ 70 AdjacencyList::AdjacencyList(const atomids_t &atomids) 71 { 72 CreateMap(atomids); 63 73 } 64 74 … … 66 76 {} 67 77 68 /** Parses the bond partners of each atom from an external file into \aatombondmap.78 /** Parses the bond partners of each atom from an external file into AdjacencyList::atombondmap. 69 79 * 70 80 * @param File file to parse 71 * @param &atombondmap map to parse into72 81 * @return true - everything ok, false - error while parsing 73 82 */ 74 bool AdjacencyList::Parse IntoMap(std::istream &File, AtomBondMap &atombondmap)83 bool AdjacencyList::ParseFromFile(std::istream &File) 75 84 { 76 85 if (File.fail()) { … … 83 92 int tmp; 84 93 // Parse the file line by line and count the bonds 85 while ( !File.eof()) {94 while (File.good()) { 86 95 File.getline(buffer, MAXSTRINGSIZE); 87 96 stringstream line; … … 91 100 // parse into structure 92 101 if (AtomNr > 0) { 93 const atom *Walker = World::getInstance().getAtom(AtomById(AtomNr-1)); 94 if (Walker == NULL) 95 return false; 96 const atomId_t WalkerId = Walker->getId(); 102 const atomId_t WalkerId = AtomNr-1; 97 103 // parse bond partner ids associated to AtomNr 98 104 while (line >> ws >> tmp) { … … 110 116 } 111 117 112 /** Fills the InternalAtomBondMap from the atoms given by the two iterators. 113 * 114 * @param &atombondmap map to create 118 /** Fills the AdjacencyList::atombondmap from the atoms given by the two iterators. 119 * 115 120 * @param atomids set of atomic ids to check (must be global ids, i.e. from atom::getId()) 116 121 */ 117 void AdjacencyList::CreateMap( const atomids_t &atomids, AtomBondMap &atombondmap)122 void AdjacencyList::CreateMap(atomids_t atomids) 118 123 { 119 124 atombondmap.clear(); 125 std::sort(atomids.begin(), atomids.end()); 120 126 // go through each atom in the list 121 127 for (atomids_t::const_iterator iter = atomids.begin(); iter != atomids.end(); ++iter) { … … 135 141 ASSERT(id != (size_t)-1, 136 142 "AdjacencyList::CreateMap() - OtherAtom has not id."); 137 atombondmap.insert( std::make_pair(WalkerId, id) ); 138 } 139 } 140 } 141 142 /** Checks contents of adjacency file against bond structure in structure molecule. 143 * \return true - structure is equal, false - not equivalence 144 */ 145 bool AdjacencyList::CheckAgainstSubset(const atomids_t &atomids) 146 { 147 LOG(0, "STATUS: Looking at bond structure of given ids and comparing against stored in adjacency file... "); 148 149 // parse in external map 150 CreateMap(atomids, ExternalAtomBondMap); 151 152 bool status = CompareInternalExternalMap(); 153 if (status) { // if equal we parse the KeySetFile 154 LOG(0, "STATUS: Equal."); 155 } else 156 LOG(0, "STATUS: Not equal by " << NonMatchNumber << " atoms."); 157 return status; 143 if (std::binary_search(atomids.begin(), atomids.end(), id)) 144 atombondmap.insert( std::make_pair(WalkerId, id) ); 145 } 146 } 158 147 } 159 148 … … 206 195 } 207 196 208 /** Compares InternalAtomBondMap and ExternalAtomBondMap and sets NonMatchNumber. 209 * 210 * @return true - both maps are the same, false - both maps diverge by NonMatchNumber counts. 211 */ 212 bool AdjacencyList::CompareInternalExternalMap() 213 { 214 NonMatchNumber = 0; 197 /** Compares whether AdjacencyList::atombondmap in this instance is a subset of 198 * the one in \a other. 199 * 200 * @param other other instance of an adjacency list to compare against 201 * @return true - this atombondmap is subset, false - else 202 */ 203 bool AdjacencyList::operator<(const AdjacencyList &other) const 204 { 205 int NonMatchNumber = 0; 215 206 // extract keys and check whether they match 216 const AtomBondRange Intrange( InternalAtomBondMap.begin(), InternalAtomBondMap.end());217 const AtomBondRange Extrange( ExternalAtomBondMap.begin(), ExternalAtomBondMap.end());207 const AtomBondRange Intrange(atombondmap.begin(), atombondmap.end()); 208 const AtomBondRange Extrange(other.atombondmap.begin(), other.atombondmap.end()); 218 209 KeysSet InternalKeys( getKeys(Intrange) ); 219 210 KeysSet ExternalKeys( getKeys(Extrange) ); … … 222 213 // std::cout << "ExternalKeys: " << ExternalKeys << std::endl; 223 214 224 // check for sameamount of keys225 if (ExternalKeys.size() >InternalKeys.size()) {226 NonMatchNumber = (int) ExternalKeys.size() - (int)InternalKeys.size();227 LOG(2, "INFO: Number of external keys exceeds internal one by " << NonMatchNumber << ".");215 // check amount of keys 216 if (ExternalKeys.size() < InternalKeys.size()) { 217 NonMatchNumber = (int)InternalKeys.size() - (int)ExternalKeys.size(); 218 LOG(2, "INFO: Number of internal keys exceeds external one by " << NonMatchNumber << "."); 228 219 return false; 229 220 } 230 221 231 222 // check which keys are missing in the internal set 232 NonMatchNumber = getMissingItems( ExternalKeys, InternalKeys);223 NonMatchNumber = getMissingItems(InternalKeys, ExternalKeys); 233 224 234 225 if (NonMatchNumber != 0) { … … 238 229 239 230 // now check each map per key 240 for (KeysSet::const_iterator keyIter = ExternalKeys.begin();241 keyIter != ExternalKeys.end();231 for (KeysSet::const_iterator keyIter = InternalKeys.begin(); 232 keyIter != InternalKeys.end(); 242 233 ++keyIter) { 243 234 // std::cout << "Current key is " << *keyIter << std::endl; 244 const AtomBondRange IntRange( InternalAtomBondMap.equal_range(*keyIter) );245 const AtomBondRange ExtRange( ExternalAtomBondMap.equal_range(*keyIter) );235 const AtomBondRange IntRange( atombondmap.equal_range(*keyIter) ); 236 const AtomBondRange ExtRange( other.atombondmap.equal_range(*keyIter) ); 246 237 ValuesSet InternalValues( getValues(IntRange) ); 247 238 ValuesSet ExternalValues( getValues(ExtRange) ); 248 239 // throw out all values not present in ExternalKeys 249 240 ValuesSet ExternalValues_temp( ExternalValues ); 250 for(KeysSet::const_iterator iter = ExternalKeys.begin();251 iter != ExternalKeys.end(); ++iter)241 for(KeysSet::const_iterator iter = InternalKeys.begin(); 242 iter != InternalKeys.end(); ++iter) 252 243 ExternalValues_temp.erase(*iter); 253 244 // all remaining values must be masked out … … 257 248 // std::cout << "InternalValues: " << InternalValues << std::endl; 258 249 // std::cout << "ExternalValues: " << ExternalValues << std::endl; 259 NonMatchNumber += getMissingItems( ExternalValues, InternalValues);250 NonMatchNumber += getMissingItems(InternalValues, ExternalValues); 260 251 } 261 252 if (NonMatchNumber != 0) { … … 267 258 } 268 259 } 260 261 /** Storing the bond structure of a molecule to file. 262 * Simply stores Atom::Nr and then the Atom::Nr of all bond partners per line. 263 * @param File output stream to write to 264 * \return true - file written successfully, false - writing failed 265 */ 266 bool AdjacencyList::StoreToFile(std::ostream &File) const 267 { 268 bool status = true; 269 std::stringstream output; 270 output << "Saving adjacency list ... "; 271 if (!File.bad()) { 272 //File << "m\tn" << endl; 273 AtomBondMap::const_iterator advanceiter = atombondmap.begin(); 274 for (AtomBondMap::const_iterator iter = atombondmap.begin(); 275 iter != atombondmap.end(); 276 iter = advanceiter) { 277 advanceiter = atombondmap.upper_bound(iter->first); 278 File << iter->first+1; 279 for (AtomBondMap::const_iterator adjacencyiter = iter; 280 adjacencyiter != advanceiter; 281 ++adjacencyiter) 282 File << " " << adjacencyiter->second+1; 283 File << std::endl; 284 } 285 output << "done."; 286 } else { 287 output << "given stream is not good."; 288 status = false; 289 } 290 LOG(1, output.str()); 291 292 return status; 293 } -
src/Graph/AdjacencyList.hpp
r5197e5 r3aa8a5 37 37 typedef std::vector<atomId_t> atomids_t; 38 38 39 /** Default constructor for class AdjacencyList. 40 * 41 * We simply have an empty adjacency list here. 42 */ 43 AdjacencyList() {} 39 44 AdjacencyList(std::istream &File); 40 45 AdjacencyList(const atomids_t &atoms); 41 46 ~AdjacencyList(); 42 47 43 bool CheckAgainstSubset(const atomids_t &atoms); 48 bool operator<(const AdjacencyList &other) const; 49 50 /** Comparison operator whether this adjacency list is a subset of \a other. 51 * 52 * @return true - is subset, false - is not subset 53 */ 54 bool operator>(const AdjacencyList &other) const { 55 return other < *this; 56 } 57 /** Equality operator, determines whether both adjacencies are the same. 58 * 59 * @return true - both are the same, false - at least one is not a subset of the other 60 */ 61 bool operator==(const AdjacencyList &other) const { 62 return (other < *this) && (*this < other); 63 } 64 /** Inquality operator, determines whether both adjacencies are not equal. 65 * 66 * @return true - both are not equal, false - both are the subset of one another 67 */ 68 bool operator!=(const AdjacencyList &other) const { 69 return !(*this == other); 70 } 71 72 /** Stores the adjacency contained in this instance to file. 73 * 74 * @param File stream to write to 75 * @return true - File is good, false - else 76 */ 77 bool StoreToFile(std::ostream &File) const; 44 78 45 79 private: … … 49 83 typedef std::multimap< atomId_t, atomId_t > AtomBondMap; 50 84 typedef std::pair<AtomBondMap::const_iterator, AtomBondMap::const_iterator> AtomBondRange; 51 AtomBondMap InternalAtomBondMap; 52 AtomBondMap ExternalAtomBondMap; 53 int NonMatchNumber; 85 AtomBondMap atombondmap; 54 86 55 87 KeysSet getKeys(const AtomBondRange &_range) const; 56 88 ValuesSet getValues(const AtomBondRange&_range) const; 57 89 58 void CreateMap(const atomids_t &atoms, AtomBondMap &atombondmap); 59 bool ParseIntoMap(std::istream &File, AtomBondMap &atombondmap); 60 bool CompareInternalExternalMap(); 90 void CreateMap(atomids_t atoms); 91 bool ParseFromFile(std::istream &File); 61 92 }; 62 93 -
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.