| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [94d5ac6] | 6 |  * 
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 13 |  *    (at your option) any later version.
 | 
|---|
 | 14 |  *
 | 
|---|
 | 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 18 |  *    GNU General Public License for more details.
 | 
|---|
 | 19 |  *
 | 
|---|
 | 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
| [7a1ce5] | 24 | /*
 | 
|---|
| [d766b5] | 25 |  * AtomDescriptorUnitTest.cpp
 | 
|---|
| [7a1ce5] | 26 |  *
 | 
|---|
 | 27 |  *  Created on: Feb 9, 2010
 | 
|---|
 | 28 |  *      Author: crueger
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
| [bf3817] | 31 | // include config.h
 | 
|---|
 | 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 33 | #include <config.h>
 | 
|---|
 | 34 | #endif
 | 
|---|
 | 35 | 
 | 
|---|
| [d766b5] | 36 | #include "AtomDescriptorUnitTest.hpp"
 | 
|---|
| [7a1ce5] | 37 | 
 | 
|---|
 | 38 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 39 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 40 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 41 | #include <iostream>
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | #include <Descriptors/AtomDescriptor.hpp>
 | 
|---|
 | 44 | #include <Descriptors/AtomIdDescriptor.hpp>
 | 
|---|
| [b49568] | 45 | #include <Descriptors/AtomOfMoleculeDescriptor.hpp>
 | 
|---|
| [61c364] | 46 | #include <Descriptors/AtomOrderDescriptor.hpp>
 | 
|---|
| [bbab87] | 47 | #include <Descriptors/AtomsWithinDistanceOfDescriptor.hpp>
 | 
|---|
| [7a1ce5] | 48 | 
 | 
|---|
 | 49 | #include "World.hpp"
 | 
|---|
| [6f0841] | 50 | #include "Atom/atom.hpp"
 | 
|---|
| [b49568] | 51 | #include "molecule.hpp"
 | 
|---|
| [bbab87] | 52 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [7a1ce5] | 53 | 
 | 
|---|
| [9b6b2f] | 54 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 55 | #include "UnitTestMain.hpp"
 | 
|---|
 | 56 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | /********************************************** Test classes **************************************/
 | 
|---|
| [7a1ce5] | 59 | // Registers the fixture into the 'registry'
 | 
|---|
| [57adc7] | 60 | CPPUNIT_TEST_SUITE_REGISTRATION( AtomDescriptorTest );
 | 
|---|
| [7a1ce5] | 61 | 
 | 
|---|
 | 62 | // set up and tear down
 | 
|---|
| [bbab87] | 63 | void AtomDescriptorTest::setUp()
 | 
|---|
 | 64 | {
 | 
|---|
| [23b547] | 65 |   World::getInstance();
 | 
|---|
| [7a1ce5] | 66 |   for(int i=0;i<ATOM_COUNT;++i){
 | 
|---|
| [23b547] | 67 |     atoms[i]= World::getInstance().createAtom();
 | 
|---|
| [57adc7] | 68 |     atomIds[i]= atoms[i]->getId();
 | 
|---|
| [7a1ce5] | 69 |   }
 | 
|---|
 | 70 | }
 | 
|---|
| [57adc7] | 71 | 
 | 
|---|
| [bbab87] | 72 | void AtomDescriptorTest::tearDown()
 | 
|---|
 | 73 | {
 | 
|---|
| [23b547] | 74 |   World::purgeInstance();
 | 
|---|
| [7a1ce5] | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | // some helper functions
 | 
|---|
| [a58c16] | 78 | static bool hasAllAtoms(
 | 
|---|
 | 79 |     std::vector<const atom*> atoms,
 | 
|---|
 | 80 |     atomId_t ids[ATOM_COUNT],
 | 
|---|
 | 81 |     std::set<atomId_t> excluded = std::set<atomId_t>())
 | 
|---|
| [bbab87] | 82 | {
 | 
|---|
| [46d958] | 83 |   for(int i=0;i<ATOM_COUNT;++i){
 | 
|---|
| [57adc7] | 84 |     atomId_t id = ids[i];
 | 
|---|
| [46d958] | 85 |     if(!excluded.count(id)){
 | 
|---|
| [a58c16] | 86 |       std::vector<const atom*>::const_iterator iter;
 | 
|---|
| [7a1ce5] | 87 |       bool res=false;
 | 
|---|
 | 88 |       for(iter=atoms.begin();iter!=atoms.end();++iter){
 | 
|---|
| [46d958] | 89 |         res |= (*iter)->getId() == id;
 | 
|---|
| [7a1ce5] | 90 |       }
 | 
|---|
 | 91 |       if(!res) {
 | 
|---|
| [46d958] | 92 |         cout << "Atom " << id << " missing in returned list" << endl;
 | 
|---|
| [7a1ce5] | 93 |         return false;
 | 
|---|
 | 94 |       }
 | 
|---|
 | 95 |     }
 | 
|---|
 | 96 |   }
 | 
|---|
 | 97 |   return true;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
| [a58c16] | 100 | static bool hasNoDuplicateAtoms(std::vector<const atom*> atoms)
 | 
|---|
| [bbab87] | 101 | {
 | 
|---|
| [57adc7] | 102 |   std::set<atomId_t> found;
 | 
|---|
| [a58c16] | 103 |   std::vector<const atom*>::const_iterator iter;
 | 
|---|
| [7a1ce5] | 104 |   for(iter=atoms.begin();iter!=atoms.end();++iter){
 | 
|---|
 | 105 |     int id = (*iter)->getId();
 | 
|---|
 | 106 |     if(found.count(id))
 | 
|---|
 | 107 |       return false;
 | 
|---|
 | 108 |     found.insert(id);
 | 
|---|
 | 109 |   }
 | 
|---|
 | 110 |   return true;
 | 
|---|
 | 111 | }
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 | 
 | 
|---|
| [bbab87] | 114 | void AtomDescriptorTest::AtomBaseSetsTest()
 | 
|---|
 | 115 | {
 | 
|---|
| [a58c16] | 116 |   std::vector<const atom*> allAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 117 |       getAllAtoms(AllAtoms());
 | 
|---|
| [57adc7] | 118 |   CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
 | 
|---|
 | 119 |   CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
 | 
|---|
| [7a1ce5] | 120 | 
 | 
|---|
| [a58c16] | 121 |   std::vector<const atom*> noAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 122 |       getAllAtoms(NoAtoms());
 | 
|---|
| [7a1ce5] | 123 |   CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
 | 
|---|
 | 124 | }
 | 
|---|
| [bbab87] | 125 | 
 | 
|---|
 | 126 | void AtomDescriptorTest::AtomIdTest()
 | 
|---|
 | 127 | {
 | 
|---|
| [7a1ce5] | 128 |   // test Atoms from boundaries and middle of the set
 | 
|---|
| [f01769] | 129 |   const atom* testAtom;
 | 
|---|
 | 130 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 131 |       getAtom(AtomById(atomIds[0]));
 | 
|---|
| [46d958] | 132 |   CPPUNIT_ASSERT(testAtom);
 | 
|---|
 | 133 |   CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
 | 
|---|
| [f01769] | 134 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 135 |       getAtom(AtomById(atomIds[ATOM_COUNT/2]));
 | 
|---|
| [46d958] | 136 |   CPPUNIT_ASSERT(testAtom);
 | 
|---|
 | 137 |   CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
 | 
|---|
| [f01769] | 138 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 139 |       getAtom(AtomById(atomIds[ATOM_COUNT-1]));
 | 
|---|
| [46d958] | 140 |   CPPUNIT_ASSERT(testAtom);
 | 
|---|
 | 141 |   CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 |   // find some ID that has not been created
 | 
|---|
| [57adc7] | 144 |   atomId_t outsideId=0;
 | 
|---|
| [46d958] | 145 |   bool res = false;
 | 
|---|
| [57adc7] | 146 |   for(outsideId=0;!res;++outsideId) {
 | 
|---|
| [46d958] | 147 |     res = true;
 | 
|---|
 | 148 |     for(int i = 0; i < ATOM_COUNT; ++i){
 | 
|---|
 | 149 |       res &= atomIds[i]!=outsideId;
 | 
|---|
 | 150 |     }
 | 
|---|
 | 151 |   }
 | 
|---|
| [7a1ce5] | 152 |   // test from outside of set
 | 
|---|
| [f01769] | 153 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 154 |       getAtom(AtomById(outsideId));
 | 
|---|
| [7a1ce5] | 155 |   CPPUNIT_ASSERT(!testAtom);
 | 
|---|
 | 156 | }
 | 
|---|
| [bbab87] | 157 | 
 | 
|---|
 | 158 | void AtomDescriptorTest::AtomOfMoleculeTest()
 | 
|---|
 | 159 | {
 | 
|---|
| [b49568] | 160 |   // test Atoms from boundaries and middle of the set
 | 
|---|
 | 161 |   atom* testAtom;
 | 
|---|
 | 162 |   testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
 | 
|---|
 | 163 |   CPPUNIT_ASSERT(testAtom);
 | 
|---|
 | 164 |   CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 |   // create some molecule and associate atom to it
 | 
|---|
 | 167 |   testAtom->setType(1);
 | 
|---|
 | 168 |   molecule * newmol = World::getInstance().createMolecule();
 | 
|---|
 | 169 |   newmol->AddAtom(testAtom);
 | 
|---|
 | 170 |   CPPUNIT_ASSERT_EQUAL(newmol->getId(), testAtom->getMolecule()->getId());
 | 
|---|
 | 171 | 
 | 
|---|
 | 172 |   // get atom by descriptor
 | 
|---|
| [a58c16] | 173 |   World::ConstAtomComposite atoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 174 |       getAllAtoms(AtomOfMolecule(newmol->getId()));
 | 
|---|
| [b49568] | 175 |   CPPUNIT_ASSERT_EQUAL( (size_t)1, atoms.size() );
 | 
|---|
 | 176 |   CPPUNIT_ASSERT_EQUAL( (*atoms.begin())->getId(), testAtom->getId() );
 | 
|---|
 | 177 | 
 | 
|---|
 | 178 |   // remove molecule again
 | 
|---|
 | 179 |   World::getInstance().destroyMolecule(newmol);
 | 
|---|
 | 180 | }
 | 
|---|
| [bbab87] | 181 | 
 | 
|---|
| [61c364] | 182 | void AtomDescriptorTest::AtomOrderTest()
 | 
|---|
 | 183 | {
 | 
|---|
| [f01769] | 184 |   const atom* testAtom;
 | 
|---|
| [61c364] | 185 | 
 | 
|---|
 | 186 |   // test in normal order: 1, 2, ...
 | 
|---|
 | 187 |   for(int i=1;i<=ATOM_COUNT;++i){
 | 
|---|
| [f01769] | 188 |     testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 189 |         getAtom(AtomByOrder(i));
 | 
|---|
| [61c364] | 190 |     CPPUNIT_ASSERT_EQUAL( atomIds[i-1], testAtom->getId());
 | 
|---|
 | 191 |   }
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 |   // test in reverse order: -1, -2, ...
 | 
|---|
 | 194 |   for(int i=1; i<= ATOM_COUNT;++i){
 | 
|---|
| [f01769] | 195 |     testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 196 |         getAtom(AtomByOrder(-i));
 | 
|---|
| [61c364] | 197 |     CPPUNIT_ASSERT_EQUAL( atomIds[(int)ATOM_COUNT-i], testAtom->getId());
 | 
|---|
 | 198 |   }
 | 
|---|
 | 199 | 
 | 
|---|
 | 200 |   // test from outside of set
 | 
|---|
| [f01769] | 201 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 202 |       getAtom(AtomByOrder(ATOM_COUNT+1));
 | 
|---|
| [61c364] | 203 |   CPPUNIT_ASSERT(!testAtom);
 | 
|---|
| [f01769] | 204 |   testAtom = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 205 |       getAtom(AtomByOrder(-ATOM_COUNT-1));
 | 
|---|
| [61c364] | 206 |   CPPUNIT_ASSERT(!testAtom);
 | 
|---|
 | 207 | }
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 | 
 | 
|---|
| [bbab87] | 210 | std::set<atomId_t> getDistanceList(const double distance, const Vector &position, atom **list)
 | 
|---|
 | 211 | {
 | 
|---|
 | 212 |   const double distanceSquared = distance*distance;
 | 
|---|
 | 213 |   std::set<atomId_t> reflist;
 | 
|---|
 | 214 |   for (size_t i=0; i<ATOM_COUNT;++i)
 | 
|---|
 | 215 |     if (list[i]->getPosition().DistanceSquared(position) < distanceSquared)
 | 
|---|
 | 216 |       reflist.insert ( list[i]->getId() );
 | 
|---|
 | 217 |   return reflist;
 | 
|---|
 | 218 | }
 | 
|---|
 | 219 | 
 | 
|---|
 | 220 | 
 | 
|---|
| [a58c16] | 221 | std::set<atomId_t> getIdList(const World::ConstAtomComposite &list)
 | 
|---|
| [bbab87] | 222 | {
 | 
|---|
 | 223 |   std::set<atomId_t> testlist;
 | 
|---|
| [a58c16] | 224 |   for (World::ConstAtomComposite::const_iterator iter = list.begin();
 | 
|---|
| [bbab87] | 225 |       iter != list.end(); ++iter)
 | 
|---|
 | 226 |     testlist.insert( (*iter)->getId() );
 | 
|---|
 | 227 |   return testlist;
 | 
|---|
 | 228 | }
 | 
|---|
 | 229 | 
 | 
|---|
| [61c364] | 230 | //void AtomDescriptorTest::AtomsShapeTest()
 | 
|---|
 | 231 | //{
 | 
|---|
 | 232 | //  // align atoms along an axis
 | 
|---|
 | 233 | //  for(int i=0;i<ATOM_COUNT;++i) {
 | 
|---|
 | 234 | //    atoms[i]->setPosition(Vector((double)i, 0., 0.));
 | 
|---|
 | 235 | //    //std::cout << "atoms[" << i << "]: " << atoms[i]->getId() << " at " << atoms[i]->getPosition() << std::endl;
 | 
|---|
 | 236 | //  }
 | 
|---|
 | 237 | //
 | 
|---|
 | 238 | //  // get atom by descriptor ...
 | 
|---|
 | 239 | //  // ... from origin up to 2.5
 | 
|---|
 | 240 | //  {
 | 
|---|
 | 241 | //    const double distance = 1.5;
 | 
|---|
 | 242 | //    Vector position(0.,0.,0.);
 | 
|---|
 | 243 | //    Shape s = Sphere(position, distance);
 | 
|---|
| [a58c16] | 244 | //    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 245 | //        getAllAtoms(AtomsByShape(s));
 | 
|---|
| [61c364] | 246 | //    CPPUNIT_ASSERT_EQUAL( (size_t)2, atomlist.size() );
 | 
|---|
 | 247 | //    std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
 | 
|---|
 | 248 | //    std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
 | 249 | //    CPPUNIT_ASSERT_EQUAL( reflist, testlist );
 | 
|---|
 | 250 | //  }
 | 
|---|
 | 251 | //  // ... from (4,0,0) up to 2.9 (i.e. more shells or different view)
 | 
|---|
 | 252 | //  {
 | 
|---|
 | 253 | //    const double distance = 2.9;
 | 
|---|
 | 254 | //    Vector position(4.,0.,0.);
 | 
|---|
 | 255 | //    Shape s = Sphere(position, distance);
 | 
|---|
| [a58c16] | 256 | //    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 257 | //        getAllAtoms(AtomsByShape(s));
 | 
|---|
| [61c364] | 258 | //    CPPUNIT_ASSERT_EQUAL( (size_t)5, atomlist.size() );
 | 
|---|
 | 259 | //    std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
 | 
|---|
 | 260 | //    std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
 | 261 | //    CPPUNIT_ASSERT_EQUAL( reflist, testlist );
 | 
|---|
 | 262 | //  }
 | 
|---|
 | 263 | //  // ... from (10,0,0) up to 1.5
 | 
|---|
 | 264 | //  {
 | 
|---|
 | 265 | //    const double distance = 1.5;
 | 
|---|
 | 266 | //    Vector *position = new Vector(10.,0.,0.);
 | 
|---|
 | 267 | //    Shape s = Sphere(position, distance);
 | 
|---|
| [a58c16] | 268 | //    World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 269 | //        getAllAtoms(AtomsByShape(s));
 | 
|---|
| [61c364] | 270 | //    CPPUNIT_ASSERT_EQUAL( (size_t)1, atomlist.size() );
 | 
|---|
 | 271 | //    std::set<atomId_t> reflist = getDistanceList(distance, *position, atoms);
 | 
|---|
 | 272 | //    std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
 | 273 | //    CPPUNIT_ASSERT_EQUAL( reflist, testlist );
 | 
|---|
 | 274 | //    delete position;
 | 
|---|
 | 275 | //  }
 | 
|---|
 | 276 | //}
 | 
|---|
 | 277 | 
 | 
|---|
| [bbab87] | 278 | void AtomDescriptorTest::AtomsWithinDistanceOfTest()
 | 
|---|
 | 279 | {
 | 
|---|
 | 280 |   // align atoms along an axis
 | 
|---|
 | 281 |   for(int i=0;i<ATOM_COUNT;++i) {
 | 
|---|
 | 282 |     atoms[i]->setPosition(Vector((double)i, 0., 0.));
 | 
|---|
 | 283 |     //std::cout << "atoms[" << i << "]: " << atoms[i]->getId() << " at " << atoms[i]->getPosition() << std::endl;
 | 
|---|
 | 284 |   }
 | 
|---|
 | 285 | 
 | 
|---|
 | 286 |   // get atom by descriptor ...
 | 
|---|
 | 287 |   // ... from origin up to 2.5
 | 
|---|
 | 288 |   {
 | 
|---|
 | 289 |     const double distance = 1.5;
 | 
|---|
 | 290 |     Vector position(0.,0.,0.);
 | 
|---|
| [a58c16] | 291 |     World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 292 |         getAllAtoms(AtomsWithinDistanceOf(distance, position));
 | 
|---|
| [bbab87] | 293 |     CPPUNIT_ASSERT_EQUAL( (size_t)2, atomlist.size() );
 | 
|---|
 | 294 |     std::set<atomId_t> reflist = getDistanceList(distance, position, atoms);
 | 
|---|
 | 295 |     std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
| [87d6bd] | 296 |     CPPUNIT_ASSERT( reflist == testlist );
 | 
|---|
| [bbab87] | 297 |   }
 | 
|---|
 | 298 |   // ... from (4,0,0) up to 2.9 (i.e. more shells or different view)
 | 
|---|
 | 299 |   {
 | 
|---|
 | 300 |     const double distance = 2.9;
 | 
|---|
| [a58c16] | 301 |     World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 302 |         getAllAtoms(AtomsWithinDistanceOf(distance, Vector(4.,0.,0.)));
 | 
|---|
| [bbab87] | 303 |     CPPUNIT_ASSERT_EQUAL( (size_t)5, atomlist.size() );
 | 
|---|
 | 304 |     std::set<atomId_t> reflist = getDistanceList(distance, Vector(4.,0.,0.), atoms);
 | 
|---|
 | 305 |     std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
| [87d6bd] | 306 |     CPPUNIT_ASSERT( reflist == testlist );
 | 
|---|
| [bbab87] | 307 |   }
 | 
|---|
 | 308 |   // ... from (10,0,0) up to 1.5
 | 
|---|
 | 309 |   {
 | 
|---|
 | 310 |     const double distance = 1.5;
 | 
|---|
 | 311 |     Vector *position = new Vector(10.,0.,0.);
 | 
|---|
| [a58c16] | 312 |     World::ConstAtomComposite atomlist = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 313 |         getAllAtoms(AtomsWithinDistanceOf(distance, *position));
 | 
|---|
| [bbab87] | 314 |     CPPUNIT_ASSERT_EQUAL( (size_t)1, atomlist.size() );
 | 
|---|
 | 315 |     std::set<atomId_t> reflist = getDistanceList(distance, *position, atoms);
 | 
|---|
 | 316 |     std::set<atomId_t> testlist = getIdList(atomlist);
 | 
|---|
| [87d6bd] | 317 |     CPPUNIT_ASSERT( reflist == testlist );
 | 
|---|
| [bbab87] | 318 |     delete position;
 | 
|---|
 | 319 |   }
 | 
|---|
 | 320 | }
 | 
|---|
 | 321 | 
 | 
|---|
 | 322 | void AtomDescriptorTest::AtomCalcTest()
 | 
|---|
 | 323 | {
 | 
|---|
| [7a1ce5] | 324 |   // test some elementary set operations
 | 
|---|
 | 325 |   {
 | 
|---|
| [a58c16] | 326 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 327 |         getAllAtoms(AllAtoms()||NoAtoms());
 | 
|---|
| [57adc7] | 328 |     CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
 | 
|---|
 | 329 |     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
 | 
|---|
| [7a1ce5] | 330 |   }
 | 
|---|
 | 331 | 
 | 
|---|
 | 332 |   {
 | 
|---|
| [a58c16] | 333 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 334 |         getAllAtoms(NoAtoms()||AllAtoms());
 | 
|---|
| [57adc7] | 335 |     CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
 | 
|---|
 | 336 |     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
 | 
|---|
| [7a1ce5] | 337 |   }
 | 
|---|
 | 338 | 
 | 
|---|
 | 339 |   {
 | 
|---|
| [a58c16] | 340 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 341 |         getAllAtoms(NoAtoms()&&AllAtoms());
 | 
|---|
| [7a1ce5] | 342 |     CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
 | 
|---|
 | 343 |   }
 | 
|---|
 | 344 | 
 | 
|---|
 | 345 |   {
 | 
|---|
| [a58c16] | 346 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 347 |         getAllAtoms(AllAtoms()&&NoAtoms());
 | 
|---|
| [7a1ce5] | 348 |     CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
 | 
|---|
 | 349 |   }
 | 
|---|
 | 350 | 
 | 
|---|
 | 351 |   {
 | 
|---|
| [a58c16] | 352 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 353 |         getAllAtoms(!AllAtoms());
 | 
|---|
| [7a1ce5] | 354 |     CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
 | 
|---|
 | 355 |   }
 | 
|---|
 | 356 | 
 | 
|---|
 | 357 |   {
 | 
|---|
| [a58c16] | 358 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 359 |         getAllAtoms(!NoAtoms());
 | 
|---|
| [57adc7] | 360 |     CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
 | 
|---|
 | 361 |     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
 | 
|---|
| [7a1ce5] | 362 |   }
 | 
|---|
 | 363 |   // exclude and include some atoms
 | 
|---|
 | 364 |   {
 | 
|---|
| [a58c16] | 365 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 366 |         getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
 | 
|---|
| [57adc7] | 367 |     std::set<atomId_t> excluded;
 | 
|---|
| [46d958] | 368 |     excluded.insert(atomIds[ATOM_COUNT/2]);
 | 
|---|
| [57adc7] | 369 |     CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds,excluded));
 | 
|---|
 | 370 |     CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
 | 
|---|
| [7a1ce5] | 371 |     CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
 | 
|---|
 | 372 |   }
 | 
|---|
 | 373 | 
 | 
|---|
 | 374 |   {
 | 
|---|
| [a58c16] | 375 |     std::vector<const atom*> testAtoms = const_cast<const World &>(World::getInstance()).
 | 
|---|
 | 376 |         getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
 | 
|---|
| [7a1ce5] | 377 |     CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
 | 
|---|
| [46d958] | 378 |     CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
 | 
|---|
| [7a1ce5] | 379 |   }
 | 
|---|
 | 380 | }
 | 
|---|