/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2012 University of Bonn. All rights reserved.
* Copyright (C) 2013 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 .
*/
/*
* MPQCDataUnitTest.cpp
*
* Created on: Feb 09, 2012
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
// include headers that implement a archive in simple text format
#include
#include
#include
#include
#include "MPQCDataUnitTest.hpp"
#include "Fragmentation/Summation/Containers/MPQCData.hpp"
#include "CodePatterns/Assert.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( MPQCDataTest );
void MPQCDataTest::setUp()
{
// Throw assertions
ASSERT_DO(Assert::Throw);
data = new MPQCData;
data->energies.total = -37.3479855;
std::vector force;
std::vector< std::vector > forces;
force.push_back(-2.35);
force.push_back(-0.54);
force.push_back(0.345);
data->forces.push_back(force);
force.clear();
force.push_back(-2.35);
force.push_back(-0.54);
force.push_back(0.345);
data->forces.push_back( force );
CPPUNIT_ASSERT_EQUAL( (size_t)2, data->forces.size() );
}
void MPQCDataTest::tearDown()
{
delete data;
}
/** UnitTest for operator==()
*/
void MPQCDataTest::operatorTest()
{
MPQCData otherData;
// ascertain unequality
CPPUNIT_ASSERT( !(*data == otherData) );
CPPUNIT_ASSERT( *data != otherData );
// construct closer and closer pendant
otherData.energies.total = -37.3479855;
CPPUNIT_ASSERT( *data != otherData );
std::vector force;
std::vector< std::vector > forces;
force.push_back(-2.35);
force.push_back(-0.54);
force.push_back(0.345);
otherData.forces.push_back(force);
CPPUNIT_ASSERT( *data != otherData );
force.clear();
force.push_back(-2.35);
force.push_back(-0.54);
force.push_back(0.345);
otherData.forces.push_back( force );
CPPUNIT_ASSERT( *data == otherData );
// change energy
otherData.energies.total = -4;
CPPUNIT_ASSERT( *data != otherData );
otherData.energies.total = -37.3479855;
CPPUNIT_ASSERT( *data == otherData );
// change force component
otherData.forces[0][2] = -4;
CPPUNIT_ASSERT( *data != otherData );
otherData.forces[0][2] = 0.345;
CPPUNIT_ASSERT( *data == otherData );
// check sensibility
otherData.energies.total -= 1e-1*std::numeric_limits::epsilon();
CPPUNIT_ASSERT( *data == otherData );
otherData.forces[1][0] -= 1e-1*std::numeric_limits::epsilon();
CPPUNIT_ASSERT( *data == otherData );
}
/** UnitTest for serialization
*/
void MPQCDataTest::serializationTest()
{
// serialize
std::stringstream outputstream;
boost::archive::text_oarchive oa(outputstream);
oa << data;
// deserialize
MPQCData *extractedData;
std::stringstream returnstream(outputstream.str());
boost::archive::text_iarchive ia(returnstream);
ia >> extractedData;
CPPUNIT_ASSERT( *data == *extractedData );
delete extractedData;
}