Changeset 5dba7a for molecuilder/src/unittests/atomsCalculationTest.cpp
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/unittests/atomsCalculationTest.cpp
r1e0785 r5dba7a 31 31 CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest ); 32 32 33 // some stubs34 class AtomStub : public atom {35 public:36 AtomStub(atomId_t _id) :37 atom(),38 id(_id),39 manipulated(false)40 {}41 42 virtual atomId_t getId(){43 return id;44 }45 46 virtual void doSomething(){47 manipulated = true;48 }49 50 bool manipulated;51 private:52 atomId_t id;53 };54 55 33 // set up and tear down 56 34 void atomsCalculationTest::setUp(){ 57 35 World::getInstance(); 58 36 for(int i=0;i<ATOM_COUNT;++i){ 59 atoms[i]= new AtomStub(i);60 World::getInstance().registerAtom(atoms[i]);37 atoms[i]= World::getInstance().createAtom(); 38 atomIds[i]= atoms[i]->getId(); 61 39 } 62 40 } … … 67 45 68 46 // some helper functions 69 static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){ 70 for(int i=min;i<max;++i){ 71 if(!excluded.count(i)){ 72 std::vector<int>::iterator iter; 47 static bool hasAllIds(std::vector<atomId_t> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){ 48 for(int i=0;i<ATOM_COUNT;++i){ 49 atomId_t id = ids[i]; 50 if(!excluded.count(id)){ 51 std::vector<atomId_t>::iterator iter; 73 52 bool res=false; 74 for(iter= ids.begin();iter!=ids.end();++iter){75 res |= (*iter) == i ;53 for(iter=atoms.begin();iter!=atoms.end();++iter){ 54 res |= (*iter) == id; 76 55 } 77 56 if(!res) { 78 cout << "Atom " << i << " missing in returned list" << endl;57 cout << "Atom " << id << " missing in returned list" << endl; 79 58 return false; 80 59 } … … 84 63 } 85 64 86 static bool hasNoDuplicates(std::vector< int> ids){87 std::set< int> found;88 std::vector< int>::iterator iter;65 static bool hasNoDuplicates(std::vector<atomId_t> ids){ 66 std::set<atomId_t> found; 67 std::vector<atomId_t>::iterator iter; 89 68 for(iter=ids.begin();iter!=ids.end();++iter){ 90 69 int id = (*iter); … … 97 76 98 77 void atomsCalculationTest::testCalculateSimple(){ 99 AtomsCalculation< int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());100 std::vector< int> allIds = (*calc)();101 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT));78 AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms()); 79 std::vector<atomId_t> allIds = (*calc)(); 80 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds)); 102 81 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 103 82 } 104 83 105 84 void atomsCalculationTest::testCalculateExcluded(){ 106 int excluded = ATOM_COUNT/2;107 AtomsCalculation< int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));108 std::vector< int> allIds = (*calc)();109 std::set< int> excluded_set;85 atomId_t excluded = atomIds[ATOM_COUNT/2]; 86 AtomsCalculation<atomId_t> *calc = World::getInstance().calcOnAtoms<atomId_t>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded)); 87 std::vector<atomId_t> allIds = (*calc)(); 88 std::set<atomId_t> excluded_set; 110 89 excluded_set.insert(excluded); 111 CPPUNIT_ASSERT(hasAll (allIds,0,ATOM_COUNT,excluded_set));90 CPPUNIT_ASSERT(hasAllIds(allIds,atomIds,excluded_set)); 112 91 CPPUNIT_ASSERT(hasNoDuplicates(allIds)); 113 92 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
Note:
See TracChangeset
for help on using the changeset viewer.
