| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| 6 |  * 
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  *   This file is part of MoleCuilder.
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 13 |  *    (at your option) any later version.
 | 
|---|
| 14 |  *
 | 
|---|
| 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 18 |  *    GNU General Public License for more details.
 | 
|---|
| 19 |  *
 | 
|---|
| 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 22 |  */
 | 
|---|
| 23 | 
 | 
|---|
| 24 | /*
 | 
|---|
| 25 |  * SaturatedFragmentUnitTest.cpp
 | 
|---|
| 26 |  *
 | 
|---|
| 27 |  *  Created on: Aug 09, 2012
 | 
|---|
| 28 |  *      Author: heber
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | 
 | 
|---|
| 31 | // include config.h
 | 
|---|
| 32 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 33 | #include <config.h>
 | 
|---|
| 34 | #endif
 | 
|---|
| 35 | 
 | 
|---|
| 36 | using namespace std;
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
| 39 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
| 40 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
| 41 | 
 | 
|---|
| 42 | // include headers that implement a archive in simple text format
 | 
|---|
| 43 | #include <boost/archive/text_oarchive.hpp>
 | 
|---|
| 44 | #include <boost/archive/text_iarchive.hpp>
 | 
|---|
| 45 | 
 | 
|---|
| 46 | #include "SaturatedFragmentUnitTest.hpp"
 | 
|---|
| 47 | 
 | 
|---|
| 48 | #include <boost/assign.hpp>
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 51 | 
 | 
|---|
| 52 | #include "Atom/atom.hpp"
 | 
|---|
| 53 | #include "Atom/AtomObserver.hpp"
 | 
|---|
| 54 | #include "Element/element.hpp"
 | 
|---|
| 55 | #include "Element/periodentafel.hpp"
 | 
|---|
| 56 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
 | 
|---|
| 57 | #include "molecule.hpp"
 | 
|---|
| 58 | #include "World.hpp"
 | 
|---|
| 59 | #include "WorldTime.hpp"
 | 
|---|
| 60 | 
 | 
|---|
| 61 | #ifdef HAVE_TESTRUNNER
 | 
|---|
| 62 | #include "UnitTestMain.hpp"
 | 
|---|
| 63 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
| 64 | 
 | 
|---|
| 65 | using namespace boost::assign;
 | 
|---|
| 66 | 
 | 
|---|
| 67 | /********************************************** Test classes **************************************/
 | 
|---|
| 68 | 
 | 
|---|
| 69 | // Registers the fixture into the 'registry'
 | 
|---|
| 70 | CPPUNIT_TEST_SUITE_REGISTRATION( SaturatedFragmentTest );
 | 
|---|
| 71 | 
 | 
|---|
| 72 | 
 | 
|---|
| 73 | void SaturatedFragmentTest::setUp()
 | 
|---|
| 74 | {
 | 
|---|
| 75 |   // failing asserts should be thrown
 | 
|---|
| 76 |   ASSERT_DO(Assert::Throw);
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   // construct element
 | 
|---|
| 79 |   hydrogen = World::getInstance().getPeriode()->FindElement(1);
 | 
|---|
| 80 |   CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
 | 
|---|
| 81 |   oxygen = World::getInstance().getPeriode()->FindElement(8);
 | 
|---|
| 82 |   CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
 | 
|---|
| 83 | 
 | 
|---|
| 84 |   // construct molecule (tetraeder of hydrogens)
 | 
|---|
| 85 |   TestMolecule = World::getInstance().createMolecule();
 | 
|---|
| 86 |   CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
 | 
|---|
| 87 |   atom * Walker = World::getInstance().createAtom();
 | 
|---|
| 88 |   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
 | 
|---|
| 89 |   Walker->setType(oxygen);
 | 
|---|
| 90 |   Walker->setPosition(Vector(1., 0., 1. ));
 | 
|---|
| 91 |   TestMolecule->AddAtom(Walker);
 | 
|---|
| 92 |   Walker = World::getInstance().createAtom();
 | 
|---|
| 93 |   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
 | 
|---|
| 94 |   Walker->setType(hydrogen);
 | 
|---|
| 95 |   Walker->setPosition(Vector(0., 1., 1. ));
 | 
|---|
| 96 |   TestMolecule->AddAtom(Walker);
 | 
|---|
| 97 |   Walker = World::getInstance().createAtom();
 | 
|---|
| 98 |   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
 | 
|---|
| 99 |   Walker->setType(hydrogen);
 | 
|---|
| 100 |   Walker->setPosition(Vector(1., 1., 0. ));
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   // construct fragment keyset
 | 
|---|
| 103 |   SaturatedFragment::GlobalSaturationPositions_t globalpositions;
 | 
|---|
| 104 |   set = new KeySet;
 | 
|---|
| 105 |   set->insert(0);
 | 
|---|
| 106 |   set->insert(1);
 | 
|---|
| 107 |   set->insert(2);
 | 
|---|
| 108 |   fragment = new SaturatedFragment(
 | 
|---|
| 109 |       *set,
 | 
|---|
| 110 |       KeySetsInUse,
 | 
|---|
| 111 |       hydrogens,
 | 
|---|
| 112 |       ExcludeHydrogen,
 | 
|---|
| 113 |       DoSaturate,
 | 
|---|
| 114 |       globalpositions);
 | 
|---|
| 115 | 
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | 
 | 
|---|
| 119 | void SaturatedFragmentTest::tearDown()
 | 
|---|
| 120 | {
 | 
|---|
| 121 |   delete fragment;
 | 
|---|
| 122 |   delete set;
 | 
|---|
| 123 | 
 | 
|---|
| 124 |   // remove
 | 
|---|
| 125 |   World::getInstance().destroyMolecule(TestMolecule);
 | 
|---|
| 126 |   // note that all the atoms, molecules, the tafel and the elements
 | 
|---|
| 127 |   // are all cleaned when the world is destroyed
 | 
|---|
| 128 |   World::purgeInstance();
 | 
|---|
| 129 |   AtomObserver::purgeInstance();
 | 
|---|
| 130 |   logger::purgeInstance();
 | 
|---|
| 131 |   errorLogger::purgeInstance();
 | 
|---|
| 132 |   WorldTime::purgeInstance();
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | /** UnitTest for getKeySet()
 | 
|---|
| 136 |  */
 | 
|---|
| 137 | void SaturatedFragmentTest::getKeySet_Test()
 | 
|---|
| 138 | {
 | 
|---|
| 139 |   CPPUNIT_ASSERT_EQUAL( *set, fragment->getKeySet() );
 | 
|---|
| 140 | }
 | 
|---|
| 141 | 
 | 
|---|
| 142 | /** UnitTest for getRoughBoundingBox()
 | 
|---|
| 143 |  */
 | 
|---|
| 144 | void SaturatedFragmentTest::getRoughBoundingBox()
 | 
|---|
| 145 | {
 | 
|---|
| 146 |   const std::pair<Vector, Vector> minmax = fragment->getRoughBoundingBox();
 | 
|---|
| 147 |   for (size_t i=0;i<NDIM;++i) {
 | 
|---|
| 148 |     CPPUNIT_ASSERT( minmax.first[i] >= 0. );
 | 
|---|
| 149 |     CPPUNIT_ASSERT( minmax.second[i] <= 1. );
 | 
|---|
| 150 |   }
 | 
|---|
| 151 | }
 | 
|---|