Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/DescriptorUnittest.cpp

    r46d958 r7a1ce5  
    2222CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2323
     24// some stubs
     25class AtomStub : public atom {
     26public:
     27  AtomStub(int _id) :
     28  atom(),
     29  id(_id)
     30  {}
     31
     32  virtual int getId(){
     33    return id;
     34  }
     35
     36private:
     37  int id;
     38};
     39
     40
    2441// set up and tear down
    2542void DescriptorUnittest::setUp(){
    2643  World::get();
    2744  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);
    3046  }
    3147}
    3248void DescriptorUnittest::tearDown(){
    3349  World::destroy();
     50  for(int i=0;i<ATOM_COUNT;++i){
     51    delete atoms[i];
     52  }
    3453}
    3554
    3655// 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)){
     56bool 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)){
    4159      std::vector<atom*>::iterator iter;
    4260      bool res=false;
    4361      for(iter=atoms.begin();iter!=atoms.end();++iter){
    44         res |= (*iter)->getId() == id;
     62        res |= (*iter)->getId() == i;
    4563      }
    4664      if(!res) {
    47         cout << "Atom " << id << " missing in returned list" << endl;
     65        cout << "Atom " << i << " missing in returned list" << endl;
    4866        return false;
    4967      }
     
    6886void DescriptorUnittest::AtomBaseSetsTest(){
    6987  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));
    7189  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    7290
     
    7795  // test Atoms from boundaries and middle of the set
    7896  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());
    88103
    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   }
    99104  // test from outside of set
    100   testAtom = World::get()->getAtom(AtomById(outsideId));
     105  testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
    101106  CPPUNIT_ASSERT(!testAtom);
    102107}
     
    105110  {
    106111    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));
    108113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    109114  }
     
    111116  {
    112117    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));
    114119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    115120  }
     
    132137  {
    133138    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));
    135140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    136141  }
     
    138143  // exclude and include some atoms
    139144  {
    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)));
    141146    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));
    144149    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    145150    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    147152
    148153  {
    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)));
    150155    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());
    152157  }
    153158}
Note: See TracChangeset for help on using the changeset viewer.