Changeset 06f41f3 for src/Graph


Ignore:
Timestamp:
Dec 3, 2012, 9:49:30 AM (12 years ago)
Author:
Frederik Heber <heber@…>
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:
9511c7
Parents:
b78dfd
git-author:
Frederik Heber <heber@…> (09/19/12 13:55:43)
git-committer:
Frederik Heber <heber@…> (12/03/12 09:49:30)
Message:

CheckAgainstAdjacencyFile now works on given vector of atomids.

  • added helper function getGlobalIdsFromLocalIds() as we have to translate molecule's internal ids to global atomId_t to check against those in file.
  • TESTFIX: Adapted CheckAgainstAdjacencyFileUnitTest to the changes, also added another test case to operatorTest().
Location:
src/Graph
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/CheckAgainstAdjacencyFile.cpp

    rb78dfd r06f41f3  
    5656 */
    5757CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile(std::istream &File) :
    58   status(true),
    5958  NonMatchNumber(0)
    6059{
    61   ParseInExternalMap(File);
     60  bool status = ParseInInternalMap(File);
     61  if (!status) // remove map if failed to parse
     62    InternalAtomBondMap.clear();
    6263}
    6364
    6465CheckAgainstAdjacencyFile::~CheckAgainstAdjacencyFile()
    65 {
    66   ExternalAtomBondMap.clear();
    67   InternalAtomBondMap.clear();
    68 }
     66{}
    6967
    7068/** Parses the bond partners of each atom from an external file into \a AtomBondMap.
     
    7371 * @return true - everything ok, false - error while parsing
    7472 */
    75 bool CheckAgainstAdjacencyFile::ParseInExternalMap(std::istream &File)
     73bool CheckAgainstAdjacencyFile::ParseInInternalMap(std::istream &File)
    7674{
    7775  if (File.fail()) {
     
    8078  }
    8179
    82   ExternalAtomBondMap.clear();
     80  InternalAtomBondMap.clear();
    8381  char buffer[MAXSTRINGSIZE];
    8482  int tmp;
     
    9391    if (AtomNr > 0) {
    9492      const atom *Walker = World::getInstance().getAtom(AtomById(AtomNr-1));
    95       ASSERT(Walker != NULL,
    96           "CheckAgainstAdjacencyFile::ParseInExternalMap() - there is no atom with id "+toString(AtomNr-1)+".");
    9793      if (Walker == NULL)
    9894        return false;
     95      const atomId_t WalkerId = Walker->getId();
    9996      // parse bond partner ids associated to AtomNr
    10097      while (line >> ws >> tmp) {
    101         LOG(3, "INFO: Recognized bond partner " << tmp-1);
    102         ExternalAtomBondMap.insert( std::make_pair(Walker->getId(), tmp-1) );
     98        LOG(3, "INFO: Recognized bond partner " << tmp-1 << " for " << WalkerId << ".");
     99        InternalAtomBondMap.insert( std::make_pair(WalkerId, tmp-1) );
    103100      }
    104101    } else {
     
    114111/** Fills the InternalAtomBondMap from the atoms given by the two iterators.
    115112 *
    116  * @param AtomMapBegin iterator pointing to begin of map (think of World's SelectionIterator)
    117  * @param AtomMapEnd iterator pointing past end of map (think of World's SelectionIterator)
    118  */
    119 void CheckAgainstAdjacencyFile::CreateInternalMap(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd)
    120 {
    121   InternalAtomBondMap.clear();
     113 * @param atomids set of atomic ids to check (must be global ids, i.e. from atom::getId())
     114 */
     115void CheckAgainstAdjacencyFile::CreateExternalMap(const atomids_t &atomids)
     116{
     117  ExternalAtomBondMap.clear();
    122118  // go through each atom in the list
    123   for (World::AtomSet::const_iterator iter = AtomMapBegin; iter != AtomMapEnd; ++iter) {
    124     const atom *Walker = iter->second;
    125     const atomId_t WalkerId = Walker->getId();
     119  for (atomids_t::const_iterator iter = atomids.begin(); iter != atomids.end(); ++iter) {
     120    const atomId_t WalkerId = *iter;
    126121    ASSERT(WalkerId != (size_t)-1,
    127         "CheckAgainstAdjacencyFile::CreateInternalMap() - Walker has no id.");
     122        "CheckAgainstAdjacencyFile::CreateExternalMap() - Walker has no id.");
     123    const atom *Walker = World::getInstance().getAtom(AtomById(WalkerId));
     124    ASSERT( Walker != NULL,
     125        "CheckAgainstAdjacencyFile::CreateExternalMap() - Walker id "+toString(*iter)
     126        +" is not associated to any of World's atoms.");
    128127    const BondList& ListOfBonds = Walker->getListOfBonds();
    129128    // go through each of its bonds
     
    133132      const atomId_t id = (*Runner)->GetOtherAtom(Walker)->getId();
    134133      ASSERT(id != (size_t)-1,
    135           "CheckAgainstAdjacencyFile::CreateInternalMap() - OtherAtom has not id.");
    136       InternalAtomBondMap.insert( std::make_pair(WalkerId, id) );
     134          "CheckAgainstAdjacencyFile::CreateExternalMap() - OtherAtom has not id.");
     135      ExternalAtomBondMap.insert( std::make_pair(WalkerId, id) );
    137136    }
    138137  }
     
    142141 * \return true - structure is equal, false - not equivalence
    143142 */
    144 bool CheckAgainstAdjacencyFile::operator()(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd)
    145 {
    146   LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... ");
    147 
    148   bool status = true;
    149 
    150   if (InternalAtomBondMap.empty())
    151     CreateInternalMap(AtomMapBegin, AtomMapEnd);
    152 
    153   status = status && CompareInternalExternalMap();
    154 
     143bool CheckAgainstAdjacencyFile::operator()(const atomids_t &atomids)
     144{
     145  LOG(0, "STATUS: Looking at bond structure of given ids and comparing against stored in adjacency file... ");
     146
     147  // parse in external map
     148  CreateExternalMap(atomids);
     149
     150  bool status = CompareInternalExternalMap();
    155151  if (status) { // if equal we parse the KeySetFile
    156152    LOG(0, "STATUS: Equal.");
     
    182178}
    183179
    184 /** Counts the number of mismatching items in each set.
    185  *
    186  * @param firstset first set
    187  * @param secondset second set
    188  * @return number of items that don't match between first and second set
     180/** Counts the number of items in the second set not present in the first set.
     181 *
     182 * \note We assume that the sets are sorted.
     183 *
     184 * @param firstset check set
     185 * @param secondset reference set
     186 * @return number of items in the first set that are missing in the second
    189187 */
    190188template <class T>
    191 size_t getMismatchingItems(const T &firstset, const T &secondset)
     189size_t getMissingItems(const T &firstset, const T &secondset)
    192190{
    193191  size_t Mismatch = 0;
    194192  typename T::const_iterator firstiter = firstset.begin();
    195193  typename T::const_iterator seconditer = secondset.begin();
    196   for (; (firstiter != firstset.end()) && (seconditer != secondset.end());
    197       ++firstiter, ++seconditer) {
    198     if (*firstiter != *seconditer)
    199       ++Mismatch;
     194  for (; (firstiter != firstset.end()) && (seconditer != secondset.end());) {
     195    if (*firstiter > *seconditer)
     196      ++seconditer;
     197    else {
     198      if (*firstiter < *seconditer)
     199        ++Mismatch;
     200      ++firstiter;
     201    }
    200202  }
    201203  return Mismatch;
     
    209211{
    210212  NonMatchNumber = 0;
    211   // check whether sizes match
    212   if (ExternalAtomBondMap.size() != InternalAtomBondMap.size()) {
    213     NonMatchNumber = abs((int)ExternalAtomBondMap.size() - (int)InternalAtomBondMap.size());
    214     LOG(2, "INFO: " << NonMatchNumber << " entries don't match.");
    215     return false;
    216   }
    217213  // extract keys and check whether they match
    218214  const AtomBondRange Intrange(InternalAtomBondMap.begin(), InternalAtomBondMap.end());
     
    225221
    226222  // check for same amount of keys
    227   if (InternalKeys.size() != ExternalKeys.size()) {
    228     NonMatchNumber = abs((int)ExternalKeys.size() - (int)InternalKeys.size());
    229     LOG(2, "INFO: Number of keys don't match: "
    230         << InternalKeys.size() << " != " << ExternalKeys.size());
    231     return false;
    232   }
    233 
    234   // check items against one another
    235   NonMatchNumber = getMismatchingItems(InternalKeys, ExternalKeys);
     223  if (ExternalKeys.size() > InternalKeys.size()) {
     224    NonMatchNumber = (int)ExternalKeys.size() - (int)InternalKeys.size();
     225    LOG(2, "INFO: Number of external keys exceeds internal one by " << NonMatchNumber << ".");
     226    return false;
     227  }
     228
     229  // check which keys are missing in the internal set
     230  NonMatchNumber = getMissingItems(ExternalKeys, InternalKeys);
    236231
    237232  if (NonMatchNumber != 0) {
     
    241236
    242237  // now check each map per key
    243   for (KeysSet::const_iterator keyIter = InternalKeys.begin();
    244       keyIter != InternalKeys.end();
     238  for (KeysSet::const_iterator keyIter = ExternalKeys.begin();
     239      keyIter != ExternalKeys.end();
    245240      ++keyIter) {
    246241//    std::cout << "Current key is " << *keyIter << std::endl;
     
    249244    ValuesSet InternalValues( getValues(IntRange) );
    250245    ValuesSet ExternalValues( getValues(ExtRange) );
     246    // throw out all values not present in ExternalKeys
     247    ValuesSet ExternalValues_temp( ExternalValues );
     248    for(KeysSet::const_iterator iter = ExternalKeys.begin();
     249        iter != ExternalKeys.end(); ++iter)
     250      ExternalValues_temp.erase(*iter);
     251    // all remaining values must be masked out
     252    for (ValuesSet::const_iterator iter = ExternalValues_temp.begin();
     253        iter != ExternalValues_temp.end(); ++iter)
     254      ExternalValues.erase(*iter);
    251255//    std::cout << "InternalValues: " << InternalValues << std::endl;
    252256//    std::cout << "ExternalValues: " << ExternalValues << std::endl;
    253     NonMatchNumber += getMismatchingItems(InternalValues, ExternalValues);
     257    NonMatchNumber += getMissingItems(ExternalValues, InternalValues);
    254258  }
    255259  if (NonMatchNumber != 0) {
  • src/Graph/CheckAgainstAdjacencyFile.hpp

    rb78dfd r06f41f3  
    2323class atom;
    2424
     25/** This class contains the bond structure inside an internal map of atoms which
     26 * each bond neighbor parsed from an external file.
     27 *
     28 * We may compare a subset of atoms against this internal bond structure. It is
     29 * true it is a true subset of the bond structure.
     30 */
    2531class CheckAgainstAdjacencyFile
    2632{
     
    3137  ~CheckAgainstAdjacencyFile();
    3238
    33   bool operator()(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd);
     39  typedef std::vector<atomId_t> atomids_t;
     40
     41  bool operator()(const atomids_t &atoms);
    3442
    3543private:
     
    4149  AtomBondMap InternalAtomBondMap;
    4250  AtomBondMap ExternalAtomBondMap;
    43   bool status;
    4451  int NonMatchNumber;
    4552
     
    4754  ValuesSet getValues(const AtomBondRange&_range) const;
    4855
    49   void CreateInternalMap(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd);
    50   bool ParseInExternalMap(std::istream &File);
     56  void CreateExternalMap(const atomids_t &atoms);
     57  bool ParseInInternalMap(std::istream &File);
    5158  bool CompareInternalExternalMap();
    5259};
  • src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp

    rb78dfd r06f41f3  
    3939#include <cppunit/ui/text/TestRunner.h>
    4040
     41#include <boost/lambda/lambda.hpp>
    4142#include <iostream>
    42 #include <string>
     43#include <iterator>
     44#include <iostream>
     45#include <vector>
    4346
    4447#include "CodePatterns/Assert.hpp"
     
    7679static std::string wrongadjacencyfile1 ="\
    77801 2\n\
    78 2 1 3\n\
    79 4 3 5\n\
     812 1\n\
     824 5\n\
    80835 4 6\n\
    81846 5 7\n\
     
    9810111 10";
    99102
     103static std::string wrongadjacencyfile3 ="\
     1041 2\n\
     1052 1 3\n\
     1063 2 4\n\
     1074 3 5\n\
     1085 4 7\n\
     1096\n\
     1107 5 8\n\
     1118 7 9\n\
     1129 8 10\n\
     11310 9 11\n\
     11411 10";
     115
    100116// set up and tear down
    101117void CheckAgainstAdjacencyFileTest::setUp()
     
    110126  CPPUNIT_ASSERT(TestMolecule != NULL);
    111127  for(int i=0;i<ATOM_COUNT;++i){
    112     atoms[i]= World::getInstance().createAtom();
    113     CPPUNIT_ASSERT(atoms[i] != NULL);
    114     atoms[i]->setType(hydrogen);
    115     TestMolecule->AddAtom(atoms[i]);
    116     atomIds[i]= atoms[i]->getId();
    117   }
     128    atom *_atom = World::getInstance().createAtom();
     129    CPPUNIT_ASSERT(_atom != NULL);
     130    _atom->setType(hydrogen);
     131    TestMolecule->AddAtom(_atom);
     132    atoms.push_back(_atom);
     133    atomIds.push_back(_atom->getId());
     134  }
     135  CPPUNIT_ASSERT_EQUAL( (size_t)ATOM_COUNT, atoms.size());
     136  CPPUNIT_ASSERT_EQUAL( (size_t)ATOM_COUNT, atomIds.size());
    118137  // create linear chain
    119   for(int i=0;i<ATOM_COUNT-1;++i){
     138  for(int i=0;i<ATOM_COUNT-1;++i)
    120139    atoms[i]->addBond(WorldTime::getTime(), atoms[i+1]);
    121   }
    122140
    123141  // create map as it should be
     
    143161}
    144162
    145 /** Unit tests for CheckAgainstAdjacencyFile::CreateInternalMap().
    146  *
    147  */
    148 void CheckAgainstAdjacencyFileTest::CreateInternalMapTest()
     163/** Unit tests for CheckAgainstAdjacencyFile::CreateExternalMap().
     164 *
     165 */
     166void CheckAgainstAdjacencyFileTest::CreateExternalMapTest()
    149167{
    150168  std::stringstream input;
    151169  CheckAgainstAdjacencyFile fileChecker(input);
    152   World::getInstance().selectAllAtoms(AllAtoms());
    153   const World &world = World::getInstance();
    154   fileChecker.CreateInternalMap(world.beginAtomSelection(), world.endAtomSelection());
     170  fileChecker.CreateExternalMap(atomIds);
    155171
    156172  // 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() );
     175
     176  // check equality
     177  CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
     178//  std::cout << "comparisonMap: " << comparisonMap << std::endl;
     179//  std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
     180  CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
     181
     182  // check non-equality: more
     183  comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
     184  CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
     185  comparisonMap.erase((atomId_t)10);
     186
     187  // check non-equality: less
     188  comparisonMap.erase((atomId_t)9);
     189  CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
     190}
     191
     192/** Unit tests for CheckAgainstAdjacencyFile::ParseInInternalMap().
     193 *
     194 */
     195void CheckAgainstAdjacencyFileTest::ParseInInternalMapTest()
     196{
     197  std::stringstream input(adjacencyfile);
     198  CheckAgainstAdjacencyFile fileChecker(input);
     199  std::vector<atomId_t> noids;
     200  fileChecker.CreateExternalMap(noids);
     201
     202  // check size (it's 8*2 + 2*1 = 18 keys)
     203  CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
    157204  CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );
    158   CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
    159205
    160206  // check equality
    161207  CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );
    162 //  std::cout << "comparisonMap: " << comparisonMap << std::endl;
    163 //  std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
    164208  CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );
    165209
     
    174218}
    175219
    176 /** Unit tests for CheckAgainstAdjacencyFile::ParseInExternalMap().
    177  *
    178  */
    179 void CheckAgainstAdjacencyFileTest::ParseInExternalMapTest()
    180 {
    181   std::stringstream input(adjacencyfile);
    182   World::getInstance().selectAllAtoms(NoAtoms());
    183   CheckAgainstAdjacencyFile fileChecker(input);
    184   fileChecker.CreateInternalMap(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
    185 
    186   // check size (it's 8*2 + 2*1 = 18 keys)
    187   CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );
    188   CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );
    189 
    190   // check equality
    191   CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
    192   CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
    193 
    194   // check non-equality: more
    195   comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
    196   CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
    197   comparisonMap.erase((atomId_t)10);
    198 
    199   // check non-equality: less
    200   comparisonMap.erase((atomId_t)9);
    201   CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
    202 }
    203 
    204220/** Unit tests for CheckAgainstAdjacencyFile::CompareInternalExternalMap().
    205221 *
     
    210226  CheckAgainstAdjacencyFile fileChecker(input);
    211227
    212   // assert non-equality before parsing
    213   CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() != fileChecker.ExternalAtomBondMap.size() );
    214   CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap != fileChecker.ExternalAtomBondMap );
    215   CPPUNIT_ASSERT( !fileChecker.CompareInternalExternalMap() );
    216 
    217   // parse
    218   World::getInstance().selectAllAtoms(AllAtoms());
    219   fileChecker.CreateInternalMap(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
     228  // 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() );
     232
     233  // parse in external map
     234  fileChecker.CreateExternalMap(atomIds);
    220235
    221236  // assert equality after parsing
    222   CPPUNIT_ASSERT_EQUAL( fileChecker.InternalAtomBondMap.size(), fileChecker.ExternalAtomBondMap.size() );
    223   CPPUNIT_ASSERT_EQUAL( fileChecker.InternalAtomBondMap, fileChecker.ExternalAtomBondMap );
     237  CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap.size(), fileChecker.InternalAtomBondMap.size() );
     238  CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap, fileChecker.InternalAtomBondMap );
    224239  CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
    225240}
     
    230245void CheckAgainstAdjacencyFileTest::operatorTest()
    231246{
    232   World::getInstance().selectAllAtoms(AllAtoms());
    233247  {
    234248    // parse right
    235249    std::stringstream input(adjacencyfile);
    236250    CheckAgainstAdjacencyFile fileChecker(input);
    237     CPPUNIT_ASSERT( fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection()) );
    238   }
    239   {
    240     // parse wrong1
     251    CPPUNIT_ASSERT( fileChecker(atomIds) );
     252  }
     253  {
     254    // parse wrong1 (more atoms in the world than in file, hence wrong)
    241255    std::stringstream input(wrongadjacencyfile1);
    242256    CheckAgainstAdjacencyFile fileChecker(input);
    243     CPPUNIT_ASSERT( !fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection()) );
    244   }
    245   {
    246     // parse wrong2 (there is no atom 10)
     257    CPPUNIT_ASSERT( !fileChecker(atomIds) );
     258  }
     259  {
     260    // remove third atom (index starts at 0) and test for equality then
     261    std::vector<atomId_t> validids;
     262    std::remove_copy_if(atomIds.begin(), atomIds.end(), std::back_inserter(validids), boost::lambda::_1 == (atomId_t)2);
     263    CPPUNIT_ASSERT_EQUAL( (size_t)ATOM_COUNT-1, validids.size() );
     264    // parse wrong1 (more atoms in the world than in file, hence wrong)
     265    std::stringstream input(wrongadjacencyfile1);
     266    CheckAgainstAdjacencyFile fileChecker(input);
     267    CPPUNIT_ASSERT( fileChecker(validids) );
     268  }
     269  {
     270    // parse wrong2 (there is no atom 10, but present in file. hence true)
    247271    std::stringstream input(wrongadjacencyfile2);
    248 #ifndef NDEBUG
    249     std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    250     CPPUNIT_ASSERT_THROW( CheckAgainstAdjacencyFile fileChecker(input), Assert::AssertionFailure );
    251 #else
    252     CheckAgainstAdjacencyFile fileChecker(input);
    253     CPPUNIT_ASSERT( !fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection()) );
    254 #endif
    255   }
    256 }
     272    CheckAgainstAdjacencyFile fileChecker(input);
     273    CPPUNIT_ASSERT( !fileChecker(atomIds) );
     274  }
     275  {
     276    // parse wrong3 (6 is not connected)
     277    std::stringstream input(wrongadjacencyfile3);
     278    CheckAgainstAdjacencyFile fileChecker(input);
     279    CPPUNIT_ASSERT( !fileChecker(atomIds) );
     280  }
     281}
  • src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp

    rb78dfd r06f41f3  
    3030{
    3131  CPPUNIT_TEST_SUITE( CheckAgainstAdjacencyFileTest );
    32   CPPUNIT_TEST ( CreateInternalMapTest );
    33   CPPUNIT_TEST ( ParseInExternalMapTest );
     32  CPPUNIT_TEST ( CreateExternalMapTest );
     33  CPPUNIT_TEST ( ParseInInternalMapTest );
    3434  CPPUNIT_TEST ( CompareInternalExternalMapTest );
    3535  CPPUNIT_TEST ( operatorTest );
     
    4040  void tearDown();
    4141
    42   void CreateInternalMapTest();
    43   void ParseInExternalMapTest();
     42  void CreateExternalMapTest();
     43  void ParseInInternalMapTest();
    4444  void CompareInternalExternalMapTest();
    4545  void operatorTest();
     
    4747private:
    4848  CheckAgainstAdjacencyFile::AtomBondMap comparisonMap;
    49   atom *atoms [ATOM_COUNT];
    50   atomId_t atomIds [ATOM_COUNT];
     49  std::vector<atom *> atoms;
     50  std::vector<atomId_t> atomIds;
    5151  molecule * TestMolecule;
    5252};
Note: See TracChangeset for help on using the changeset viewer.