/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 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 .
*/
/*
* ExtractorsUnitTest.cpp
*
* Created on: Oct 16, 2012
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
using namespace std;
#include
#include
#include
#include "ExtractorsUnitTest.hpp"
#include
#include "CodePatterns/Assert.hpp"
#include "FunctionApproximation/Extractors.hpp"
#include "Potentials/helpers.hpp"
using namespace boost::assign;
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( ExtractorsTest );
void ExtractorsTest::setUp()
{
// failing asserts should be thrown
ASSERT_DO(Assert::Throw);
}
void ExtractorsTest::tearDown()
{
}
/** UnitTest for gatherAllDistanceArguments()
*/
void ExtractorsTest::gatherAllDistanceArgumentsTest()
{
// create positions
Fragment::positions_t positions;
Fragment::position_t pos(3, 0.);
for (double i = 0; i < 5; i+=1.) {
pos[0] = i;
positions.push_back(pos);
}
// create charges
Fragment::charges_t charges;
charges += 6., 6., 1., 1., 1.;
// create distances
FunctionModel::arguments_t args =
Extractors::gatherAllDistanceArguments(positions, charges, 0);
CPPUNIT_ASSERT_EQUAL( (size_t)(5*4), args.size() );
// check created args
for (size_t i=0; i< 5*4; ++i)
CPPUNIT_ASSERT( (args[i].distance >= 0) && (args[i].distance <= 4));
}
/** UnitTest for gatherPositionsFromFragment()
*/
void ExtractorsTest::gatherPositionsFromFragmentTest()
{
// create positions
Fragment::positions_t positions;
Fragment::position_t pos(3, 0.);
for (double i = 0; i < 5; i+=1.) {
pos[0] = i;
positions.push_back(pos);
}
// create charges
Fragment::charges_t charges;
charges += 6., 6., 1., 1., 1.;
{
// extract carbon pairs
Fragment::charges_t carbonpair;
carbonpair += 6.,6.;
Fragment::positions_t filtered_positions =
Extractors::gatherPositionsFromFragment(positions, charges, carbonpair);
CPPUNIT_ASSERT_EQUAL( (size_t)2, filtered_positions.size() );
}
{
// extract hydrogen triple
Fragment::charges_t hydrogentriple;
hydrogentriple += 1.,1.,1.;
Fragment::positions_t filtered_positions =
Extractors::gatherPositionsFromFragment(positions, charges, hydrogentriple);
CPPUNIT_ASSERT_EQUAL( (size_t)3, filtered_positions.size() );
}
}
/** UnitTest for gatherDistancesFromFragment()
*/
void ExtractorsTest::gatherDistancesFromFragmentTest()
{
// create positions
Fragment::positions_t positions;
Fragment::position_t pos(3, 0.);
for (double i = 0; i < 5; i+=1.) {
pos[0] = i;
positions.push_back(pos);
}
// create charges
Fragment::charges_t charges;
charges += 6., 6., 1., 1., 1.;
{
// extract carbon pairs
Fragment::charges_t carbonpair;
carbonpair += 6.,6.;
FunctionModel::arguments_t args =
Extractors::gatherDistancesFromFragment(positions, charges, carbonpair, 0);
CPPUNIT_ASSERT_EQUAL( (size_t)1, args.size() );
}
{
// extract hydrogen triple
Fragment::charges_t hydrogentriple;
hydrogentriple += 1.,1.,1.;
FunctionModel::arguments_t args =
Extractors::gatherDistancesFromFragment(positions, charges, hydrogentriple, 0);
CPPUNIT_ASSERT_EQUAL( (size_t)3, args.size() );
}
}
/** UnitTest for reorderArgumentsByIncreasingDistance()
*/
void ExtractorsTest::reorderArgumentsByIncreasingDistanceTest()
{
// prepare some arguments
FunctionModel::arguments_t args;
argument_t arg;
arg.distance = 0.1;
args.push_back(arg);
arg.distance = 0.9;
args.push_back(arg);
arg.distance = 0.3;
args.push_back(arg);
CPPUNIT_ASSERT_EQUAL( (size_t)3, args.size() );
// reorder
FunctionModel::arguments_t args_sorted =
Extractors::reorderArgumentsByIncreasingDistance(args);
CPPUNIT_ASSERT_EQUAL( (size_t)3, args_sorted.size() );
CPPUNIT_ASSERT_EQUAL( args[0].distance, args_sorted[0].distance );
CPPUNIT_ASSERT_EQUAL( args[1].distance, args_sorted[2].distance );
CPPUNIT_ASSERT_EQUAL( args[2].distance, args_sorted[1].distance );
}