[0dc8bf2] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2017 Frederik Heber. 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 | * BoostGraphCreatorUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: May 19, 2017
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
| 41 | #include <boost/assign.hpp>
|
---|
| 42 |
|
---|
| 43 | #include "CodePatterns/Assert.hpp"
|
---|
| 44 |
|
---|
| 45 | #include "Atom/atom.hpp"
|
---|
| 46 | #include "Graph/BoostGraphCreator.hpp"
|
---|
| 47 | #include "molecule.hpp"
|
---|
| 48 | #include "Element/periodentafel.hpp"
|
---|
| 49 | #include "World.hpp"
|
---|
| 50 |
|
---|
| 51 | #include "BoostGraphCreatorUnitTest.hpp"
|
---|
| 52 |
|
---|
| 53 | #ifdef HAVE_TESTRUNNER
|
---|
| 54 | #include "UnitTestMain.hpp"
|
---|
| 55 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 56 |
|
---|
| 57 | using namespace boost::assign;
|
---|
| 58 |
|
---|
| 59 | /********************************************** Test classes **************************************/
|
---|
| 60 |
|
---|
| 61 | // Registers the fixture into the 'registry'
|
---|
| 62 | CPPUNIT_TEST_SUITE_REGISTRATION( BoostGraphCreatorTest );
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | void BoostGraphCreatorTest::setUp()
|
---|
| 66 | {
|
---|
| 67 | BGCreator = new BoostGraphCreator;
|
---|
| 68 |
|
---|
| 69 | // construct element
|
---|
| 70 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
| 71 | carbon = World::getInstance().getPeriode()->FindElement(6);
|
---|
| 72 | CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
|
---|
| 73 | CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
|
---|
| 74 |
|
---|
| 75 | // construct molecule (tetraeder of hydrogens)
|
---|
| 76 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 77 | CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
|
---|
| 78 | atom *Walker = World::getInstance().createAtom();
|
---|
| 79 | CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
|
---|
| 80 | Walker->setType(carbon);
|
---|
| 81 | Walker->setPosition(Vector(5., 5., 5. ));
|
---|
| 82 | TestMolecule->AddAtom(Walker);
|
---|
| 83 |
|
---|
| 84 | atom *OtherWalker = World::getInstance().createAtom();
|
---|
| 85 | CPPUNIT_ASSERT(OtherWalker != NULL && "could not create atom");
|
---|
| 86 | OtherWalker->setType(carbon);
|
---|
| 87 | Walker->setPosition(Vector(6.5, 5., 5. ));
|
---|
| 88 | TestMolecule->AddAtom(OtherWalker);
|
---|
| 89 | Walker->addBond(OtherWalker);
|
---|
| 90 |
|
---|
| 91 | atom *HWalker = World::getInstance().createAtom();
|
---|
| 92 | CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
|
---|
| 93 | HWalker->setType(hydrogen);
|
---|
| 94 | HWalker->setPosition(Vector(4.3, 4.5, 5. ));
|
---|
| 95 | TestMolecule->AddAtom(HWalker);
|
---|
| 96 | Walker->addBond(HWalker);
|
---|
| 97 |
|
---|
| 98 | HWalker = World::getInstance().createAtom();
|
---|
| 99 | CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
|
---|
| 100 | HWalker->setType(hydrogen);
|
---|
| 101 | HWalker->setPosition(Vector(4.3, 5.5, 5. ));
|
---|
| 102 | TestMolecule->AddAtom(HWalker);
|
---|
| 103 | Walker->addBond(HWalker);
|
---|
| 104 |
|
---|
| 105 | HWalker = World::getInstance().createAtom();
|
---|
| 106 | CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
|
---|
| 107 | HWalker->setType(hydrogen);
|
---|
| 108 | HWalker->setPosition(Vector(7.2, 4.5, 5. ));
|
---|
| 109 | TestMolecule->AddAtom(HWalker);
|
---|
| 110 | OtherWalker->addBond(HWalker);
|
---|
| 111 |
|
---|
| 112 | HWalker = World::getInstance().createAtom();
|
---|
| 113 | CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
|
---|
| 114 | HWalker->setType(hydrogen);
|
---|
| 115 | HWalker->setPosition(Vector(7.2, 5.5, 5. ));
|
---|
| 116 | TestMolecule->AddAtom(HWalker);
|
---|
| 117 | OtherWalker->addBond(HWalker);
|
---|
| 118 |
|
---|
| 119 | // check that TestMolecule was correctly constructed
|
---|
| 120 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 6 );
|
---|
| 121 |
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | void BoostGraphCreatorTest::tearDown()
|
---|
| 126 | {
|
---|
| 127 | delete BGCreator;
|
---|
| 128 |
|
---|
| 129 | // remove molecule
|
---|
| 130 | World::getInstance().destroyMolecule(TestMolecule);
|
---|
| 131 | // note that all the atoms, molecules, the tafel and the elements
|
---|
| 132 | // are all cleaned when the world is destroyed
|
---|
| 133 | World::purgeInstance();
|
---|
| 134 | logger::purgeInstance();
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | /** Tests whether setup works.
|
---|
| 138 | */
|
---|
| 139 | void BoostGraphCreatorTest::SetupTest()
|
---|
| 140 | {
|
---|
| 141 | // CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | /** Tests whether createFromRange() works.
|
---|
| 145 | */
|
---|
| 146 | void BoostGraphCreatorTest::createFromRangeTest()
|
---|
| 147 | {
|
---|
| 148 | // CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | static bool AlwaysTruePredicate(const bond &_bond) { return true; }
|
---|
| 152 |
|
---|
| 153 | /** Tests whether createFromMolecule() works.
|
---|
| 154 | */
|
---|
| 155 | void BoostGraphCreatorTest::createFromMoleculeTest()
|
---|
| 156 | {
|
---|
| 157 | BGCreator->createFromMolecule(*TestMolecule, AlwaysTruePredicate);
|
---|
| 158 |
|
---|
| 159 | CPPUNIT_ASSERT_EQUAL ((size_t)6, BGCreator->getNumVertices());
|
---|
| 160 | CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumEdges());
|
---|
| 161 | };
|
---|
| 162 |
|
---|
| 163 | /** Tests whether createFromAtoms() works.
|
---|
| 164 | */
|
---|
| 165 | void BoostGraphCreatorTest::createFromAtomsTest()
|
---|
| 166 | {
|
---|
| 167 | std::vector<atom *> atoms;
|
---|
| 168 | std::copy(TestMolecule->begin(), TestMolecule->end(), std::back_inserter(atoms));
|
---|
| 169 | BGCreator->createFromAtoms(atoms, AlwaysTruePredicate);
|
---|
| 170 |
|
---|
| 171 | CPPUNIT_ASSERT_EQUAL ((size_t)6, BGCreator->getNumVertices());
|
---|
| 172 | CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumEdges());
|
---|
| 173 | };
|
---|