[f3bc5f] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * FragmentUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Aug 09, 2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
| 41 | #include "FragmentUnitTest.hpp"
|
---|
| 42 |
|
---|
| 43 | #include <algorithm>
|
---|
| 44 | #include <limits>
|
---|
| 45 |
|
---|
| 46 | #include <boost/assign.hpp>
|
---|
| 47 | #include <boost/foreach.hpp>
|
---|
| 48 |
|
---|
| 49 | #include "CodePatterns/Assert.hpp"
|
---|
| 50 |
|
---|
| 51 | #ifdef HAVE_TESTRUNNER
|
---|
| 52 | #include "UnitTestMain.hpp"
|
---|
| 53 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 54 |
|
---|
| 55 | using namespace boost::assign;
|
---|
| 56 |
|
---|
| 57 | /********************************************** Test classes **************************************/
|
---|
| 58 |
|
---|
| 59 | // Registers the fixture into the 'registry'
|
---|
| 60 | CPPUNIT_TEST_SUITE_REGISTRATION( FragmentTest );
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | void FragmentTest::setUp()
|
---|
| 64 | {
|
---|
| 65 | // failing asserts should be thrown
|
---|
| 66 | ASSERT_DO(Assert::Throw);
|
---|
| 67 |
|
---|
| 68 | Fragment::position_t pos(3,0.);
|
---|
| 69 | positions += pos;
|
---|
| 70 | pos[0] = 1.;
|
---|
| 71 | positions += pos;
|
---|
| 72 | pos[1] = 1.;
|
---|
| 73 | positions += pos;
|
---|
| 74 | pos[2] = 1.;
|
---|
| 75 | positions += pos;
|
---|
| 76 | charges += 1., 2., 3., 4.;
|
---|
| 77 | CPPUNIT_ASSERT_EQUAL( (size_t)3, pos.size() );
|
---|
| 78 | CPPUNIT_ASSERT( positions.size() == charges.size() );
|
---|
| 79 |
|
---|
| 80 | fragment = new Fragment(positions, charges);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | void FragmentTest::tearDown()
|
---|
| 85 | {
|
---|
| 86 | delete fragment;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | /** UnitTest for isPositionEqual()
|
---|
| 90 | */
|
---|
| 91 | void FragmentTest::isPositionEqual_Test()
|
---|
| 92 | {
|
---|
| 93 | // same position
|
---|
| 94 | for (Fragment::positions_t::const_iterator iter = positions.begin();
|
---|
| 95 | iter != positions.end(); ++iter)
|
---|
| 96 | CPPUNIT_ASSERT( Fragment::isPositionEqual(*iter, *iter) );
|
---|
| 97 |
|
---|
| 98 | // other position
|
---|
| 99 | Fragment::position_t unequalpos(3,2.);
|
---|
| 100 | for (Fragment::positions_t::const_iterator iter = positions.begin();
|
---|
| 101 | iter != positions.end(); ++iter)
|
---|
| 102 | CPPUNIT_ASSERT( !Fragment::isPositionEqual(*iter, unequalpos) );
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | /** UnitTest for containsNuclei()
|
---|
| 107 | */
|
---|
| 108 | void FragmentTest::containsNuclei_Test()
|
---|
| 109 | {
|
---|
| 110 | {
|
---|
| 111 | // tests present ones for containment
|
---|
| 112 | Fragment::nuclei_t validnuclei(positions.size());
|
---|
| 113 | std::transform(positions.begin(), positions.end(),
|
---|
| 114 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 115 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 116 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | {
|
---|
| 121 | // test some others
|
---|
| 122 | Fragment::nuclei_t invalidnuclei;
|
---|
| 123 | Fragment::position_t pos(3, -1.);
|
---|
| 124 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 125 | pos[0] = 0.;
|
---|
| 126 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 127 | pos[1] = 0.;
|
---|
| 128 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 129 | pos[2] = -std::numeric_limits<double>::epsilon()*1e+4;
|
---|
| 130 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 131 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 132 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /** UnitTest for removeNuclei()
|
---|
| 138 | */
|
---|
| 139 | void FragmentTest::removeNuclei_Test()
|
---|
| 140 | {
|
---|
| 141 | {
|
---|
| 142 | // tests present ones for removal
|
---|
| 143 | size_t size = fragment->nuclei.size();
|
---|
| 144 | Fragment::nuclei_t validnuclei(positions.size());
|
---|
| 145 | std::transform(positions.begin(), positions.end(),
|
---|
| 146 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 147 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 148 | CPPUNIT_ASSERT_NO_THROW( fragment->removeNuclei(nucleus) );
|
---|
| 149 | CPPUNIT_ASSERT_EQUAL( --size, fragment->nuclei.size() );
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | {
|
---|
| 153 | // test some others
|
---|
| 154 | Fragment::nuclei_t invalidnuclei;
|
---|
| 155 | Fragment::position_t pos(3, -1.);
|
---|
| 156 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 157 | pos[0] = 0;
|
---|
| 158 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 159 | pos[1] = 0;
|
---|
| 160 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 161 | pos[2] = -std::numeric_limits<double>::epsilon()*1e+4;
|
---|
| 162 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
---|
| 163 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 164 | CPPUNIT_ASSERT_NO_THROW( fragment->removeNuclei(nucleus) );
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /** UnitTest for operator==() for Fragment::nucleus_t
|
---|
| 170 | */
|
---|
| 171 | void FragmentTest::equalityNucleus_Test()
|
---|
| 172 | {
|
---|
| 173 | Fragment::nuclei_t validnuclei(positions.size());
|
---|
| 174 | std::transform(positions.begin(), positions.end(),
|
---|
| 175 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 176 | {
|
---|
| 177 | // create some nuclei
|
---|
| 178 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 179 | CPPUNIT_ASSERT( nucleus == nucleus );
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | {
|
---|
| 184 | // create nucleus at other position
|
---|
| 185 | Fragment::position_t pos(3, 2.);
|
---|
| 186 | Fragment::nucleus_t unequalposnucleus(pos, 1.);
|
---|
| 187 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 188 | CPPUNIT_ASSERT( nucleus != unequalposnucleus );
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | {
|
---|
| 193 | // create nucleus with different charge
|
---|
| 194 | Fragment::position_t pos(3, 1.);
|
---|
| 195 | Fragment::nucleus_t unequalchargenucleus(pos, 5.);
|
---|
| 196 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 197 | CPPUNIT_ASSERT( nucleus != unequalchargenucleus );
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /** UnitTest for operator==()
|
---|
| 203 | */
|
---|
| 204 | void FragmentTest::equality_Test()
|
---|
| 205 | {
|
---|
| 206 | // create different fragment
|
---|
| 207 | Fragment::positions_t otherpositions;
|
---|
| 208 | Fragment::position_t otherpos(3, 2.);
|
---|
| 209 | otherpositions += otherpos;
|
---|
| 210 | otherpos[0] = 0.;
|
---|
| 211 | otherpositions += otherpos;
|
---|
| 212 | otherpos[1] = 0.;
|
---|
| 213 | otherpositions += otherpos;
|
---|
| 214 | Fragment::charges_t othercharges;
|
---|
| 215 | othercharges += 1., 2., 3.;
|
---|
| 216 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 217 |
|
---|
| 218 | CPPUNIT_ASSERT( !(*fragment == otherfragment) );
|
---|
| 219 | CPPUNIT_ASSERT( *fragment != otherfragment );
|
---|
| 220 |
|
---|
| 221 | // test against empty fragment
|
---|
| 222 | Fragment emptyfragment;
|
---|
| 223 | CPPUNIT_ASSERT( !(*fragment == emptyfragment) );
|
---|
| 224 | CPPUNIT_ASSERT( *fragment != emptyfragment );
|
---|
| 225 |
|
---|
| 226 | // tests against themselves
|
---|
| 227 | CPPUNIT_ASSERT( *fragment == *fragment );
|
---|
| 228 | CPPUNIT_ASSERT( otherfragment == otherfragment );
|
---|
| 229 | CPPUNIT_ASSERT( emptyfragment == emptyfragment );
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | /** UnitTest for operator+=()
|
---|
| 233 | */
|
---|
| 234 | void FragmentTest::assignment_Test()
|
---|
| 235 | {
|
---|
| 236 | // create different fragment
|
---|
| 237 | Fragment::positions_t otherpositions;
|
---|
| 238 | Fragment::position_t otherpos(3, 2.);
|
---|
| 239 | otherpositions += otherpos;
|
---|
| 240 | otherpos[0] = 0.;
|
---|
| 241 | otherpositions += otherpos;
|
---|
| 242 | otherpos[1] = 0.;
|
---|
| 243 | otherpositions += otherpos;
|
---|
| 244 | Fragment::charges_t othercharges;
|
---|
| 245 | othercharges += 1., 2., 3.;
|
---|
| 246 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 247 |
|
---|
| 248 | // check for inequality
|
---|
| 249 | CPPUNIT_ASSERT( otherfragment.nuclei.size() != fragment->nuclei.size() );
|
---|
| 250 | CPPUNIT_ASSERT( otherfragment != *fragment );
|
---|
| 251 |
|
---|
| 252 | //assign
|
---|
| 253 | otherfragment = *fragment;
|
---|
| 254 |
|
---|
| 255 | // check for equality
|
---|
| 256 | CPPUNIT_ASSERT( otherfragment.nuclei.size() == fragment->nuclei.size() );
|
---|
| 257 | CPPUNIT_ASSERT( otherfragment == *fragment );
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /** UnitTest for operator+=()
|
---|
| 261 | */
|
---|
| 262 | void FragmentTest::operatorPlusEqual_NonOverlapping_Test()
|
---|
| 263 | {
|
---|
| 264 | {
|
---|
| 265 | // create non-overlapping set
|
---|
| 266 | Fragment::positions_t otherpositions;
|
---|
| 267 | Fragment::position_t otherpos(3, 2.);
|
---|
| 268 | otherpositions += otherpos;
|
---|
| 269 | otherpos[0] = 0.;
|
---|
| 270 | otherpositions += otherpos;
|
---|
| 271 | otherpos[1] = 0.;
|
---|
| 272 | otherpositions += otherpos;
|
---|
| 273 | Fragment::charges_t othercharges;
|
---|
| 274 | othercharges += 1., 2., 3.;
|
---|
| 275 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 276 | const size_t othersize = otherfragment.nuclei.size();
|
---|
| 277 | const size_t size = fragment->nuclei.size();
|
---|
| 278 | *fragment += otherfragment;
|
---|
| 279 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
---|
| 280 | CPPUNIT_ASSERT_EQUAL( size+othersize, fragment->nuclei.size() );
|
---|
| 281 | {
|
---|
| 282 | // tests all for containment
|
---|
| 283 | Fragment::nuclei_t validnuclei(positions.size()+otherpositions.size());
|
---|
| 284 | Fragment::nuclei_t::iterator iter =
|
---|
| 285 | std::transform(positions.begin(), positions.end(),
|
---|
| 286 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 287 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 288 | othercharges.begin(), iter, Fragment::createNucleus);
|
---|
| 289 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 290 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
---|
| 291 | }
|
---|
| 292 | }
|
---|
| 293 | {
|
---|
| 294 | // tests positions for no containment in otherfragment
|
---|
| 295 | Fragment::nuclei_t invalidnuclei(positions.size());
|
---|
| 296 | std::transform(positions.begin(), positions.end(),
|
---|
| 297 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
---|
| 298 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 299 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | {
|
---|
| 303 | // tests otherpositions for containment in otherfragment
|
---|
| 304 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
---|
| 305 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 306 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 307 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 308 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | /** UnitTest for operator+=()
|
---|
| 315 | */
|
---|
| 316 | void FragmentTest::operatorPlusEqual_Test()
|
---|
| 317 | {
|
---|
| 318 | {
|
---|
| 319 | // create overlapping set (first overlaps)
|
---|
| 320 | Fragment::positions_t otherpositions;
|
---|
| 321 | Fragment::position_t otherpos(3, 1.);
|
---|
| 322 | otherpositions += otherpos;
|
---|
| 323 | otherpos[0] = 2.;
|
---|
| 324 | otherpositions += otherpos;
|
---|
| 325 | otherpos[1] = 2.;
|
---|
| 326 | otherpositions += otherpos;
|
---|
| 327 | Fragment::charges_t othercharges;
|
---|
| 328 | othercharges += 1., 2., 3.;
|
---|
| 329 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 330 | const size_t othersize = otherfragment.nuclei.size();
|
---|
| 331 | const size_t size = fragment->nuclei.size();
|
---|
| 332 | *fragment += otherfragment;
|
---|
| 333 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
---|
| 334 | CPPUNIT_ASSERT_EQUAL( size+othersize-1, fragment->nuclei.size() ); // one for already present
|
---|
| 335 | {
|
---|
| 336 | // tests all for containment
|
---|
| 337 | Fragment::nuclei_t validnuclei(positions.size()+otherpositions.size());
|
---|
| 338 | Fragment::nuclei_t::iterator iter =
|
---|
| 339 | std::transform(positions.begin(), positions.end(),
|
---|
| 340 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 341 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 342 | othercharges.begin(), iter, Fragment::createNucleus);
|
---|
| 343 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 344 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
| 347 | {
|
---|
| 348 | // tests positions for no containment in otherfragment (but last)
|
---|
| 349 | Fragment::nuclei_t invalidnuclei(positions.size()-1);
|
---|
| 350 | std::transform(positions.begin(), --positions.end(),
|
---|
| 351 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
---|
| 352 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 353 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
---|
| 354 | }
|
---|
| 355 | }
|
---|
| 356 | {
|
---|
| 357 | // tests otherpositions for containment in otherfragment
|
---|
| 358 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
---|
| 359 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 360 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 361 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 362 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /** UnitTest for operator-=()
|
---|
| 369 | */
|
---|
| 370 | void FragmentTest::operatorMinusEqual_NonOverlapping_Test()
|
---|
| 371 | {
|
---|
| 372 | {
|
---|
| 373 | // create non-overlapping set
|
---|
| 374 | Fragment::positions_t otherpositions;
|
---|
| 375 | Fragment::position_t otherpos(3, 2.);
|
---|
| 376 | otherpositions += otherpos;
|
---|
| 377 | otherpos[0] = 0.;
|
---|
| 378 | otherpositions += otherpos;
|
---|
| 379 | otherpos[1] = 0.;
|
---|
| 380 | otherpositions += otherpos;
|
---|
| 381 | Fragment::charges_t othercharges;
|
---|
| 382 | othercharges += 1., 2., 3.;
|
---|
| 383 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 384 | const size_t othersize = otherfragment.nuclei.size();
|
---|
| 385 | const size_t size = fragment->nuclei.size();
|
---|
| 386 | *fragment -= otherfragment;
|
---|
| 387 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
---|
| 388 | CPPUNIT_ASSERT_EQUAL( size, fragment->nuclei.size() );
|
---|
| 389 | {
|
---|
| 390 | // tests positions for containment
|
---|
| 391 | Fragment::nuclei_t validnuclei(positions.size());
|
---|
| 392 | std::transform(positions.begin(), positions.end(),
|
---|
| 393 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 394 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 395 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 | {
|
---|
| 399 | // tests otherpositions for no containment
|
---|
| 400 | Fragment::nuclei_t invalidnuclei(otherpositions.size());
|
---|
| 401 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 402 | othercharges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
---|
| 403 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 404 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
---|
| 405 | }
|
---|
| 406 | }
|
---|
| 407 | {
|
---|
| 408 | // tests positions for no containment in otherfragment
|
---|
| 409 | Fragment::nuclei_t invalidnuclei(positions.size());
|
---|
| 410 | std::transform(positions.begin(), positions.end(),
|
---|
| 411 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
---|
| 412 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 413 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
| 416 | {
|
---|
| 417 | // tests otherpositions for containment in otherfragment
|
---|
| 418 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
---|
| 419 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 420 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 421 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 422 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | /** UnitTest for operator-=()
|
---|
| 429 | */
|
---|
| 430 | void FragmentTest::operatorMinusEqual_Test()
|
---|
| 431 | {
|
---|
| 432 | {
|
---|
| 433 | // create overlapping set (first overlaps although with different charge)
|
---|
| 434 | Fragment::positions_t otherpositions;
|
---|
| 435 | Fragment::position_t otherpos(3, 1.);
|
---|
| 436 | otherpositions += otherpos;
|
---|
| 437 | otherpos[0] = 2.;
|
---|
| 438 | otherpositions += otherpos;
|
---|
| 439 | otherpos[1] = 2.;
|
---|
| 440 | otherpositions += otherpos;
|
---|
| 441 | Fragment::charges_t othercharges;
|
---|
| 442 | othercharges += 1., 2., 3.;
|
---|
| 443 | Fragment otherfragment(otherpositions, othercharges);
|
---|
| 444 | const size_t othersize = otherfragment.nuclei.size();
|
---|
| 445 | const size_t size = fragment->nuclei.size();
|
---|
| 446 | CPPUNIT_ASSERT( Fragment::isPositionEqual(otherpositions[0],positions[3]) );
|
---|
| 447 | *fragment -= otherfragment;
|
---|
| 448 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
---|
| 449 | CPPUNIT_ASSERT_EQUAL( size-1, fragment->nuclei.size() ); // just one overlaps
|
---|
| 450 | {
|
---|
| 451 | // tests all but last for containment
|
---|
| 452 | Fragment::nuclei_t validnuclei(positions.size());
|
---|
| 453 | std::transform(positions.begin(), positions.end(),
|
---|
| 454 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 455 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 456 | if (Fragment::isPositionEqual(nucleus.first, otherpositions[0])) // only test position
|
---|
| 457 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
---|
| 458 | else
|
---|
| 459 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
---|
| 460 | }
|
---|
| 461 | }
|
---|
| 462 | {
|
---|
| 463 | // tests positions for no containment in otherfragment
|
---|
| 464 | Fragment::nuclei_t invalidnuclei(positions.size()-1);
|
---|
| 465 | std::transform(positions.begin(), --positions.end(),
|
---|
| 466 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
---|
| 467 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
---|
| 468 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
---|
| 469 | }
|
---|
| 470 | }
|
---|
| 471 | {
|
---|
| 472 | // tests otherpositions for containment in otherfragment
|
---|
| 473 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
---|
| 474 | std::transform(otherpositions.begin(), otherpositions.end(),
|
---|
| 475 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
---|
| 476 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
---|
| 477 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
---|
| 478 | }
|
---|
| 479 | }
|
---|
| 480 | }
|
---|
| 481 | }
|
---|