Index: src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp
===================================================================
--- src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp	(revision 70879889df9c3fa9ecec560fe07215db0e872f09)
+++ src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.cpp	(revision 70879889df9c3fa9ecec560fe07215db0e872f09)
@@ -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 70879889df9c3fa9ecec560fe07215db0e872f09)
+++ src/Graph/unittests/CheckAgainstAdjacencyFileUnitTest.hpp	(revision 70879889df9c3fa9ecec560fe07215db0e872f09)
@@ -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 9317be0fb11b31ce2211407310d3957055993f16)
+++ src/Graph/unittests/Makefile.am	(revision 70879889df9c3fa9ecec560fe07215db0e872f09)
@@ -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}
+
 
 
