/* * atomsCalculationTest.cpp * * Created on: Feb 19, 2010 * Author: crueger */ #include "atomsCalculationTest.hpp" #include #include #include #include #include #include "Descriptors/AtomDescriptor.hpp" #include "Descriptors/AtomIdDescriptor.hpp" #include "Actions/AtomsCalculation.hpp" #include "Actions/AtomsCalculation_impl.hpp" #include "Actions/ActionRegistry.hpp" #include "World.hpp" #include "World_calculations.hpp" #include "atom.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest ); // set up and tear down void atomsCalculationTest::setUp(){ World::getInstance(); for(int i=0;igetId(); } } void atomsCalculationTest::tearDown(){ World::purgeInstance(); ActionRegistry::purgeInstance(); } // some helper functions static bool hasAllIds(std::vector atoms,atomId_t ids[ATOM_COUNT], std::set excluded = std::set()){ for(int i=0;i::iterator iter; bool res=false; for(iter=atoms.begin();iter!=atoms.end();++iter){ res |= (*iter) == id; } if(!res) { cout << "Atom " << id << " missing in returned list" << endl; return false; } } } return true; } static bool hasNoDuplicates(std::vector ids){ std::set found; std::vector::iterator iter; for(iter=ids.begin();iter!=ids.end();++iter){ int id = (*iter); if(found.count(id)) return false; found.insert(id); } return true; } void atomsCalculationTest::testCalculateSimple(){ AtomsCalculation *calc = World::getInstance().calcOnAtoms(boost::bind(&atom::getId,_1),"FOO",AllAtoms()); std::vector allIds = (*calc)(); CPPUNIT_ASSERT(hasAllIds(allIds,atomIds)); CPPUNIT_ASSERT(hasNoDuplicates(allIds)); } void atomsCalculationTest::testCalculateExcluded(){ atomId_t excluded = atomIds[ATOM_COUNT/2]; AtomsCalculation *calc = World::getInstance().calcOnAtoms(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded)); std::vector allIds = (*calc)(); std::set excluded_set; excluded_set.insert(excluded); CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set)); CPPUNIT_ASSERT(hasNoDuplicates(allIds)); CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size()); }