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