source: src/unittests/MoleculeUnitTest.cpp@ 802a9d

Candidate_v1.7.1 stable
Last change on this file since 802a9d was 25aa214, checked in by Frederik Heber <frederik.heber@…>, 12 days ago

FIX: fragmentation hydrogens do not trigger AtomInserted.

  • we had already switched off position and element changes. However, the fragmentation hydrogens could still be briefly seen on creation because the AtomInserted notification is still triggered. The World::createAtom allows now to suppress the notifcation. The switch options are put into an enum to make them very verbose in the code. This should really only be used by the HydrogenPool.
  • Property mode set to 100644
File size: 4.7 KB
Line 
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 * 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'
57CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeUnittest );
58
59size_t MoleculeUnittest::MaxAtoms = 6;
60
61void 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, boost::bind(
67 static_cast<atom* (World::*)(World::CreateAtomNotificationType)>(&World::createAtom),
68 World::getPointer(),
69 World::CreateAtomNotificationType::NOTIFY_ON_CREATE_ATOM)
70 );
71 std::for_each(atomVector.begin(), atomVector.end(),
72 boost::bind(static_cast<void (AtomInfo::*)(int)>(&AtomInfo::setType), _1, (atomicNumber_t)1));
73
74 mol = new molecule;
75 std::for_each(atomVector.begin(), atomVector.end(),
76 boost::bind(&molecule::AddAtom, boost::ref(mol), _1));
77}
78
79void MoleculeUnittest::tearDown()
80{
81 delete mol;
82 World::purgeInstance();
83}
84
85/** Unit test for molecule::getBoundingSphere() with a linear chain
86 *
87 */
88void MoleculeUnittest::getBoundingSphereTest_linearchain()
89{
90 // prepare a chain of atoms
91 double offset = 0.;
92 BOOST_FOREACH(atom *_atom, atomVector) {
93 _atom->setPosition( Vector(offset, 0., 0.) );
94 offset += 1.;
95 }
96
97 {
98 // get bounding shape
99 Shape s = mol->getBoundingSphere();
100
101 // check that each atom is truely inside the shape
102 BOOST_FOREACH(atom *_atom, atomVector) {
103 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
104 }
105 }
106}
107
108/** Unit test for molecule::getBoundingSphere() with a v-shaped molecule.
109 *
110 */
111void MoleculeUnittest::getBoundingSphereTest_vshaped()
112{
113 double xoffset = -2.5;
114 double yoffset = -2.5;
115 double yadder = -1;
116 BOOST_FOREACH(atom *_atom, atomVector) {
117 _atom->setPosition( Vector(xoffset, yoffset, 0.) );
118 xoffset += 1.;
119 yoffset -= yadder;
120 if (yoffset <= 0) {
121 yadder = 1.;
122 }
123 }
124
125 {
126 // get bounding shape
127 Shape s = mol->getBoundingSphere();
128
129 // check that each atom is truely inside the shape
130 BOOST_FOREACH(atom *_atom, atomVector) {
131 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
132 }
133 }
134}
135
136/** Unit test for molecule::getBoundingShape() with a linear chain
137 *
138 */
139void MoleculeUnittest::getBoundingShapeTest_linearchain()
140{
141 // prepare a chain of atoms
142 double offset = 0.;
143 BOOST_FOREACH(atom *_atom, atomVector) {
144 _atom->setPosition( Vector(offset, 0., 0.) );
145 offset += 1.;
146 }
147
148 {
149 // get bounding shape
150 Shape s = mol->getBoundingShape();
151
152 // check that each atom is truely inside the shape
153 BOOST_FOREACH(atom *_atom, atomVector) {
154 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
155 }
156 }
157}
158
159/** Unit test for molecule::getBoundingShape() with a v-shaped molecule.
160 *
161 */
162void MoleculeUnittest::getBoundingShapeTest_vshaped()
163{
164 double xoffset = -2.5;
165 double yoffset = -2.5;
166 double yadder = -1;
167 BOOST_FOREACH(atom *_atom, atomVector) {
168 _atom->setPosition( Vector(xoffset, yoffset, 0.) );
169 xoffset += 1.;
170 yoffset -= yadder;
171 if (yoffset <= 0) {
172 yadder = 1.;
173 }
174 }
175
176 {
177 // get bounding shape
178 Shape s = mol->getBoundingShape();
179
180 // check that each atom is truely inside the shape
181 BOOST_FOREACH(atom *_atom, atomVector) {
182 CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
183 }
184 }
185}
Note: See TracBrowser for help on using the repository browser.