[c67ff9] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 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/>.
|
---|
[c67ff9] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * MoleculeUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Mar 19, 2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include <cppunit/CompilerOutputter.h>
|
---|
| 36 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 37 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 38 |
|
---|
| 39 | #include <algorithm>
|
---|
| 40 |
|
---|
| 41 | #include "Atom/atom.hpp"
|
---|
| 42 | #include "CodePatterns/Assert.hpp"
|
---|
| 43 | #include "Element/element.hpp"
|
---|
| 44 | #include "Element/periodentafel.hpp"
|
---|
| 45 | #include "molecule.hpp"
|
---|
| 46 |
|
---|
| 47 | #include "MoleculeUnitTest.hpp"
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | #ifdef HAVE_TESTRUNNER
|
---|
| 51 | #include "UnitTestMain.hpp"
|
---|
| 52 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 53 |
|
---|
| 54 | /********************************************** Test classes **************************************/
|
---|
| 55 |
|
---|
| 56 | // Registers the fixture into the 'registry'
|
---|
| 57 | CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeUnittest );
|
---|
| 58 |
|
---|
| 59 | size_t MoleculeUnittest::MaxAtoms = 6;
|
---|
| 60 |
|
---|
| 61 | void MoleculeUnittest::setUp(){
|
---|
| 62 | // failing asserts should be thrown
|
---|
| 63 | ASSERT_DO(Assert::Throw);
|
---|
| 64 |
|
---|
| 65 | atomVector.resize((size_t)MaxAtoms);
|
---|
| 66 | std::generate_n(atomVector.begin(), MaxAtoms,
|
---|
| 67 | boost::bind(&World::createAtom, boost::ref(World::getInstance())));
|
---|
| 68 | std::for_each(atomVector.begin(), atomVector.end(),
|
---|
| 69 | boost::bind(static_cast<void (AtomInfo::*)(int)>(&AtomInfo::setType), _1, (atomicNumber_t)1));
|
---|
| 70 |
|
---|
| 71 | mol = new molecule;
|
---|
| 72 | std::for_each(atomVector.begin(), atomVector.end(),
|
---|
| 73 | boost::bind(&molecule::AddAtom, boost::ref(mol), _1));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void MoleculeUnittest::tearDown()
|
---|
| 77 | {
|
---|
| 78 | delete mol;
|
---|
| 79 | World::purgeInstance();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /** Unit test for molecule::getBoundingShape() with a linear chain
|
---|
| 83 | *
|
---|
| 84 | */
|
---|
| 85 | void MoleculeUnittest::getBoundingShapeTest_linearchain()
|
---|
| 86 | {
|
---|
| 87 | // prepare a chain of atoms
|
---|
| 88 | double offset = 0.;
|
---|
| 89 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
| 90 | _atom->setPosition( Vector(offset, 0., 0.) );
|
---|
| 91 | offset += 1.;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | {
|
---|
| 95 | // get bounding shape
|
---|
| 96 | Shape s = mol->getBoundingShape();
|
---|
| 97 |
|
---|
| 98 | // check that each atom is truely inside the shape
|
---|
| 99 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
| 100 | CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /** Unit test for molecule::getBoundingShape() with a v-shaped molecule.
|
---|
| 106 | *
|
---|
| 107 | */
|
---|
| 108 | void MoleculeUnittest::getBoundingShapeTest_vshaped()
|
---|
| 109 | {
|
---|
| 110 | double xoffset = -2.5;
|
---|
| 111 | double yoffset = -2.5;
|
---|
| 112 | double yadder = -1;
|
---|
| 113 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
| 114 | _atom->setPosition( Vector(xoffset, yoffset, 0.) );
|
---|
| 115 | xoffset += 1.;
|
---|
| 116 | yoffset -= yadder;
|
---|
| 117 | if (yoffset <= 0) {
|
---|
| 118 | yadder = 1.;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | {
|
---|
| 123 | // get bounding shape
|
---|
| 124 | Shape s = mol->getBoundingShape();
|
---|
| 125 |
|
---|
| 126 | // check that each atom is truely inside the shape
|
---|
| 127 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
| 128 | CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|