source: src/Filling/unittests/Ops_FillPredicateUnitTest.cpp@ bc58f2

Candidate_v1.7.1 stable
Last change on this file since bc58f2 was 25aa214, checked in by Frederik Heber <frederik.heber@…>, 10 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: 9.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-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 * Ops_FillPredicateUnitTest.cpp
25 *
26 * Created on: Jan 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 "CodePatterns/Assert.hpp"
40
41#include "Atom/atom.hpp"
42#include "Box.hpp"
43#include "Filling/Predicates/IsValidInDomain_FillPredicate.hpp"
44#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
45#include "Filling/Predicates/Ops_FillPredicate.hpp"
46#include "LinearAlgebra/RealSpaceMatrix.hpp"
47#include "Filling/NodeTypes.hpp"
48#include "Shapes/BaseShapes.hpp"
49#include "World.hpp"
50
51#include "Ops_FillPredicateUnitTest.hpp"
52
53#ifdef HAVE_TESTRUNNER
54#include "UnitTestMain.hpp"
55#endif /*HAVE_TESTRUNNER*/
56
57/********************************************** Test classes **************************************/
58
59// Registers the fixture into the 'registry'
60CPPUNIT_TEST_SUITE_REGISTRATION( Ops_FillPredicateTest );
61
62void DoSomething(atom * const _atom)
63{
64 _atom->setPosition( Vector((double)_atom->getId(), 0., 0.) );
65}
66
67void Ops_FillPredicateTest::setUp()
68{
69 // failing asserts should be thrown
70 ASSERT_DO(Assert::Throw);
71
72 // set default BCs to ignore
73 World::getInstance().getDomain().setConditions(
74 BoundaryConditions::Conditions_t(3, BoundaryConditions::Ignore)
75 );
76
77 Domainpredicate = new FillPredicate(IsValidInDomain_FillPredicate(World::getInstance().getDomain()));
78
79 // create some atoms as "neighbours"
80 atoms.resize((size_t)5, NULL);
81 std::generate_n(atoms.begin(), (size_t)5, boost::bind(
82 static_cast<atom* (World::*)(World::CreateAtomNotificationType)>(&World::createAtom),
83 World::getPointer(),
84 World::CreateAtomNotificationType::NOTIFY_ON_CREATE_ATOM) );
85
86 // position them
87 std::for_each(atoms.begin(), atoms.end(), &DoSomething);
88
89 Voidpredicate = new FillPredicate(IsVoidNode_FillPredicate(Sphere()));
90}
91
92
93void Ops_FillPredicateTest::tearDown()
94{
95 delete Domainpredicate;
96 delete Voidpredicate;
97
98 World::purgeInstance();
99}
100
101/** Test whether operator() returns as desired
102 *
103 */
104void Ops_FillPredicateTest::AndTest()
105{
106 FillPredicate Andpredicate = (*Domainpredicate) && (*Voidpredicate);
107
108 CPPUNIT_ASSERT( !Andpredicate( Vector(-1.,1.,0.)) );
109 CPPUNIT_ASSERT( !Andpredicate( Vector(-2.,0.,0.)) );
110 CPPUNIT_ASSERT( Andpredicate( Vector(5.,1.,0.)) );
111 CPPUNIT_ASSERT( Andpredicate( Vector(5.,0.,1.)) );
112 for (double i = 0; i < 5.; ++i) {
113 CPPUNIT_ASSERT( !Andpredicate( Vector(i, 0., 0.)) );
114 CPPUNIT_ASSERT( !Andpredicate( Vector(i, 1., 0.)) );
115 CPPUNIT_ASSERT( !Andpredicate( Vector(i, -1., 0.)) );
116 CPPUNIT_ASSERT( !Andpredicate( Vector(i, 0., 1.)) );
117 CPPUNIT_ASSERT( !Andpredicate( Vector(i, 0., -1.)) );
118 }
119 CPPUNIT_ASSERT( !Andpredicate( Vector(5.,-1.,0.)) );
120 CPPUNIT_ASSERT( Andpredicate( Vector(5.,0.,1.)) );
121 CPPUNIT_ASSERT( !Andpredicate( Vector(5.,0.,-1.)) );
122 CPPUNIT_ASSERT( Andpredicate( Vector(6.,0.,0.)) );
123}
124/** Test whether operator() returns as desired
125 *
126 */
127void Ops_FillPredicateTest::OrTest()
128{
129 FillPredicate Orpredicate = (*Domainpredicate) || (*Voidpredicate);
130
131 // in OR case: Voidpredicate will always throw because it internally checks
132 // whether Linked Cell structure gets correct index to cell, which fails under
133 // Ignore boundary conditions
134#ifndef NDEBUG
135 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
136 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(-1.,1.,0.)), Assert::AssertionFailure );
137#else
138 CPPUNIT_ASSERT( Orpredicate( Vector(-1.,1.,0.)) );
139#endif
140 CPPUNIT_ASSERT( Orpredicate( Vector(5.,1.,0.)) );
141#ifndef NDEBUG
142 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
143 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(-2.,0.,0.)), Assert::AssertionFailure );
144#else
145 CPPUNIT_ASSERT( Orpredicate( Vector(-2.,0.,0.)) );
146#endif
147 for (double i = 0; i < 5.; ++i) {
148 CPPUNIT_ASSERT( Orpredicate( Vector(i, 0., 0.)) );
149 CPPUNIT_ASSERT( Orpredicate( Vector(i, 1., 0.)) );
150#ifndef NDEBUG
151 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
152 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(i, -1., 0.)), Assert::AssertionFailure );
153#else
154 CPPUNIT_ASSERT( !Orpredicate( Vector(i, -1., 0.)) );
155#endif
156 CPPUNIT_ASSERT( Orpredicate( Vector(i, 0., 1.)) );
157#ifndef NDEBUG
158 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
159 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(i, 0., -1.)), Assert::AssertionFailure );
160#else
161 CPPUNIT_ASSERT( !Orpredicate( Vector(i, 0., -1.)) );
162#endif
163 }
164 CPPUNIT_ASSERT( Orpredicate( Vector(5.,1.,0.)) );
165#ifndef NDEBUG
166 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
167 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(5.,-1.,0.)), Assert::AssertionFailure );
168#else
169 CPPUNIT_ASSERT( Orpredicate( Vector(5.,-1.,0.)) );
170#endif
171 CPPUNIT_ASSERT( Orpredicate( Vector(5.,0.,1.)) );
172#ifndef NDEBUG
173 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
174 CPPUNIT_ASSERT_THROW( Orpredicate( Vector(5.,0.,-1.)), Assert::AssertionFailure );
175#else
176 CPPUNIT_ASSERT( Orpredicate( Vector(5.,0.,-1.)) );
177#endif
178 CPPUNIT_ASSERT( Orpredicate( Vector(6.,0.,0.)) );
179}
180
181/** Test whether operator!() returns as desired
182 *
183 */
184void Ops_FillPredicateTest::NotTest()
185{
186 Box &domain = World::getInstance().getDomain();
187 Node origin(0.,0.,0.);
188 Node center(10.,10.,10.);
189 Node corner(20.,20.,20.);
190 Node outside(30.,30.,30.);
191
192 FillPredicate Notpredicate = !(*Domainpredicate);
193 FillPredicate Notpredicate2 = !(*Voidpredicate);
194
195 domain.setConditions(
196 BoundaryConditions::Conditions_t(3, BoundaryConditions::Wrap)
197 );
198 // boundary conditions: Wrap
199 {
200 // origin is inside
201 CPPUNIT_ASSERT( !Notpredicate(origin) );
202
203 // center is inside
204 CPPUNIT_ASSERT( !Notpredicate(center) );
205
206 // corner is inside
207 CPPUNIT_ASSERT( !Notpredicate(corner) );
208
209 // outside is outside
210 CPPUNIT_ASSERT( !Notpredicate(outside) );
211 }
212
213 // boundary conditions: Bounce
214 {
215 domain.setCondition(0, BoundaryConditions::Bounce);
216 // origin is inside
217 CPPUNIT_ASSERT( !Notpredicate(origin) );
218
219 // center is inside
220 CPPUNIT_ASSERT( !Notpredicate(center) );
221
222 // corner is inside
223 CPPUNIT_ASSERT( !Notpredicate(corner) );
224
225 // outside is outside
226 CPPUNIT_ASSERT( !Notpredicate(outside) );
227 domain.setCondition(0, BoundaryConditions::Wrap);
228 }
229
230 // boundary conditions: Ignore
231 {
232 domain.setCondition(0, BoundaryConditions::Ignore);
233 // origin is inside
234 CPPUNIT_ASSERT( !Notpredicate(origin) );
235
236 // center is inside
237 CPPUNIT_ASSERT( !Notpredicate(center) );
238
239 // corner is inside
240 CPPUNIT_ASSERT( !Notpredicate(corner) );
241
242 // outside is outside
243 CPPUNIT_ASSERT( Notpredicate(outside) );
244 domain.setCondition(0, BoundaryConditions::Wrap);
245 }
246
247 // set BCs back to default Ignore
248 domain.setConditions(
249 BoundaryConditions::Conditions_t(3, BoundaryConditions::Ignore)
250 );
251 // check on not void
252#ifndef NDEBUG
253 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
254 CPPUNIT_ASSERT_THROW( Notpredicate2( Vector(-2.,0.,0.)), Assert::AssertionFailure );
255#else
256 CPPUNIT_ASSERT( !Notpredicate2( Vector(-2.,0.,0.)) );
257#endif
258 for (double i = 0; i < 5.; ++i) {
259 CPPUNIT_ASSERT( Notpredicate2( Vector(i, 0., 0.)) );
260 CPPUNIT_ASSERT( Notpredicate2( Vector(i, 1., 0.)) );
261#ifndef NDEBUG
262 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
263 CPPUNIT_ASSERT_THROW( Notpredicate2( Vector(i, -1., 0.)), Assert::AssertionFailure );
264#else
265 CPPUNIT_ASSERT( Notpredicate2( Vector(i, -1., 0.)) );
266#endif
267 CPPUNIT_ASSERT( Notpredicate2( Vector(i, 0., 1.)) );
268#ifndef NDEBUG
269 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
270 CPPUNIT_ASSERT_THROW( Notpredicate2( Vector(i, 0., -1.)), Assert::AssertionFailure );
271#else
272 CPPUNIT_ASSERT( Notpredicate2( Vector(i, 0., -1.)) );
273#endif
274 }
275 CPPUNIT_ASSERT( !Notpredicate2( Vector(5.,1.,0.)) );
276#ifndef NDEBUG
277 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
278 CPPUNIT_ASSERT_THROW( Notpredicate2( Vector(5.,-1.,0.)), Assert::AssertionFailure );
279#else
280 CPPUNIT_ASSERT( !Notpredicate2( Vector(5.,-1.,0.)) );
281#endif
282 CPPUNIT_ASSERT( !Notpredicate2( Vector(5.,0.,1.)) );
283#ifndef NDEBUG
284 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
285 CPPUNIT_ASSERT_THROW( Notpredicate2( Vector(5.,0.,-1.)), Assert::AssertionFailure );
286#else
287 CPPUNIT_ASSERT( !Notpredicate2( Vector(5.,0.,-1.)) );
288#endif
289 CPPUNIT_ASSERT( !Notpredicate2( Vector(6.,0.,0.)) );
290}
Note: See TracBrowser for help on using the repository browser.