Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/DescriptorUnittest.cpp

    r7a1ce5 r46d958  
    2222CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2323
    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 
    4124// set up and tear down
    4225void DescriptorUnittest::setUp(){
    4326  World::get();
    4427  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();
    4630  }
    4731}
    4832void DescriptorUnittest::tearDown(){
    4933  World::destroy();
    50   for(int i=0;i<ATOM_COUNT;++i){
    51     delete atoms[i];
    52   }
    5334}
    5435
    5536// 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)){
     37bool 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)){
    5941      std::vector<atom*>::iterator iter;
    6042      bool res=false;
    6143      for(iter=atoms.begin();iter!=atoms.end();++iter){
    62         res |= (*iter)->getId() == i;
     44        res |= (*iter)->getId() == id;
    6345      }
    6446      if(!res) {
    65         cout << "Atom " << i << " missing in returned list" << endl;
     47        cout << "Atom " << id << " missing in returned list" << endl;
    6648        return false;
    6749      }
     
    8668void DescriptorUnittest::AtomBaseSetsTest(){
    8769  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));
    8971  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    9072
     
    9577  // test Atoms from boundaries and middle of the set
    9678  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());
    10388
     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  }
    10499  // test from outside of set
    105   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
     100  testAtom = World::get()->getAtom(AtomById(outsideId));
    106101  CPPUNIT_ASSERT(!testAtom);
    107102}
     
    110105  {
    111106    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));
    113108    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    114109  }
     
    116111  {
    117112    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));
    119114    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    120115  }
     
    137132  {
    138133    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));
    140135    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    141136  }
     
    143138  // exclude and include some atoms
    144139  {
    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])));
    146141    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));
    149144    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    150145    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    152147
    153148  {
    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])));
    155150    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());
    157152  }
    158153}
Note: See TracChangeset for help on using the changeset viewer.