Index: src/Fragmentation/Summation/unittests/Makefile.am
===================================================================
--- src/Fragmentation/Summation/unittests/Makefile.am	(revision 063fab36c8b0361e5f0a8e75f076b674379ba00f)
+++ src/Fragmentation/Summation/unittests/Makefile.am	(revision 2df58073c4555585bcb4fd140b1cdabe8e1aae79)
@@ -9,13 +9,16 @@
 FRAGMENTATIONSUMMATIONTESTSSOURCES = \
 	../Fragmentation/unittests/IndexSetUnitTest.cpp \
-	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp
+	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp \
+	../Fragmentation/unittests/SubsetMapUnitTest.cpp
 
 FRAGMENTATIONSUMMATIONTESTSHEADERS = \
 	../Fragmentation/unittests/IndexSetUnitTest.hpp \
-	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp
+	../Fragmentation/unittests/IndexSetContainerUnitTest.cpp \
+	../Fragmentation/unittests/SubsetMapUnitTest.hpp
 
 FRAGMENTATIONSUMMATIONTESTS = \
   IndexSetUnitTest \
-  IndexSetContainerUnitTest
+  IndexSetContainerUnitTest \
+  SubsetMapUnitTest
 
 TESTS += $(FRAGMENTATIONSUMMATIONTESTS)
@@ -44,3 +47,15 @@
 
 
+SubsetMapUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	unittests/SubsetMapUnitTest.cpp \
+	unittests/SubsetMapUnitTest.hpp \
+	IndexSet.cpp \
+	IndexSet.hpp \
+	IndexSetContainer.hpp \
+	SortedVector.hpp \
+	SubsetMap.cpp \
+	SubsetMap.hpp
+	SubsetMapUnitTest_LDADD = ${FRAGMENTATIONSUMMATIONLIBS}
+
+
 #AUTOMAKE_OPTIONS = parallel-tests
Index: src/Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp
===================================================================
--- src/Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp	(revision 2df58073c4555585bcb4fd140b1cdabe8e1aae79)
+++ src/Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp	(revision 2df58073c4555585bcb4fd140b1cdabe8e1aae79)
@@ -0,0 +1,301 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C) 2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * SubsetMapUnitTest.cpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "Fragmentation/Summation/SubsetMap.hpp"
+
+#include "SubsetMapUnitTest.hpp"
+
+#include <boost/assign.hpp>
+#include <boost/foreach.hpp>
+
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Log.hpp"
+#include "CodePatterns/Verbose.hpp"
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+using namespace boost::assign;
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( SubsetMapTest );
+
+
+void SubsetMapTest::setUp()
+{
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+
+  setVerbosity(4);
+
+  allsets.reserve(5);
+  IndexSet tempset;
+  tempset += 1;
+  allsets += tempset;
+  tempset += 2;
+  allsets += tempset;
+  tempset.clear();
+  tempset += 3;
+  allsets += tempset;
+  tempset += 2;
+  allsets += tempset;
+  tempset += 4;
+  allsets += tempset;
+  tempset += 1;
+  allsets += tempset;
+  CPPUNIT_ASSERT_EQUAL( (size_t)6, allsets.size() );
+
+  SM = NULL;
+}
+
+
+void SubsetMapTest::tearDown()
+{
+  allsets.clear();
+  delete SM;
+}
+
+/** UnitTest for getNoPowerSets()
+ */
+void SubsetMapTest::getNoPowerSetsTest()
+{
+  CPPUNIT_ASSERT_EQUAL( (size_t)2, SubsetMap::getNoPowerSets(1) );
+  CPPUNIT_ASSERT_EQUAL( (size_t)4, SubsetMap::getNoPowerSets(2) );
+  CPPUNIT_ASSERT_EQUAL( (size_t)8, SubsetMap::getNoPowerSets(3) );
+  CPPUNIT_ASSERT_EQUAL( (size_t)16, SubsetMap::getNoPowerSets(4) );
+  CPPUNIT_ASSERT_EQUAL( (size_t)32, SubsetMap::getNoPowerSets(5) );
+  CPPUNIT_ASSERT_EQUAL( (size_t)64, SubsetMap::getNoPowerSets(6) );
+}
+
+
+/** UnitTest for getPowerSetIndex()
+ */
+void SubsetMapTest::getPowerSetIndexTest()
+{
+  // we just check here all subsets of order 4 "manually"
+  IndexSet_ptr ptr(new IndexSet(allsets.back()));
+  IndexSet tempset;
+  // subset order 4
+  CPPUNIT_ASSERT_EQUAL( (size_t)(0), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 1;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 2;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  // subset order 3
+  tempset.clear();
+  tempset += 2;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 2;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  // subset order 2
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 2;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 2;
+//  CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  tempset.clear();
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(4), SubsetMap::getPowerSetIndex(ptr, tempset));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
+
+  // subset order 1
+  tempset.clear();
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( (size_t)(8), SubsetMap::getPowerSetIndex(ptr, tempset));
+}
+
+/** UnitTest for getSubset()
+ */
+void SubsetMapTest::getSubsetTest()
+{
+  // we just check here all subsets of order 4 "manually"
+  IndexSet_ptr ptr(new IndexSet(allsets.back()));
+  IndexSet tempset;
+  // subset order 4
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(0) ));
+  tempset += 1;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
+  tempset += 2;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2) ));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 4) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 4 | 8) ));
+
+  // subset order 3
+  tempset.clear();
+  tempset += 2;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4 | 8) ));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4 | 8) ));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
+  tempset += 2;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 8) ));
+
+  // subset order 2
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
+  tempset += 3;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4) ));
+
+  tempset.clear();
+  tempset += 1;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 8) ));
+
+  tempset.clear();
+  tempset += 2;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
+  tempset += 3;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4) ));
+
+  tempset.clear();
+  tempset += 2;
+//  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 8) ));
+
+  tempset.clear();
+  tempset += 3;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(4) ));
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(4 | 8) ));
+
+  // subset order 1
+  tempset.clear();
+  tempset += 4;
+  CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(8) ));
+}
+
+/** UnitTest for gatherSubset()
+ */
+void SubsetMapTest::gatherSubsetTest()
+{
+  /// we create a SubsetMap from an empty container
+  IndexSet tempset;
+  std::vector<IndexSet> sets;
+  sets.push_back(tempset);
+  tempset += 1;
+  sets.push_back(tempset);
+  tempset += 2;
+  sets.push_back(tempset);
+  tempset.clear();
+  tempset += 2;
+  sets.push_back(tempset);
+  IndexSetContainer container( sets );
+  // now we have {}, {1}, {2}, {1,2} in container
+
+  SM = new SubsetMap(container);
+  CPPUNIT_ASSERT( SM != NULL );
+  CPPUNIT_ASSERT_EQUAL( (size_t)4, SM->Lookup.size() );
+  const IndexSetContainer::Container_t &_container = container.getContainer();
+  for (IndexSetContainer::Container_t::const_iterator iter = _container.begin();
+      iter != _container.end(); ++iter) {
+    LOG(1, "INFO: Current set is " << **iter << ".");
+    SubsetMap::Lookup_t::const_iterator lookupiter = SM->Lookup.find(*iter);
+    CPPUNIT_ASSERT( lookupiter != SM->Lookup.end() );
+    CPPUNIT_ASSERT_EQUAL( lookupiter->second->getContainer().size(), SM->getSubsets(*iter)->getContainer().size() );
+    CPPUNIT_ASSERT_EQUAL( (size_t)(( 1 << (*iter)->size()) - 1), lookupiter->second->getContainer().size() );
+  }
+}
Index: src/Fragmentation/Summation/unittests/SubsetMapUnitTest.hpp
===================================================================
--- src/Fragmentation/Summation/unittests/SubsetMapUnitTest.hpp	(revision 2df58073c4555585bcb4fd140b1cdabe8e1aae79)
+++ src/Fragmentation/Summation/unittests/SubsetMapUnitTest.hpp	(revision 2df58073c4555585bcb4fd140b1cdabe8e1aae79)
@@ -0,0 +1,48 @@
+/*
+ * SubsetMapUnitTest.hpp
+ *
+ *  Created on: Jul 3, 2012
+ *      Author: heber
+ */
+
+#ifndef SUBSETMAPUNITTEST_HPP_
+#define SUBSETMAPUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <vector>
+
+#include "IndexSet.hpp"
+#include "SubsetMap.hpp"
+
+/********************************************** Test classes **************************************/
+
+class SubsetMapTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( SubsetMapTest) ;
+    CPPUNIT_TEST ( getNoPowerSetsTest );
+    CPPUNIT_TEST ( getPowerSetIndexTest );
+    CPPUNIT_TEST ( getSubsetTest );
+    CPPUNIT_TEST ( gatherSubsetTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void getNoPowerSetsTest();
+      void getPowerSetIndexTest();
+      void getSubsetTest();
+      void gatherSubsetTest();
+
+private:
+      SubsetMap *SM;
+      std::vector<IndexSet> allsets;
+};
+
+#endif /* SUBSETMAPUNITTEST_HPP_ */
