/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2017 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* BoostGraphCreatorUnitTest.cpp
*
* Created on: May 19, 2017
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
using namespace std;
#include
#include
#include
#include
#include "CodePatterns/Assert.hpp"
#include "Atom/atom.hpp"
#include "Graph/BoostGraphCreator.hpp"
#include "molecule.hpp"
#include "Element/periodentafel.hpp"
#include "World.hpp"
#include "BoostGraphCreatorUnitTest.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
using namespace boost::assign;
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( BoostGraphCreatorTest );
void BoostGraphCreatorTest::setUp()
{
BGCreator = new BoostGraphCreator;
// construct element
hydrogen = World::getInstance().getPeriode()->FindElement(1);
carbon = World::getInstance().getPeriode()->FindElement(6);
CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
// construct molecule (tetraeder of hydrogens)
TestMolecule = World::getInstance().createMolecule();
CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
atom *Walker = World::getInstance().createAtom();
CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
Walker->setType(carbon);
Walker->setPosition(Vector(5., 5., 5. ));
TestMolecule->AddAtom(Walker);
atom *OtherWalker = World::getInstance().createAtom();
CPPUNIT_ASSERT(OtherWalker != NULL && "could not create atom");
OtherWalker->setType(carbon);
Walker->setPosition(Vector(6.5, 5., 5. ));
TestMolecule->AddAtom(OtherWalker);
Walker->addBond(OtherWalker);
atom *HWalker = World::getInstance().createAtom();
CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
HWalker->setType(hydrogen);
HWalker->setPosition(Vector(4.3, 4.5, 5. ));
TestMolecule->AddAtom(HWalker);
Walker->addBond(HWalker);
HWalker = World::getInstance().createAtom();
CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
HWalker->setType(hydrogen);
HWalker->setPosition(Vector(4.3, 5.5, 5. ));
TestMolecule->AddAtom(HWalker);
Walker->addBond(HWalker);
HWalker = World::getInstance().createAtom();
CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
HWalker->setType(hydrogen);
HWalker->setPosition(Vector(7.2, 4.5, 5. ));
TestMolecule->AddAtom(HWalker);
OtherWalker->addBond(HWalker);
HWalker = World::getInstance().createAtom();
CPPUNIT_ASSERT(HWalker != NULL && "could not create atom");
HWalker->setType(hydrogen);
HWalker->setPosition(Vector(7.2, 5.5, 5. ));
TestMolecule->AddAtom(HWalker);
OtherWalker->addBond(HWalker);
// check that TestMolecule was correctly constructed
CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 6 );
};
void BoostGraphCreatorTest::tearDown()
{
delete BGCreator;
// remove molecule
World::getInstance().destroyMolecule(TestMolecule);
// note that all the atoms, molecules, the tafel and the elements
// are all cleaned when the world is destroyed
World::purgeInstance();
logger::purgeInstance();
};
/** Tests whether setup works.
*/
void BoostGraphCreatorTest::SetupTest()
{
// CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
}
/** Tests whether createFromRange() works.
*/
void BoostGraphCreatorTest::createFromRangeTest()
{
// CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
};
static bool AlwaysTruePredicate(const bond &_bond) { return true; }
/** Tests whether createFromMolecule() works.
*/
void BoostGraphCreatorTest::createFromMoleculeTest()
{
BGCreator->createFromMolecule(*TestMolecule, AlwaysTruePredicate);
CPPUNIT_ASSERT_EQUAL ((size_t)6, BGCreator->getNumVertices());
CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumEdges());
};
/** Tests whether createFromAtoms() works.
*/
void BoostGraphCreatorTest::createFromAtomsTest()
{
std::vector atoms;
std::copy(TestMolecule->begin(), TestMolecule->end(), std::back_inserter(atoms));
BGCreator->createFromAtoms(atoms, AlwaysTruePredicate);
CPPUNIT_ASSERT_EQUAL ((size_t)6, BGCreator->getNumVertices());
CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumEdges());
};