/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-2012 University of Bonn. 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 .
*/
/*
* AnalysisCorrelationToPointUnitTest.cpp
*
* Created on: Oct 13, 2009
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
using namespace std;
#include
#include
#include
#include
#include "Analysis/analysis_correlation.hpp"
#include "Atom/atom.hpp"
#include "Descriptors/MoleculeDescriptor.hpp"
#include "Element/element.hpp"
#include "Element/periodentafel.hpp"
#include "molecule.hpp"
#include "World.hpp"
#include "AnalysisCorrelationToPointUnitTest.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
void AnalysisCorrelationToPointUnitTest::setUp()
{
atom *Walker = NULL;
// init private all pointers to zero
TestMolecule = NULL;
pointmap = NULL;
binmap = NULL;
point = NULL;
// construct element list
std::vector elements;
hydrogen = World::getInstance().getPeriode()->FindElement(1);
CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
elements.push_back(hydrogen);
// construct molecule (tetraeder of hydrogens)
TestMolecule = World::getInstance().createMolecule();
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(1., 0., 1. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(0., 1., 1. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(1., 1., 0. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(0., 0., 0. ));
TestMolecule->AddAtom(Walker);
// check that TestMolecule was correctly constructed
CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
TestMolecule->ActiveFlag = true;
// init point
point = new Vector(1.,1.,1.);
// init maps
World::getInstance().selectAllMolecules(AllMolecules());
allMolecules = const_cast(World::getInstance()).getSelectedMolecules();
CPPUNIT_ASSERT_EQUAL( (size_t) 1, allMolecules.size());
pointmap = CorrelationToPoint( allMolecules, elements, (const Vector *)point );
binmap = NULL;
};
void AnalysisCorrelationToPointUnitTest::tearDown()
{
if (pointmap != NULL)
delete(pointmap);
if (binmap != NULL)
delete(binmap);
delete(point);
World::purgeInstance();
logger::purgeInstance();
};
void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
{
// do the pair correlation
CPPUNIT_ASSERT( pointmap != NULL );
CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
};
void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
{
BinPairMap::iterator tester;
// put pair correlation into bins and check with no range
binmap = BinData( pointmap, 0.5, 0., 0. );
OutputCorrelationMap ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
tester = binmap->begin();
CPPUNIT_ASSERT_EQUAL( 1., tester->first );
CPPUNIT_ASSERT_EQUAL( 3, tester->second );
};
void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
{
BinPairMap::iterator tester;
// ... and check with [0., 2.] range
binmap = BinData( pointmap, 0.5, 0., 2. );
OutputCorrelationMap ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
tester = binmap->begin();
CPPUNIT_ASSERT_EQUAL( 0., tester->first );
tester = binmap->find(1.);
CPPUNIT_ASSERT_EQUAL( 1., tester->first );
CPPUNIT_ASSERT_EQUAL( 3, tester->second );
};