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