- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/DescriptorUnittest.cpp
r46d958 r7a1ce5 22 22 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 23 23 24 // some stubs 25 class AtomStub : public atom { 26 public: 27 AtomStub(int _id) : 28 atom(), 29 id(_id) 30 {} 31 32 virtual int getId(){ 33 return id; 34 } 35 36 private: 37 int id; 38 }; 39 40 24 41 // set up and tear down 25 42 void DescriptorUnittest::setUp(){ 26 43 World::get(); 27 44 for(int i=0;i<ATOM_COUNT;++i){ 28 atoms[i]= World::get()->createAtom(); 29 atomIds[i] = atoms[i]->getId(); 45 atoms[i]= new AtomStub(i); 30 46 } 31 47 } 32 48 void DescriptorUnittest::tearDown(){ 33 49 World::destroy(); 50 for(int i=0;i<ATOM_COUNT;++i){ 51 delete atoms[i]; 52 } 34 53 } 35 54 36 55 // some helper functions 37 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){ 38 for(int i=0;i<ATOM_COUNT;++i){ 39 int id = ids[i]; 40 if(!excluded.count(id)){ 56 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 57 for(int i=min;i<max;++i){ 58 if(!excluded.count(i)){ 41 59 std::vector<atom*>::iterator iter; 42 60 bool res=false; 43 61 for(iter=atoms.begin();iter!=atoms.end();++iter){ 44 res |= (*iter)->getId() == i d;62 res |= (*iter)->getId() == i; 45 63 } 46 64 if(!res) { 47 cout << "Atom " << i d<< " missing in returned list" << endl;65 cout << "Atom " << i << " missing in returned list" << endl; 48 66 return false; 49 67 } … … 68 86 void DescriptorUnittest::AtomBaseSetsTest(){ 69 87 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 70 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms, atomIds));88 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT)); 71 89 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 72 90 … … 77 95 // test Atoms from boundaries and middle of the set 78 96 atom* testAtom; 79 testAtom = World::get()->getAtom(AtomById(atomIds[0])); 80 CPPUNIT_ASSERT(testAtom); 81 CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId()); 82 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2])); 83 CPPUNIT_ASSERT(testAtom); 84 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId()); 85 testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1])); 86 CPPUNIT_ASSERT(testAtom); 87 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId()); 97 testAtom = World::get()->getAtom(AtomById(0)); 98 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId()); 99 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2)); 100 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId()); 101 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1)); 102 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId()); 88 103 89 // find some ID that has not been created90 int outsideId =-1;91 bool res = false;92 while(!res) {93 ++outsideId;94 res = true;95 for(int i = 0; i < ATOM_COUNT; ++i){96 res &= atomIds[i]!=outsideId;97 }98 }99 104 // test from outside of set 100 testAtom = World::get()->getAtom(AtomById( outsideId));105 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT)); 101 106 CPPUNIT_ASSERT(!testAtom); 102 107 } … … 105 110 { 106 111 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 107 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));112 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 108 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 109 114 } … … 111 116 { 112 117 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 113 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));118 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 114 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 115 120 } … … 132 137 { 133 138 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 134 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));139 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 135 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 136 141 } … … 138 143 // exclude and include some atoms 139 144 { 140 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById( atomIds[ATOM_COUNT/2])));145 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2))); 141 146 std::set<int> excluded; 142 excluded.insert( atomIds[ATOM_COUNT/2]);143 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds,excluded));147 excluded.insert(ATOM_COUNT/2); 148 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded)); 144 149 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 145 150 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 147 152 148 153 { 149 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById( atomIds[ATOM_COUNT/2])));154 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2))); 150 155 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 151 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());156 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId()); 152 157 } 153 158 }
Note:
See TracChangeset
for help on using the changeset viewer.