/* * 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 . */ /* * SamplingGridPropertiesUnitTest.cpp * * Created on: Jul 29, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif using namespace std; #include #include #include // include headers that implement a archive in simple text format #include #include #include "SamplingGridPropertiesUnitTest.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( SamplingGridPropertiesTest ); void SamplingGridPropertiesTest::setUp() { // failing asserts should be thrown ASSERT_DO(Assert::Throw); // create the grid const double begin[3] = { 0., 0., 0. }; const double end[3] = { 1., 1., 1. }; props = new SamplingGridProperties(begin, end, 2); } void SamplingGridPropertiesTest::tearDown() { delete props; } /** UnitTest for isEquivalent() */ void SamplingGridPropertiesTest::isEquivalent_Test() { const double begin[3] = { 0., 0., 0. }; const double otherbegin[3] = { 1., 0.1, -0.5 }; const double end[3] = { 1., 1., 1. }; const double otherend[3] = { 2., 2., 2. }; // create other props SamplingGridProperties sameprops(begin, end, 2); SamplingGridProperties otherprops(otherbegin, end, 2); SamplingGridProperties anotherprops(begin, otherend, 2); SamplingGridProperties moreotherprops(begin, end, 4); // only checks for same level CPPUNIT_ASSERT( props->isEquivalent(*props) ); CPPUNIT_ASSERT( props->isEquivalent(sameprops) ); CPPUNIT_ASSERT( sameprops.isEquivalent(*props) ); CPPUNIT_ASSERT( !props->isEquivalent(otherprops) ); CPPUNIT_ASSERT( !otherprops.isEquivalent(*props) ); CPPUNIT_ASSERT( !props->isEquivalent(anotherprops) ); CPPUNIT_ASSERT( !anotherprops.isEquivalent(*props) ); CPPUNIT_ASSERT( !props->isEquivalent(moreotherprops) ); CPPUNIT_ASSERT( !moreotherprops.isEquivalent(*props) ); } /** UnitTest for isCompatible() */ void SamplingGridPropertiesTest::isCompatible_Test() { const double begin[3] = { 0., 0., 0. }; const double otherbegin[3] = { .5, .5, .5 }; const double end[3] = { 1., 1., 1. }; const double otherend[3] = { 2., 2., 2. }; // create other props SamplingGridProperties sameprops(begin, end, 2); // same SamplingGridProperties secondhalf(otherbegin, end, 2); // second half SamplingGridProperties goingbeyond(begin, otherend, 2); // going beyond SamplingGridProperties finerlevel(begin, end, 4); // same but different level // only checks for same level CPPUNIT_ASSERT( props->isCompatible(*props) ); CPPUNIT_ASSERT( props->isCompatible(sameprops) ); CPPUNIT_ASSERT( sameprops.isCompatible(*props) ); CPPUNIT_ASSERT( props->isCompatible(secondhalf) ); CPPUNIT_ASSERT( !secondhalf.isCompatible(*props) ); CPPUNIT_ASSERT( !props->isCompatible(goingbeyond) ); CPPUNIT_ASSERT( goingbeyond.isCompatible(*props) ); CPPUNIT_ASSERT( props->isCompatible(finerlevel) ); CPPUNIT_ASSERT( !finerlevel.isCompatible(*props) ); } /** UnitTest for operator==() */ void SamplingGridPropertiesTest::equality_Test() { const double begin[3] = { 0., 0., 0. }; const double otherbegin[3] = { 1., 0.1, -0.5 }; const double end[3] = { 1., 1., 1. }; const double otherend[3] = { 2., 2., 2. }; // create other props SamplingGridProperties sameprops(begin, end, 2); SamplingGridProperties otherprops(otherbegin, end, 2); SamplingGridProperties anotherprops(begin, otherend, 2); SamplingGridProperties moreotherprops(begin, end, 4); // check for same level, begin, and end CPPUNIT_ASSERT( *props == *props ); CPPUNIT_ASSERT( *props == sameprops ); CPPUNIT_ASSERT( sameprops == *props); CPPUNIT_ASSERT( *props != otherprops); CPPUNIT_ASSERT( otherprops != *props); CPPUNIT_ASSERT( *props != anotherprops ); CPPUNIT_ASSERT( anotherprops != *props ); CPPUNIT_ASSERT( *props != moreotherprops ); CPPUNIT_ASSERT( moreotherprops != *props ); // check against ZeroInstance CPPUNIT_ASSERT( *props != ZeroInstance() ); CPPUNIT_ASSERT( sameprops != ZeroInstance() ); CPPUNIT_ASSERT( otherprops != ZeroInstance() ); CPPUNIT_ASSERT( anotherprops != ZeroInstance() ); CPPUNIT_ASSERT( moreotherprops != ZeroInstance() ); } /** UnitTest for serialization */ void SamplingGridPropertiesTest::serializeTest() { // serialize std::stringstream outputstream; boost::archive::text_oarchive oa(outputstream); oa << props; // deserialize SamplingGridProperties *sameprops = NULL; std::stringstream returnstream(outputstream.str()); boost::archive::text_iarchive ia(returnstream); ia >> sameprops; CPPUNIT_ASSERT( sameprops != NULL ); CPPUNIT_ASSERT( *props == *sameprops ); delete sameprops; }