Index: src/Graph/CheckAgainstAdjacencyFile.cpp
===================================================================
--- src/Graph/CheckAgainstAdjacencyFile.cpp	(revision 5fd0f4d49b0461d32ede06c7157852e0fb66eb04)
+++ src/Graph/CheckAgainstAdjacencyFile.cpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -28,61 +28,29 @@
 #include "CodePatterns/Assert.hpp"
 #include "CodePatterns/Log.hpp"
-#include "CodePatterns/Verbose.hpp"
+#include "CodePatterns/Range.hpp"
+#include "Descriptors/AtomIdDescriptor.hpp"
 #include "Helpers/defs.hpp"
-
-CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile() :
-  CurrentBonds(new int[MAXBONDS]),
+#include "World.hpp"
+
+CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd) :
   status(true),
   NonMatchNumber(0)
 {
-  for(int i=0;i<MAXBONDS;i++)
-    CurrentBonds[i] = 0;
+  CreateInternalMap(AtomMapBegin, AtomMapEnd);
 }
 
 CheckAgainstAdjacencyFile::~CheckAgainstAdjacencyFile()
 {
-  delete[](CurrentBonds);
-}
-
-void CheckAgainstAdjacencyFile::CompareBonds(const atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, std::map<int, atom*> &ListOfAtoms)
-{
-  size_t j = 0;
-  int id = -1;
-
-  //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
-  const BondList& ListOfBonds = Walker->getListOfBonds();
-  if (CurrentBondsOfAtom == ListOfBonds.size()) {
-    for (BondList::const_iterator Runner = ListOfBonds.begin();
-        Runner != ListOfBonds.end();
-        ++Runner) {
-      id = (*Runner)->GetOtherAtom(Walker)->getNr();
-      j = 0;
-      for (; (j < CurrentBondsOfAtom) && (CurrentBonds[j++] != id);)
-        ; // check against all parsed bonds
-      if (CurrentBonds[j - 1] != id) { // no match ? Then mark in ListOfAtoms
-        ListOfAtoms[AtomNr] = NULL;
-        NonMatchNumber++;
-        status = false;
-        ELOG(2, id << " can not be found in list." << endl);
-      } else {
-        //Log() << Verbose(0) << "[" << id << "]\t";
-      }
-    }
-    //Log() << Verbose(0) << endl;
-  } else {
-    LOG(0, "STATUS: Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << ListOfBonds.size() << ".");
-    status = false;
-  }
-}
-;
-
-/** Checks contents of adjacency file against bond structure in structure molecule.
- * \param File file to parser
- * \param ListOfAtoms map from int (index in file) to atom
- * \return true - structure is equal, false - not equivalence
- */
-bool CheckAgainstAdjacencyFile::operator()(std::ifstream &File, std::map<int, atom*> ListOfAtoms)
-{
-  LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... ");
+  ExternalAtomBondMap.clear();
+  InternalAtomBondMap.clear();
+}
+
+/** Parses the bond partners of each atom from an external file into \a AtomBondMap.
+ *
+ * @param File file to parse
+ * @return true - everything ok, false - error while parsing
+ */
+bool CheckAgainstAdjacencyFile::ParseInExternalMap(std::istream &File)
+{
   if (File.fail()) {
     LOG(1, "STATUS: Adjacency file not found." << endl);
@@ -90,4 +58,5 @@
   }
 
+  ExternalAtomBondMap.clear();
   char buffer[MAXSTRINGSIZE];
   int tmp;
@@ -99,25 +68,65 @@
     int AtomNr = -1;
     line >> AtomNr;
-    size_t CurrentBondsOfAtom = -1; // we count one too far due to line end
     // parse into structure
     if (AtomNr >= 0) {
-      ASSERT(ListOfAtoms.count(AtomNr),
-          "CheckAgainstAdjacencyFile::operator() - index "
-          +toString(AtomNr)+" not present in ListOfAtoms.");
-      const atom *Walker = ListOfAtoms[AtomNr];
+      const atom *Walker = World::getInstance().getAtom(AtomById(AtomNr));
+      ASSERT(Walker != NULL,
+          "CheckAgainstAdjacencyFile::ParseInExternalMap() - there is no atom with id "+toString(AtomNr)+".");
+      if (Walker == NULL)
+        return false;
+      // parse bond partner ids associated to AtomNr
       while (line >> ws >> tmp) {
         LOG(3, "INFO: Recognized bond partner " << tmp);
-        CurrentBonds[++CurrentBondsOfAtom] = tmp;
-        ASSERT(CurrentBondsOfAtom < MAXBONDS,
-            "molecule::CheckAdjacencyFileAgainstMolecule() - encountered more bonds than allowed: "
-            +toString(CurrentBondsOfAtom)+" >= "+toString(int(MAXBONDS))+"!");
+        ExternalAtomBondMap.insert( std::make_pair(AtomNr, tmp) );
       }
-      // compare against present bonds
-      CompareBonds(Walker, CurrentBondsOfAtom, AtomNr, ListOfAtoms);
     } else {
-      if (AtomNr != -1)
+      if (AtomNr != -1) {
         ELOG(2, AtomNr << " is negative.");
+        return false;
+      }
     }
   }
+  return true;
+}
+
+/** Fills the InternalAtomBondMap from the atoms given by the two iterators.
+ *
+ * @param AtomMapBegin iterator pointing to begin of map (think of World's SelectionIterator)
+ * @param AtomMapEnd iterator pointing past end of map (think of World's SelectionIterator)
+ */
+void CheckAgainstAdjacencyFile::CreateInternalMap(World::AtomSet::const_iterator &AtomMapBegin, World::AtomSet::const_iterator &AtomMapEnd)
+{
+  InternalAtomBondMap.clear();
+  // go through each atom in the list
+  for (World::AtomSet::const_iterator iter = AtomMapBegin; iter != AtomMapEnd; ++iter) {
+    const atom *Walker = iter->second;
+    const atomId_t WalkerId = Walker->getId();
+    ASSERT(WalkerId != (size_t)-1,
+        "CheckAgainstAdjacencyFile::CreateInternalMap() - Walker has no id.");
+    const BondList& ListOfBonds = Walker->getListOfBonds();
+    // go through each of its bonds
+    for (BondList::const_iterator Runner = ListOfBonds.begin();
+        Runner != ListOfBonds.end();
+        ++Runner) {
+      const atomId_t id = (*Runner)->GetOtherAtom(Walker)->getId();
+      ASSERT(id != (size_t)-1,
+          "CheckAgainstAdjacencyFile::CreateInternalMap() - OtherAtom has not id.");
+      InternalAtomBondMap.insert( std::make_pair(WalkerId, id) );
+    }
+  }
+}
+
+/** Checks contents of adjacency file against bond structure in structure molecule.
+ * \param File file to parser
+ * \return true - structure is equal, false - not equivalence
+ */
+bool CheckAgainstAdjacencyFile::operator()(std::istream &File)
+{
+  LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... ");
+
+  bool status = true;
+
+  status = status && ParseInExternalMap(File);
+  status = status && CompareInternalExternalMap();
 
   if (status) { // if equal we parse the KeySetFile
@@ -127,3 +136,106 @@
   return status;
 }
-;
+
+template <class T>
+CheckAgainstAdjacencyFile::KeysSet getKeys(const CheckAgainstAdjacencyFile::AtomBondRange &_range)
+{
+  CheckAgainstAdjacencyFile::KeysSet Keys;
+  for (typename T::const_iterator iter = _range.first;
+      iter != _range.second;
+      ++iter) {
+    Keys.insert( iter->first );
+  }
+  return Keys;
+}
+
+template <class T>
+CheckAgainstAdjacencyFile::ValuesSet getValues(const CheckAgainstAdjacencyFile::AtomBondRange&_range)
+{
+  CheckAgainstAdjacencyFile::ValuesSet Values;
+  for (typename T::const_iterator iter = _range.first;
+      iter != _range.second;
+      ++iter) {
+    Values.insert( iter->second );
+  }
+  return Values;
+}
+
+/** Counts the number of mismatching items in each set.
+ *
+ * @param firstset first set
+ * @param secondset second set
+ * @return number of items that don't match between first and second set
+ */
+template <class T>
+size_t getMismatchingItems(const T &firstset, const T &secondset)
+{
+  size_t Mismatch = 0;
+  typename T::const_iterator firstiter = firstset.begin();
+  typename T::const_iterator seconditer = secondset.begin();
+  for (; (firstiter != firstset.end()) && (seconditer != secondset.end());
+      ++firstiter, ++seconditer) {
+    if (*firstiter != *seconditer)
+      ++Mismatch;
+  }
+  return Mismatch;
+}
+
+/** Compares InternalAtomBondMap and ExternalAtomBondMap and sets NonMatchNumber.
+ *
+ * @return true - both maps are the same, false - both maps diverge by NonMatchNumber counts.
+ */
+bool CheckAgainstAdjacencyFile::CompareInternalExternalMap()
+{
+  NonMatchNumber = 0;
+  // check whether sizes match
+  if (ExternalAtomBondMap.size() != InternalAtomBondMap.size()) {
+    NonMatchNumber = abs((int)ExternalAtomBondMap.size() - (int)InternalAtomBondMap.size());
+    LOG(2, "INFO: " << NonMatchNumber << " entries don't match.");
+    return false;
+  }
+  // extract keys and check whether they match
+  const AtomBondRange Intrange(InternalAtomBondMap.begin(), InternalAtomBondMap.end());
+  const AtomBondRange Extrange(ExternalAtomBondMap.begin(), ExternalAtomBondMap.end());
+  KeysSet InternalKeys( getKeys<AtomBondMap>(Intrange) );
+  KeysSet ExternalKeys( getKeys<AtomBondMap>(Extrange) );
+
+//  std::cout << "InternalKeys: " << InternalKeys << std::endl;
+//  std::cout << "ExternalKeys: " << ExternalKeys << std::endl;
+
+  // check for same amount of keys
+  if (InternalKeys.size() != ExternalKeys.size()) {
+    NonMatchNumber = abs((int)ExternalKeys.size() - (int)InternalKeys.size());
+    LOG(2, "INFO: Number of keys don't match: "
+        << InternalKeys.size() << " != " << ExternalKeys.size());
+    return false;
+  }
+
+  // check items against one another
+  NonMatchNumber = getMismatchingItems(InternalKeys, ExternalKeys);
+
+  if (NonMatchNumber != 0) {
+    LOG(2, "INFO: " << NonMatchNumber << " keys are not the same.");
+    return false;
+  }
+
+  // now check each map per key
+  for (KeysSet::const_iterator keyIter = InternalKeys.begin();
+      keyIter != InternalKeys.end();
+      ++keyIter) {
+//    std::cout << "Current key is " << *keyIter << std::endl;
+    const AtomBondRange IntRange( InternalAtomBondMap.equal_range(*keyIter) );
+    const AtomBondRange ExtRange( ExternalAtomBondMap.equal_range(*keyIter) );
+    ValuesSet InternalValues( getValues<AtomBondMap>(IntRange) );
+    ValuesSet ExternalValues( getValues<AtomBondMap>(ExtRange) );
+//    std::cout << "InternalValues: " << InternalValues << std::endl;
+//    std::cout << "ExternalValues: " << ExternalValues << std::endl;
+    NonMatchNumber += getMismatchingItems(InternalValues, ExternalValues);
+  }
+  if (NonMatchNumber != 0) {
+    LOG(2, "INFO: " << NonMatchNumber << " keys are not the same.");
+    return false;
+  } else {
+    LOG(2, "INFO: All keys are the same.");
+    return true;
+  }
+}
Index: src/Graph/CheckAgainstAdjacencyFile.hpp
===================================================================
--- src/Graph/CheckAgainstAdjacencyFile.hpp	(revision 5fd0f4d49b0461d32ede06c7157852e0fb66eb04)
+++ src/Graph/CheckAgainstAdjacencyFile.hpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -16,4 +16,8 @@
 #include <iosfwd>
 #include <map>
+#include <set>
+
+#include "types.hpp"
+#include "World.hpp"
 
 class atom;
@@ -21,18 +25,26 @@
 class CheckAgainstAdjacencyFile
 {
+  //!> Unit test is granted access to internal data
+  friend class CheckAgainstAdjacencyFileTest;
 public:
-  CheckAgainstAdjacencyFile();
+  CheckAgainstAdjacencyFile(World::AtomSet::const_iterator AtomMapBegin, World::AtomSet::const_iterator AtomMapEnd);
   ~CheckAgainstAdjacencyFile();
 
-  bool operator()(std::ifstream &File, std::map<int, atom*> ListOfAtoms);
+  bool operator()(std::istream &File);
 
 private:
-  enum {MAXBONDS=8};
-
-  int *CurrentBonds;
+  typedef std::set<atomId_t> KeysSet;
+  typedef std::set<atomId_t> ValuesSet;
+  typedef std::pair<atomId_t, atomId_t> AtomBondPair;
+  typedef std::multimap< atomId_t, atomId_t > AtomBondMap;
+  typedef std::pair<AtomBondMap::const_iterator, AtomBondMap::const_iterator> AtomBondRange;
+  AtomBondMap InternalAtomBondMap;
+  AtomBondMap ExternalAtomBondMap;
   bool status;
   int NonMatchNumber;
 
-  void CompareBonds(const atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, std::map<int, atom*> &ListOfAtoms);
+  void CreateInternalMap(World::AtomSet::const_iterator &AtomMapBegin, World::AtomSet::const_iterator &AtomMapEnd);
+  bool ParseInExternalMap(std::istream &File);
+  bool CompareInternalExternalMap();
 };
 
Index: src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp
===================================================================
--- src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
+++ src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -0,0 +1,236 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2010 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * CheckAgainstAdjacencyFileUnitTest.cpp
+ *
+ *  Created on: Oct 17, 2011
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CheckAgainstAdjacencyFileUnitTest.hpp"
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include <iostream>
+#include <string>
+
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Log.hpp"
+
+#include "atom.hpp"
+#include "Descriptors/AtomDescriptor.hpp"
+#include "Element/element.hpp"
+#include "Element/periodentafel.hpp"
+#include "Graph/CheckAgainstAdjacencyFile.hpp"
+#include "molecule.hpp"
+#include "World.hpp"
+#include "WorldTime.hpp"
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+/********************************************** Test classes **************************************/
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( CheckAgainstAdjacencyFileTest );
+
+static std::string adjacencyfile ="\
+0 1\n\
+1 0 2\n\
+2 1 3\n\
+3 2 4\n\
+4 3 5\n\
+5 4 6\n\
+6 5 7\n\
+7 6 8\n\
+8 7 9\n\
+9 8\n";
+
+static std::string wrongadjacencyfile1 ="\
+0 1\n\
+1 0 2\n\
+3 2 4\n\
+4 3 5\n\
+5 4 6\n\
+6 5 7\n\
+7 6 8\n\
+8 7 9\n\
+9 8\n";
+
+static std::string wrongadjacencyfile2 ="\
+0 1\n\
+1 0 2\n\
+2 1 3\n\
+3 2 4\n\
+4 3 5\n\
+5 4 6\n\
+6 5 7\n\
+7 6 8\n\
+8 7 9\n\
+9 8 10\n\
+10 9";
+
+// set up and tear down
+void CheckAgainstAdjacencyFileTest::setUp()
+{
+  const element *hydrogen = World::getInstance().getPeriode()->FindElement(1);
+  CPPUNIT_ASSERT(hydrogen != NULL);
+
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+
+  TestMolecule = World::getInstance().createMolecule();
+  CPPUNIT_ASSERT(TestMolecule != NULL);
+  for(int i=0;i<ATOM_COUNT;++i){
+    atoms[i]= World::getInstance().createAtom();
+    CPPUNIT_ASSERT(atoms[i] != NULL);
+    atoms[i]->setType(hydrogen);
+    TestMolecule->AddAtom(atoms[i]);
+    atomIds[i]= atoms[i]->getId();
+  }
+  // create linear chain
+  for(int i=0;i<ATOM_COUNT-1;++i){
+    atoms[i]->addBond(WorldTime::getTime(), atoms[i+1]);
+  }
+
+  // create map as it should be
+  for(int i=0;i<ATOM_COUNT;++i) {
+    if (i != 0) // first has only one bond
+      comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i-1]) );
+    if (i != ATOM_COUNT-1) // last has only one bond
+      comparisonMap.insert( std::make_pair(atomIds[i], atomIds[i+1]) );
+  }
+}
+
+void CheckAgainstAdjacencyFileTest::tearDown()
+{
+  comparisonMap.clear();
+
+  // destroy molecule and contained atoms
+  TestMolecule->removeAtomsinMolecule();
+  World::getInstance().destroyMolecule(TestMolecule);
+  // destroy World
+  World::purgeInstance();
+//  logger::purgeInstance();
+//  errorLogger::purgeInstance();
+}
+
+/** Unit tests for CheckAgainstAdjacencyFile::CreateInternalMap().
+ *
+ */
+void CheckAgainstAdjacencyFileTest::CreateInternalMapTest()
+{
+  World::getInstance().selectAllAtoms(AllAtoms());
+  CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
+
+  // check size (it's 8*2 + 2*1 = 18 keys)
+  CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );
+  CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
+
+  // check equality
+  CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );
+//  std::cout << "comparisonMap: " << comparisonMap << std::endl;
+//  std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
+  CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );
+
+  // check non-equality: more
+  comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
+  CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
+  comparisonMap.erase((atomId_t)10);
+
+  // check non-equality: less
+  comparisonMap.erase((atomId_t)9);
+  CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
+}
+
+/** Unit tests for CheckAgainstAdjacencyFile::ParseInExternalMap().
+ *
+ */
+void CheckAgainstAdjacencyFileTest::ParseInExternalMapTest()
+{
+  std::stringstream input(adjacencyfile);
+  World::getInstance().selectAllAtoms(NoAtoms());
+  CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
+  fileChecker.ParseInExternalMap(input);
+
+  // check size (it's 8*2 + 2*1 = 18 keys)
+  CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );
+  CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );
+
+  // check equality
+  CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
+  CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
+
+  // check non-equality: more
+  comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
+  CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
+  comparisonMap.erase((atomId_t)10);
+
+  // check non-equality: less
+  comparisonMap.erase((atomId_t)9);
+  CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
+}
+
+/** Unit tests for CheckAgainstAdjacencyFile::CompareInternalExternalMap().
+ *
+ */
+void CheckAgainstAdjacencyFileTest::CompareInternalExternalMapTest()
+{
+  World::getInstance().selectAllAtoms(AllAtoms());
+  CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
+
+  // assert non-equality before parsing
+  CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() != fileChecker.ExternalAtomBondMap.size() );
+  CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap != fileChecker.ExternalAtomBondMap );
+  CPPUNIT_ASSERT( !fileChecker.CompareInternalExternalMap() );
+
+  // parse
+  std::stringstream input(adjacencyfile);
+  fileChecker.ParseInExternalMap(input);
+
+  // assert equality after parsing
+  CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap.size() == fileChecker.ExternalAtomBondMap.size() );
+  CPPUNIT_ASSERT( fileChecker.InternalAtomBondMap == fileChecker.ExternalAtomBondMap );
+  CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
+}
+
+/** Unit tests for CheckAgainstAdjacencyFile::operator()().
+ *
+ */
+void CheckAgainstAdjacencyFileTest::operatorTest()
+{
+  World::getInstance().selectAllAtoms(AllAtoms());
+  CheckAgainstAdjacencyFile fileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
+  {
+    // parse right
+    std::stringstream input(adjacencyfile);
+    CPPUNIT_ASSERT( fileChecker(input) );
+  }
+  {
+    // parse wrong1
+    std::stringstream input(wrongadjacencyfile1);
+    CPPUNIT_ASSERT( !fileChecker(input) );
+  }
+  {
+    // parse wrong2 (there is no atom 10)
+    std::stringstream input(wrongadjacencyfile2);
+#ifndef NDEBUG
+    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
+    CPPUNIT_ASSERT_THROW( fileChecker(input), Assert::AssertionFailure );
+#else
+    CPPUNIT_ASSERT( !fileChecker(input) );
+#endif
+  }
+}
Index: src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp
===================================================================
--- src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
+++ src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -0,0 +1,54 @@
+/*
+ * CheckAgainstAdjacencyFileUnitTest.hpp
+ *
+ *  Created on: Oct 17, 2011
+ *      Author: heber
+ */
+
+#ifndef CHECKADJACENCYAGAINSTFILEUNITTEST_HPP_
+#define CHECKADJACENCYAGAINSTFILEUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "Graph/CheckAgainstAdjacencyFile.hpp"
+#include "types.hpp"
+
+// we prefer enum over define
+enum { ATOM_COUNT = 10 };
+
+class atom;
+class molecule;
+class World;
+
+class CheckAgainstAdjacencyFileTest : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( CheckAgainstAdjacencyFileTest );
+  CPPUNIT_TEST ( CreateInternalMapTest );
+  CPPUNIT_TEST ( ParseInExternalMapTest );
+  CPPUNIT_TEST ( CompareInternalExternalMapTest );
+  CPPUNIT_TEST ( operatorTest );
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+  void setUp();
+  void tearDown();
+
+  void CreateInternalMapTest();
+  void ParseInExternalMapTest();
+  void CompareInternalExternalMapTest();
+  void operatorTest();
+
+private:
+  CheckAgainstAdjacencyFile::AtomBondMap comparisonMap;
+  atom *atoms [ATOM_COUNT];
+  atomId_t atomIds [ATOM_COUNT];
+  molecule * TestMolecule;
+};
+
+#endif /* CHECKADJACENCYAGAINSTFILEUNITTEST_HPP_ */
Index: src/Graph/unittests/Makefile.am
===================================================================
--- src/Graph/unittests/Makefile.am	(revision 5fd0f4d49b0461d32ede06c7157852e0fb66eb04)
+++ src/Graph/unittests/Makefile.am	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -3,11 +3,15 @@
 
 GRAPHTESTSSOURCES = \
-	../Graph/unittests/BondGraphUnitTest.cpp
+	../Graph/unittests/BondGraphUnitTest.cpp \
+	../Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp
 
 GRAPHTESTSHEADERS = \
-	../Graph/unittests/BondGraphUnitTest.hpp
+	../Graph/unittests/BondGraphUnitTest.hpp \
+	../Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp
 
 GRAPHTESTS = \
-  BondGraphUnitTest
+	BondGraphUnitTest \
+	CheckAgainstAdjacencyFileUnitTest
+
 
 TESTS += $(GRAPHTESTS)
@@ -28,4 +32,9 @@
 BondGraphUnitTest_LDADD = ${GRAPHLIBS}
 
+CheckAgainstAdjacencyFileUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	../Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp \
+	../Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp
+CheckAgainstAdjacencyFileUnitTest_LDADD = ${ALLLIBS}
+
 
 
Index: src/molecule_fragmentation.cpp
===================================================================
--- src/molecule_fragmentation.cpp	(revision 5fd0f4d49b0461d32ede06c7157852e0fb66eb04)
+++ src/molecule_fragmentation.cpp	(revision ec87e45589461e444811eea2933d639a2f8b3e6a)
@@ -659,19 +659,11 @@
   {
     std::ifstream File;
-    string filename;
+    std::string filename;
     filename = prefix + ADJACENCYFILE;
     File.open(filename.c_str(), ios::out);
     DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... " << endl);
-    std::map<int, atom*> ListOfAtoms;
-    std::pair<std::map<int, atom*>::iterator, bool> inserter;
-    for (const_iterator iter = begin();
-        iter != end();
-        ++iter) {
-      atom *Walker = *iter;
-      inserter = ListOfAtoms.insert( make_pair( Walker->GetTrueFather()->getNr(), Walker) );
-      FragmentationToDo = FragmentationToDo && inserter.second;
-    }
-    CheckAgainstAdjacencyFile FileChecker;
-    FragmentationToDo = FragmentationToDo && FileChecker(File, ListOfAtoms);
+
+    CheckAgainstAdjacencyFile FileChecker(World::getInstance().beginAtomSelection(), World::getInstance().endAtomSelection());
+    FragmentationToDo = FragmentationToDo && FileChecker(File);
   }
 
