/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * 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 "Jobs/MPQCCommandJob_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->energy = -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.energy = -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.energy = -4; CPPUNIT_ASSERT( *data != otherData ); otherData.energy = -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.energy -= 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; }