| [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 |
|
|---|
| [a576eb] | 41 | // include headers that implement a archive in simple text format
|
|---|
| 42 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 44 |
|
|---|
| [f3bc5f] | 45 | #include "FragmentUnitTest.hpp"
|
|---|
| 46 |
|
|---|
| 47 | #include <algorithm>
|
|---|
| 48 | #include <limits>
|
|---|
| 49 |
|
|---|
| 50 | #include <boost/assign.hpp>
|
|---|
| 51 | #include <boost/foreach.hpp>
|
|---|
| 52 |
|
|---|
| [a576eb] | 53 | #include <sstream>
|
|---|
| 54 |
|
|---|
| [f3bc5f] | 55 | #include "CodePatterns/Assert.hpp"
|
|---|
| 56 |
|
|---|
| 57 | #ifdef HAVE_TESTRUNNER
|
|---|
| 58 | #include "UnitTestMain.hpp"
|
|---|
| 59 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 60 |
|
|---|
| 61 | using namespace boost::assign;
|
|---|
| 62 |
|
|---|
| 63 | /********************************************** Test classes **************************************/
|
|---|
| 64 |
|
|---|
| 65 | // Registers the fixture into the 'registry'
|
|---|
| 66 | CPPUNIT_TEST_SUITE_REGISTRATION( FragmentTest );
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | void FragmentTest::setUp()
|
|---|
| 70 | {
|
|---|
| 71 | // failing asserts should be thrown
|
|---|
| 72 | ASSERT_DO(Assert::Throw);
|
|---|
| 73 |
|
|---|
| 74 | Fragment::position_t pos(3,0.);
|
|---|
| 75 | positions += pos;
|
|---|
| 76 | pos[0] = 1.;
|
|---|
| 77 | positions += pos;
|
|---|
| 78 | pos[1] = 1.;
|
|---|
| 79 | positions += pos;
|
|---|
| 80 | pos[2] = 1.;
|
|---|
| 81 | positions += pos;
|
|---|
| 82 | charges += 1., 2., 3., 4.;
|
|---|
| 83 | CPPUNIT_ASSERT_EQUAL( (size_t)3, pos.size() );
|
|---|
| 84 | CPPUNIT_ASSERT( positions.size() == charges.size() );
|
|---|
| 85 |
|
|---|
| 86 | fragment = new Fragment(positions, charges);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | void FragmentTest::tearDown()
|
|---|
| 91 | {
|
|---|
| 92 | delete fragment;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /** UnitTest for isPositionEqual()
|
|---|
| 96 | */
|
|---|
| 97 | void FragmentTest::isPositionEqual_Test()
|
|---|
| 98 | {
|
|---|
| 99 | // same position
|
|---|
| 100 | for (Fragment::positions_t::const_iterator iter = positions.begin();
|
|---|
| 101 | iter != positions.end(); ++iter)
|
|---|
| 102 | CPPUNIT_ASSERT( Fragment::isPositionEqual(*iter, *iter) );
|
|---|
| 103 |
|
|---|
| 104 | // other position
|
|---|
| 105 | Fragment::position_t unequalpos(3,2.);
|
|---|
| 106 | for (Fragment::positions_t::const_iterator iter = positions.begin();
|
|---|
| 107 | iter != positions.end(); ++iter)
|
|---|
| 108 | CPPUNIT_ASSERT( !Fragment::isPositionEqual(*iter, unequalpos) );
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | /** UnitTest for containsNuclei()
|
|---|
| 113 | */
|
|---|
| 114 | void FragmentTest::containsNuclei_Test()
|
|---|
| 115 | {
|
|---|
| 116 | {
|
|---|
| 117 | // tests present ones for containment
|
|---|
| 118 | Fragment::nuclei_t validnuclei(positions.size());
|
|---|
| 119 | std::transform(positions.begin(), positions.end(),
|
|---|
| 120 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 121 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 122 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | {
|
|---|
| 127 | // test some others
|
|---|
| 128 | Fragment::nuclei_t invalidnuclei;
|
|---|
| 129 | Fragment::position_t pos(3, -1.);
|
|---|
| 130 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 131 | pos[0] = 0.;
|
|---|
| 132 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 133 | pos[1] = 0.;
|
|---|
| 134 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 135 | pos[2] = -std::numeric_limits<double>::epsilon()*1e+4;
|
|---|
| 136 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 137 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 138 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | /** UnitTest for removeNuclei()
|
|---|
| 144 | */
|
|---|
| 145 | void FragmentTest::removeNuclei_Test()
|
|---|
| 146 | {
|
|---|
| 147 | {
|
|---|
| 148 | // tests present ones for removal
|
|---|
| 149 | size_t size = fragment->nuclei.size();
|
|---|
| 150 | Fragment::nuclei_t validnuclei(positions.size());
|
|---|
| 151 | std::transform(positions.begin(), positions.end(),
|
|---|
| 152 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 153 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 154 | CPPUNIT_ASSERT_NO_THROW( fragment->removeNuclei(nucleus) );
|
|---|
| 155 | CPPUNIT_ASSERT_EQUAL( --size, fragment->nuclei.size() );
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 | {
|
|---|
| 159 | // test some others
|
|---|
| 160 | Fragment::nuclei_t invalidnuclei;
|
|---|
| 161 | Fragment::position_t pos(3, -1.);
|
|---|
| 162 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 163 | pos[0] = 0;
|
|---|
| 164 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 165 | pos[1] = 0;
|
|---|
| 166 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 167 | pos[2] = -std::numeric_limits<double>::epsilon()*1e+4;
|
|---|
| 168 | invalidnuclei += Fragment::createNucleus(pos, 1.);
|
|---|
| 169 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 170 | CPPUNIT_ASSERT_NO_THROW( fragment->removeNuclei(nucleus) );
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | /** UnitTest for operator==() for Fragment::nucleus_t
|
|---|
| 176 | */
|
|---|
| 177 | void FragmentTest::equalityNucleus_Test()
|
|---|
| 178 | {
|
|---|
| 179 | Fragment::nuclei_t validnuclei(positions.size());
|
|---|
| 180 | std::transform(positions.begin(), positions.end(),
|
|---|
| 181 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 182 | {
|
|---|
| 183 | // create some nuclei
|
|---|
| 184 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 185 | CPPUNIT_ASSERT( nucleus == nucleus );
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | {
|
|---|
| 190 | // create nucleus at other position
|
|---|
| 191 | Fragment::position_t pos(3, 2.);
|
|---|
| 192 | Fragment::nucleus_t unequalposnucleus(pos, 1.);
|
|---|
| 193 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 194 | CPPUNIT_ASSERT( nucleus != unequalposnucleus );
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | {
|
|---|
| 199 | // create nucleus with different charge
|
|---|
| 200 | Fragment::position_t pos(3, 1.);
|
|---|
| 201 | Fragment::nucleus_t unequalchargenucleus(pos, 5.);
|
|---|
| 202 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 203 | CPPUNIT_ASSERT( nucleus != unequalchargenucleus );
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | /** UnitTest for operator==()
|
|---|
| 209 | */
|
|---|
| 210 | void FragmentTest::equality_Test()
|
|---|
| 211 | {
|
|---|
| 212 | // create different fragment
|
|---|
| 213 | Fragment::positions_t otherpositions;
|
|---|
| 214 | Fragment::position_t otherpos(3, 2.);
|
|---|
| 215 | otherpositions += otherpos;
|
|---|
| 216 | otherpos[0] = 0.;
|
|---|
| 217 | otherpositions += otherpos;
|
|---|
| 218 | otherpos[1] = 0.;
|
|---|
| 219 | otherpositions += otherpos;
|
|---|
| 220 | Fragment::charges_t othercharges;
|
|---|
| 221 | othercharges += 1., 2., 3.;
|
|---|
| 222 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 223 |
|
|---|
| 224 | CPPUNIT_ASSERT( !(*fragment == otherfragment) );
|
|---|
| 225 | CPPUNIT_ASSERT( *fragment != otherfragment );
|
|---|
| 226 |
|
|---|
| 227 | // test against empty fragment
|
|---|
| 228 | Fragment emptyfragment;
|
|---|
| 229 | CPPUNIT_ASSERT( !(*fragment == emptyfragment) );
|
|---|
| 230 | CPPUNIT_ASSERT( *fragment != emptyfragment );
|
|---|
| 231 |
|
|---|
| 232 | // tests against themselves
|
|---|
| 233 | CPPUNIT_ASSERT( *fragment == *fragment );
|
|---|
| 234 | CPPUNIT_ASSERT( otherfragment == otherfragment );
|
|---|
| 235 | CPPUNIT_ASSERT( emptyfragment == emptyfragment );
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | /** UnitTest for operator+=()
|
|---|
| 239 | */
|
|---|
| 240 | void FragmentTest::assignment_Test()
|
|---|
| 241 | {
|
|---|
| 242 | // create different fragment
|
|---|
| 243 | Fragment::positions_t otherpositions;
|
|---|
| 244 | Fragment::position_t otherpos(3, 2.);
|
|---|
| 245 | otherpositions += otherpos;
|
|---|
| 246 | otherpos[0] = 0.;
|
|---|
| 247 | otherpositions += otherpos;
|
|---|
| 248 | otherpos[1] = 0.;
|
|---|
| 249 | otherpositions += otherpos;
|
|---|
| 250 | Fragment::charges_t othercharges;
|
|---|
| 251 | othercharges += 1., 2., 3.;
|
|---|
| 252 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 253 |
|
|---|
| 254 | // check for inequality
|
|---|
| 255 | CPPUNIT_ASSERT( otherfragment.nuclei.size() != fragment->nuclei.size() );
|
|---|
| 256 | CPPUNIT_ASSERT( otherfragment != *fragment );
|
|---|
| 257 |
|
|---|
| 258 | //assign
|
|---|
| 259 | otherfragment = *fragment;
|
|---|
| 260 |
|
|---|
| 261 | // check for equality
|
|---|
| 262 | CPPUNIT_ASSERT( otherfragment.nuclei.size() == fragment->nuclei.size() );
|
|---|
| 263 | CPPUNIT_ASSERT( otherfragment == *fragment );
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | /** UnitTest for operator+=()
|
|---|
| 267 | */
|
|---|
| 268 | void FragmentTest::operatorPlusEqual_NonOverlapping_Test()
|
|---|
| 269 | {
|
|---|
| 270 | {
|
|---|
| 271 | // create non-overlapping set
|
|---|
| 272 | Fragment::positions_t otherpositions;
|
|---|
| 273 | Fragment::position_t otherpos(3, 2.);
|
|---|
| 274 | otherpositions += otherpos;
|
|---|
| 275 | otherpos[0] = 0.;
|
|---|
| 276 | otherpositions += otherpos;
|
|---|
| 277 | otherpos[1] = 0.;
|
|---|
| 278 | otherpositions += otherpos;
|
|---|
| 279 | Fragment::charges_t othercharges;
|
|---|
| 280 | othercharges += 1., 2., 3.;
|
|---|
| 281 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 282 | const size_t othersize = otherfragment.nuclei.size();
|
|---|
| 283 | const size_t size = fragment->nuclei.size();
|
|---|
| 284 | *fragment += otherfragment;
|
|---|
| 285 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
|---|
| 286 | CPPUNIT_ASSERT_EQUAL( size+othersize, fragment->nuclei.size() );
|
|---|
| 287 | {
|
|---|
| 288 | // tests all for containment
|
|---|
| 289 | Fragment::nuclei_t validnuclei(positions.size()+otherpositions.size());
|
|---|
| 290 | Fragment::nuclei_t::iterator iter =
|
|---|
| 291 | std::transform(positions.begin(), positions.end(),
|
|---|
| 292 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 293 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 294 | othercharges.begin(), iter, Fragment::createNucleus);
|
|---|
| 295 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 296 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
|---|
| 297 | }
|
|---|
| 298 | }
|
|---|
| 299 | {
|
|---|
| 300 | // tests positions for no containment in otherfragment
|
|---|
| 301 | Fragment::nuclei_t invalidnuclei(positions.size());
|
|---|
| 302 | std::transform(positions.begin(), positions.end(),
|
|---|
| 303 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
|---|
| 304 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 305 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
|---|
| 306 | }
|
|---|
| 307 | }
|
|---|
| 308 | {
|
|---|
| 309 | // tests otherpositions for containment in otherfragment
|
|---|
| 310 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
|---|
| 311 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 312 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 313 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 314 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
|---|
| 315 | }
|
|---|
| 316 | }
|
|---|
| 317 | }
|
|---|
| 318 | }
|
|---|
| 319 |
|
|---|
| 320 | /** UnitTest for operator+=()
|
|---|
| 321 | */
|
|---|
| 322 | void FragmentTest::operatorPlusEqual_Test()
|
|---|
| 323 | {
|
|---|
| 324 | {
|
|---|
| 325 | // create overlapping set (first overlaps)
|
|---|
| 326 | Fragment::positions_t otherpositions;
|
|---|
| 327 | Fragment::position_t otherpos(3, 1.);
|
|---|
| 328 | otherpositions += otherpos;
|
|---|
| 329 | otherpos[0] = 2.;
|
|---|
| 330 | otherpositions += otherpos;
|
|---|
| 331 | otherpos[1] = 2.;
|
|---|
| 332 | otherpositions += otherpos;
|
|---|
| 333 | Fragment::charges_t othercharges;
|
|---|
| 334 | othercharges += 1., 2., 3.;
|
|---|
| 335 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 336 | const size_t othersize = otherfragment.nuclei.size();
|
|---|
| 337 | const size_t size = fragment->nuclei.size();
|
|---|
| 338 | *fragment += otherfragment;
|
|---|
| 339 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
|---|
| 340 | CPPUNIT_ASSERT_EQUAL( size+othersize-1, fragment->nuclei.size() ); // one for already present
|
|---|
| 341 | {
|
|---|
| 342 | // tests all for containment
|
|---|
| 343 | Fragment::nuclei_t validnuclei(positions.size()+otherpositions.size());
|
|---|
| 344 | Fragment::nuclei_t::iterator iter =
|
|---|
| 345 | std::transform(positions.begin(), positions.end(),
|
|---|
| 346 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 347 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 348 | othercharges.begin(), iter, Fragment::createNucleus);
|
|---|
| 349 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 350 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
|---|
| 351 | }
|
|---|
| 352 | }
|
|---|
| 353 | {
|
|---|
| 354 | // tests positions for no containment in otherfragment (but last)
|
|---|
| 355 | Fragment::nuclei_t invalidnuclei(positions.size()-1);
|
|---|
| 356 | std::transform(positions.begin(), --positions.end(),
|
|---|
| 357 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
|---|
| 358 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 359 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
|---|
| 360 | }
|
|---|
| 361 | }
|
|---|
| 362 | {
|
|---|
| 363 | // tests otherpositions for containment in otherfragment
|
|---|
| 364 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
|---|
| 365 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 366 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 367 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 368 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
|---|
| 369 | }
|
|---|
| 370 | }
|
|---|
| 371 | }
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | /** UnitTest for operator-=()
|
|---|
| 375 | */
|
|---|
| 376 | void FragmentTest::operatorMinusEqual_NonOverlapping_Test()
|
|---|
| 377 | {
|
|---|
| 378 | {
|
|---|
| 379 | // create non-overlapping set
|
|---|
| 380 | Fragment::positions_t otherpositions;
|
|---|
| 381 | Fragment::position_t otherpos(3, 2.);
|
|---|
| 382 | otherpositions += otherpos;
|
|---|
| 383 | otherpos[0] = 0.;
|
|---|
| 384 | otherpositions += otherpos;
|
|---|
| 385 | otherpos[1] = 0.;
|
|---|
| 386 | otherpositions += otherpos;
|
|---|
| 387 | Fragment::charges_t othercharges;
|
|---|
| 388 | othercharges += 1., 2., 3.;
|
|---|
| 389 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 390 | const size_t othersize = otherfragment.nuclei.size();
|
|---|
| 391 | const size_t size = fragment->nuclei.size();
|
|---|
| 392 | *fragment -= otherfragment;
|
|---|
| 393 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
|---|
| 394 | CPPUNIT_ASSERT_EQUAL( size, fragment->nuclei.size() );
|
|---|
| 395 | {
|
|---|
| 396 | // tests positions for containment
|
|---|
| 397 | Fragment::nuclei_t validnuclei(positions.size());
|
|---|
| 398 | std::transform(positions.begin(), positions.end(),
|
|---|
| 399 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 400 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 401 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
|---|
| 402 | }
|
|---|
| 403 | }
|
|---|
| 404 | {
|
|---|
| 405 | // tests otherpositions for no containment
|
|---|
| 406 | Fragment::nuclei_t invalidnuclei(otherpositions.size());
|
|---|
| 407 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 408 | othercharges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
|---|
| 409 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 410 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
|---|
| 411 | }
|
|---|
| 412 | }
|
|---|
| 413 | {
|
|---|
| 414 | // tests positions for no containment in otherfragment
|
|---|
| 415 | Fragment::nuclei_t invalidnuclei(positions.size());
|
|---|
| 416 | std::transform(positions.begin(), positions.end(),
|
|---|
| 417 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
|---|
| 418 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 419 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
|---|
| 420 | }
|
|---|
| 421 | }
|
|---|
| 422 | {
|
|---|
| 423 | // tests otherpositions for containment in otherfragment
|
|---|
| 424 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
|---|
| 425 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 426 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 427 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 428 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
|---|
| 429 | }
|
|---|
| 430 | }
|
|---|
| 431 | }
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | /** UnitTest for operator-=()
|
|---|
| 435 | */
|
|---|
| 436 | void FragmentTest::operatorMinusEqual_Test()
|
|---|
| 437 | {
|
|---|
| 438 | {
|
|---|
| 439 | // create overlapping set (first overlaps although with different charge)
|
|---|
| 440 | Fragment::positions_t otherpositions;
|
|---|
| 441 | Fragment::position_t otherpos(3, 1.);
|
|---|
| 442 | otherpositions += otherpos;
|
|---|
| 443 | otherpos[0] = 2.;
|
|---|
| 444 | otherpositions += otherpos;
|
|---|
| 445 | otherpos[1] = 2.;
|
|---|
| 446 | otherpositions += otherpos;
|
|---|
| 447 | Fragment::charges_t othercharges;
|
|---|
| 448 | othercharges += 1., 2., 3.;
|
|---|
| 449 | Fragment otherfragment(otherpositions, othercharges);
|
|---|
| 450 | const size_t othersize = otherfragment.nuclei.size();
|
|---|
| 451 | const size_t size = fragment->nuclei.size();
|
|---|
| 452 | CPPUNIT_ASSERT( Fragment::isPositionEqual(otherpositions[0],positions[3]) );
|
|---|
| 453 | *fragment -= otherfragment;
|
|---|
| 454 | CPPUNIT_ASSERT_EQUAL( othersize, otherfragment.nuclei.size() );
|
|---|
| 455 | CPPUNIT_ASSERT_EQUAL( size-1, fragment->nuclei.size() ); // just one overlaps
|
|---|
| 456 | {
|
|---|
| 457 | // tests all but last for containment
|
|---|
| 458 | Fragment::nuclei_t validnuclei(positions.size());
|
|---|
| 459 | std::transform(positions.begin(), positions.end(),
|
|---|
| 460 | charges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 461 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 462 | if (Fragment::isPositionEqual(nucleus.first, otherpositions[0])) // only test position
|
|---|
| 463 | CPPUNIT_ASSERT( !fragment->containsNuclei(nucleus) );
|
|---|
| 464 | else
|
|---|
| 465 | CPPUNIT_ASSERT( fragment->containsNuclei(nucleus) );
|
|---|
| 466 | }
|
|---|
| 467 | }
|
|---|
| 468 | {
|
|---|
| 469 | // tests positions for no containment in otherfragment
|
|---|
| 470 | Fragment::nuclei_t invalidnuclei(positions.size()-1);
|
|---|
| 471 | std::transform(positions.begin(), --positions.end(),
|
|---|
| 472 | charges.begin(), invalidnuclei.begin(), Fragment::createNucleus);
|
|---|
| 473 | BOOST_FOREACH( Fragment::nucleus_t nucleus, invalidnuclei) {
|
|---|
| 474 | CPPUNIT_ASSERT( !otherfragment.containsNuclei(nucleus) );
|
|---|
| 475 | }
|
|---|
| 476 | }
|
|---|
| 477 | {
|
|---|
| 478 | // tests otherpositions for containment in otherfragment
|
|---|
| 479 | Fragment::nuclei_t validnuclei(otherpositions.size());
|
|---|
| 480 | std::transform(otherpositions.begin(), otherpositions.end(),
|
|---|
| 481 | othercharges.begin(), validnuclei.begin(), Fragment::createNucleus);
|
|---|
| 482 | BOOST_FOREACH( Fragment::nucleus_t nucleus, validnuclei) {
|
|---|
| 483 | CPPUNIT_ASSERT( otherfragment.containsNuclei(nucleus) );
|
|---|
| 484 | }
|
|---|
| 485 | }
|
|---|
| 486 | }
|
|---|
| 487 | }
|
|---|
| [a576eb] | 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 | /** UnitTest for serialization
|
|---|
| 492 | */
|
|---|
| 493 | void FragmentTest::serializeTest()
|
|---|
| 494 | {
|
|---|
| 495 | // serialize
|
|---|
| 496 | std::stringstream outputstream;
|
|---|
| 497 | boost::archive::text_oarchive oa(outputstream);
|
|---|
| 498 | oa << fragment;
|
|---|
| 499 |
|
|---|
| 500 | // deserialize
|
|---|
| 501 | Fragment *samefragment = NULL;
|
|---|
| 502 | std::stringstream returnstream(outputstream.str());
|
|---|
| 503 | boost::archive::text_iarchive ia(returnstream);
|
|---|
| 504 | ia >> samefragment;
|
|---|
| 505 |
|
|---|
| 506 | CPPUNIT_ASSERT( *fragment == *samefragment );
|
|---|
| 507 |
|
|---|
| 508 | delete samefragment;
|
|---|
| 509 | }
|
|---|