/* * 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 . */ /* * SamplingGridUnitTest.cpp * * Created on: Jul 29, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif using namespace std; #include #include #include #include "SamplingGridUnitTest.hpp" #include "CodePatterns/Assert.hpp" #include #include #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ using namespace boost::assign; /********************************************** Test classes **************************************/ const double grid_value=1.; // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( SamplingGridTest ); void SamplingGridTest::setUp() { // failing asserts should be thrown ASSERT_DO(Assert::Throw); // create the grid const double begin[3] = { 0., 0., 0. }; for (size_t i=0; i< pow(pow(2,2),3); ++i) values += grid_value; grid = new SamplingGrid(begin, 1., 2, values); CPPUNIT_ASSERT_EQUAL( grid_value, *(grid->sampled_grid.begin()) ); } void SamplingGridTest::tearDown() { delete grid; } #define NUMBEROFSAMPLES(n) pow(pow(2,n),3) /** UnitTest for operator+=() */ void SamplingGridTest::superposeOtherGrid_Test() { // check illegal grid const double begin[3] = { 0., 0., 0. }; SamplingGridProperties illegal_props(begin, 2., 1); CPPUNIT_ASSERT( !grid->isCompatible(illegal_props) ); SamplingGrid::sampledvalues_t illegal_values; for (size_t i=0; i< NUMBEROFSAMPLES(1); ++i) illegal_values += 1.5; SamplingGrid illegal_grid(illegal_props, illegal_values); #ifndef NDEBUG CPPUNIT_ASSERT_THROW( *grid += illegal_grid, Assert::AssertionFailure ); #else *grid += illegal_grid; #endif // check that grid is still the same for (SamplingGrid::sampledvalues_t::const_iterator iter = grid->sampled_grid.begin(); iter != grid->sampled_grid.end(); ++iter) CPPUNIT_ASSERT_EQUAL( grid_value, *iter ); } /** UnitTest for operator+=() */ void SamplingGridTest::operatorPlusEqual_Test() { // create other grid const double begin[3] = { 0., 0., 0. }; SamplingGrid::sampledvalues_t othervalues; const double othergrid_value = 1.5; for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i) othervalues += othergrid_value; SamplingGrid othergrid(begin, 1., 2, othervalues); CPPUNIT_ASSERT_EQUAL( othergrid_value, *(othergrid.sampled_grid.begin()) ); // perform operation CPPUNIT_ASSERT_NO_THROW( *grid += othergrid ); // check the contents of the grid const double sum = grid_value+othergrid_value; for (SamplingGrid::sampledvalues_t::const_iterator iter = grid->sampled_grid.begin(); iter != grid->sampled_grid.end(); ++iter) CPPUNIT_ASSERT_EQUAL( sum, *iter ); } /** UnitTest for operator-=() */ void SamplingGridTest::operatorMinusEqual_Test() { // create other grid const double begin[3] = { 0., 0., 0. }; SamplingGrid::sampledvalues_t othervalues; const double othergrid_value = 1.5; for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i) othervalues += othergrid_value; SamplingGrid othergrid(begin, 1., 2, othervalues); CPPUNIT_ASSERT_EQUAL( othergrid_value, *(othergrid.sampled_grid.begin()) ); // perform operation CPPUNIT_ASSERT_NO_THROW( *grid -= othergrid ); // check the contents of the grid const double difference = grid_value-othergrid_value; for (SamplingGrid::sampledvalues_t::const_iterator iter = grid->sampled_grid.begin(); iter != grid->sampled_grid.end(); ++iter) CPPUNIT_ASSERT_EQUAL( difference, *iter ); }