[baac79] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010-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/>.
|
---|
[baac79] | 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'
|
---|
| 63 | CPPUNIT_TEST_SUITE_REGISTRATION( IsVoidNode_FillPredicateTest );
|
---|
| 64 |
|
---|
| 65 | void DoSomething(atom * const _atom)
|
---|
| 66 | {
|
---|
| 67 | _atom->setPosition( Vector((double)_atom->getId(), 0., 0.) );
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void 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(&World::createAtom, World::getPointer()) );
|
---|
| 83 |
|
---|
| 84 | // position them
|
---|
| 85 | std::for_each(atoms.begin(), atoms.end(), &DoSomething);
|
---|
| 86 |
|
---|
| 87 | predicate = new FillPredicate(IsVoidNode_FillPredicate(Sphere()));
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | void IsVoidNode_FillPredicateTest::tearDown()
|
---|
| 92 | {
|
---|
| 93 | delete predicate;
|
---|
| 94 |
|
---|
| 95 | World::purgeInstance();
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | /** Test whether operator() returns as desired
|
---|
| 99 | *
|
---|
| 100 | */
|
---|
| 101 | void IsVoidNode_FillPredicateTest::operatorTest()
|
---|
| 102 | {
|
---|
| 103 | #ifndef NDEBUG
|
---|
| 104 | std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
|
---|
| 105 | CPPUNIT_ASSERT_THROW( (*predicate)( Vector(-2.,0.,0.)), Assert::AssertionFailure );
|
---|
| 106 | #else
|
---|
| 107 | CPPUNIT_ASSERT( (*predicate)( Vector(-2.,0.,0.)) );
|
---|
| 108 | #endif
|
---|
| 109 | for (double i = 0; i < 5.; ++i) {
|
---|
| 110 | CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., 0.)) );
|
---|
| 111 | CPPUNIT_ASSERT( !(*predicate)( Vector(i, 1., 0.)) );
|
---|
| 112 | #ifndef NDEBUG
|
---|
| 113 | std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
|
---|
| 114 | CPPUNIT_ASSERT_THROW( (*predicate)( Vector(i, -1., 0.)), Assert::AssertionFailure );
|
---|
| 115 | #else
|
---|
| 116 | CPPUNIT_ASSERT( !(*predicate)( Vector(i, -1., 0.)) );
|
---|
| 117 | #endif
|
---|
| 118 | CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., 1.)) );
|
---|
| 119 | #ifndef NDEBUG
|
---|
| 120 | std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
|
---|
| 121 | CPPUNIT_ASSERT_THROW( (*predicate)( Vector(i, 0., -1.)), Assert::AssertionFailure );
|
---|
| 122 | #else
|
---|
| 123 | CPPUNIT_ASSERT( !(*predicate)( Vector(i, 0., -1.)) );
|
---|
| 124 | #endif
|
---|
| 125 | }
|
---|
| 126 | CPPUNIT_ASSERT( (*predicate)( Vector(5.,1.,0.)) );
|
---|
| 127 | #ifndef NDEBUG
|
---|
| 128 | std::cout << "The following Assertion is intended and does not represent a failure of the test." << std::endl;
|
---|
| 129 | CPPUNIT_ASSERT_THROW( (*predicate)( Vector(5.,-1.,0.)), Assert::AssertionFailure );
|
---|
| 130 | #else
|
---|
| 131 | CPPUNIT_ASSERT( (*predicate)( Vector(5.,-1.,0.)) );
|
---|
| 132 | #endif
|
---|
| 133 | CPPUNIT_ASSERT( (*predicate)( Vector(5.,0.,1.)) );
|
---|
| 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( (*predicate)( Vector(5.,0.,-1.)), Assert::AssertionFailure );
|
---|
| 137 | #else
|
---|
| 138 | CPPUNIT_ASSERT( (*predicate)( Vector(5.,0.,-1.)) );
|
---|
| 139 | #endif
|
---|
| 140 | CPPUNIT_ASSERT( (*predicate)( Vector(6.,0.,0.)) );
|
---|
| 141 | }
|
---|