source: src/Filling/unittests/IsVoidNode_FillPredicateUnitTest.cpp@ 98ad30

Candidate_v1.7.1 stable
Last change on this file since 98ad30 was 25aa214, checked in by Frederik Heber <frederik.heber@…>, 2 weeks 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.6 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 * IsVoidNode_FillPredicateUnitTest.cpp
25 *
26 * Created on: Jan 18, 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#include <boost/bind.hpp>
41#include <iostream>
42
43#include "CodePatterns/Assert.hpp"
44
45#include "Atom/atom.hpp"
46#include "Box.hpp"
47#include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
48#include "LinearAlgebra/RealSpaceMatrix.hpp"
49#include "Filling/NodeTypes.hpp"
50#include "Shapes/BaseShapes.hpp"
51#include "Shapes/Shape.hpp"
52#include "World.hpp"
53
54#include "IsVoidNode_FillPredicateUnitTest.hpp"
55
56#ifdef HAVE_TESTRUNNER
57#include "UnitTestMain.hpp"
58#endif /*HAVE_TESTRUNNER*/
59
60/********************************************** Test classes **************************************/
61
62// Registers the fixture into the 'registry'
63CPPUNIT_TEST_SUITE_REGISTRATION( IsVoidNode_FillPredicateTest );
64
65void DoSomething(atom * const _atom)
66{
67 _atom->setPosition( Vector((double)_atom->getId(), 0., 0.) );
68}
69
70void IsVoidNode_FillPredicateTest::setUp()
71{
72 // failing asserts should be thrown
73 ASSERT_DO(Assert::Throw);
74
75 // set default BCs to ignore
76 World::getInstance().getDomain().setConditions(
77 BoundaryConditions::Conditions_t(3, BoundaryConditions::Ignore)
78 );
79
80 // create some atoms as "neighbours"
81 atoms.resize((size_t)5, NULL);
82 std::generate_n(atoms.begin(), (size_t)5, boost::bind(
83 static_cast<atom* (World::*)(World::CreateAtomNotificationType)>(&World::createAtom),
84 World::getPointer(),
85 World::CreateAtomNotificationType::NOTIFY_ON_CREATE_ATOM)
86 );
87
88 // position them
89 std::for_each(atoms.begin(), atoms.end(), &DoSomething);
90
91 predicate = new FillPredicate(IsVoidNode_FillPredicate(Sphere()));
92}
93
94
95void IsVoidNode_FillPredicateTest::tearDown()
96{
97 delete predicate;
98
99 World::purgeInstance();
100}
101
102/** Test whether operator() returns as desired
103 *
104 */
105void IsVoidNode_FillPredicateTest::operatorTest()
106{
107#ifndef NDEBUG
108 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
109 CPPUNIT_ASSERT_THROW( (*predicate)( Vector(-2.,0.,0.)), Assert::AssertionFailure );
110#else
111 CPPUNIT_ASSERT( (*predicate)( Vector(-2.,0.,0.)) );
112#endif
113 for (double i = 0; i < 5.; ++i) {
114 CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., 0.)) );
115 CPPUNIT_ASSERT( !(*predicate)( Vector(i, 1., 0.)) );
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( (*predicate)( Vector(i, -1., 0.)), Assert::AssertionFailure );
119#else
120 CPPUNIT_ASSERT( !(*predicate)( Vector(i, -1., 0.)) );
121#endif
122 CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., 1.)) );
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( (*predicate)( Vector(i, 0., -1.)), Assert::AssertionFailure );
126#else
127 CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., -1.)) );
128#endif
129 }
130 CPPUNIT_ASSERT( (*predicate)( Vector(5.,1.,0.)) );
131#ifndef NDEBUG
132 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
133 CPPUNIT_ASSERT_THROW( (*predicate)( Vector(5.,-1.,0.)), Assert::AssertionFailure );
134#else
135 CPPUNIT_ASSERT( (*predicate)( Vector(5.,-1.,0.)) );
136#endif
137 CPPUNIT_ASSERT( (*predicate)( Vector(5.,0.,1.)) );
138#ifndef NDEBUG
139 std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
140 CPPUNIT_ASSERT_THROW( (*predicate)( Vector(5.,0.,-1.)), Assert::AssertionFailure );
141#else
142 CPPUNIT_ASSERT( (*predicate)( Vector(5.,0.,-1.)) );
143#endif
144 CPPUNIT_ASSERT( (*predicate)( Vector(6.,0.,0.)) );
145}
Note: See TracBrowser for help on using the repository browser.