- File:
-
- 1 edited
-
src/unittests/DescriptorUnittest.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/DescriptorUnittest.cpp
r46d958 r9b6b2f 19 19 #include "atom.hpp" 20 20 21 #ifdef HAVE_TESTRUNNER 22 #include "UnitTestMain.hpp" 23 #endif /*HAVE_TESTRUNNER*/ 24 25 /********************************************** Test classes **************************************/ 21 26 // Registers the fixture into the 'registry' 22 27 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 28 29 // some stubs 30 class AtomStub : public atom { 31 public: 32 AtomStub(int _id) : 33 atom(), 34 id(_id) 35 {} 36 37 virtual int getId(){ 38 return id; 39 } 40 41 private: 42 int id; 43 }; 44 23 45 24 46 // set up and tear down … … 26 48 World::get(); 27 49 for(int i=0;i<ATOM_COUNT;++i){ 28 atoms[i]= World::get()->createAtom(); 29 atomIds[i] = atoms[i]->getId(); 50 atoms[i]= new AtomStub(i); 30 51 } 31 52 } 32 53 void DescriptorUnittest::tearDown(){ 33 54 World::destroy(); 55 for(int i=0;i<ATOM_COUNT;++i){ 56 delete atoms[i]; 57 } 34 58 } 35 59 36 60 // 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)){ 61 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){ 62 for(int i=min;i<max;++i){ 63 if(!excluded.count(i)){ 41 64 std::vector<atom*>::iterator iter; 42 65 bool res=false; 43 66 for(iter=atoms.begin();iter!=atoms.end();++iter){ 44 res |= (*iter)->getId() == i d;67 res |= (*iter)->getId() == i; 45 68 } 46 69 if(!res) { 47 cout << "Atom " << i d<< " missing in returned list" << endl;70 cout << "Atom " << i << " missing in returned list" << endl; 48 71 return false; 49 72 } … … 68 91 void DescriptorUnittest::AtomBaseSetsTest(){ 69 92 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 70 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms, atomIds));93 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT)); 71 94 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 72 95 … … 77 100 // test Atoms from boundaries and middle of the set 78 101 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()); 102 testAtom = World::get()->getAtom(AtomById(0)); 103 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId()); 104 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2)); 105 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId()); 106 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1)); 107 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId()); 88 108 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 109 // test from outside of set 100 testAtom = World::get()->getAtom(AtomById( outsideId));110 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT)); 101 111 CPPUNIT_ASSERT(!testAtom); 102 112 } … … 105 115 { 106 116 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 107 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));117 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 108 118 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 109 119 } … … 111 121 { 112 122 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 113 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));123 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 114 124 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 115 125 } … … 132 142 { 133 143 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 134 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds));144 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT)); 135 145 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 136 146 } … … 138 148 // exclude and include some atoms 139 149 { 140 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById( atomIds[ATOM_COUNT/2])));150 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2))); 141 151 std::set<int> excluded; 142 excluded.insert( atomIds[ATOM_COUNT/2]);143 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms, atomIds,excluded));152 excluded.insert(ATOM_COUNT/2); 153 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded)); 144 154 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 145 155 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 147 157 148 158 { 149 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById( atomIds[ATOM_COUNT/2])));159 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2))); 150 160 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size()); 151 CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());161 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId()); 152 162 } 153 163 } 154 155 /********************************************** Main routine **************************************/156 157 int main(int argc, char **argv)158 {159 // Get the top level suite from the registry160 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();161 162 // Adds the test to the list of test to run163 CppUnit::TextUi::TestRunner runner;164 runner.addTest( suite );165 166 // Change the default outputter to a compiler error format outputter167 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),168 std::cerr ) );169 // Run the tests.170 bool wasSucessful = runner.run();171 172 // Return error code 1 if the one of test failed.173 return wasSucessful ? 0 : 1;174 };
Note:
See TracChangeset
for help on using the changeset viewer.
