/* * 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 . */ /* * SetValueUnitTest.cpp * * Created on: Jun 27, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif using namespace std; #include #include #include #include "Fragmentation/Summation/IndexSet.hpp" #include "Fragmentation/Summation/IndexSetContainer.hpp" #include "Fragmentation/Summation/SetValue.hpp" #include "SetValueUnitTest.hpp" #include "stubs/SetValueMap_Mock.hpp" #include "stubs/SubsetMap_Mock.hpp" #include #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ using namespace boost::assign; /********************************************** Test classes **************************************/ enum { OTHER=2, VALUE = 4 }; // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( SetValueTest ); LookupValue LV; LookupSubset LS; void SetValueTest::setUp() { IndexSet set; set += 1,2,3,4; indices.reset(new IndexSet( set )); value.reset(new SetValue(indices, VALUE)); SetValue::lookupSubset = boost::bind(&LookupSubset::getSubsets, boost::ref(LS), _1); SetValue::lookupValue = boost::bind(&LookupValue::getValue, boost::ref(LV), _1); LV.LookupMap.insert( std::make_pair(indices, value) ); //IndexSet_ptr emptyset(new IndexSet); //LS.LookupMap.insert( std::make_pair(indices, IndexSetContainer::ptr( new IndexSetContainer(emptyset) )) ); }; void SetValueTest::tearDown() { }; /** UnitTest for constructor */ void SetValueTest::constructorTest() { CPPUNIT_ASSERT( value != NULL ); CPPUNIT_ASSERT_EQUAL( (int)VALUE, value->getValue() ); }; /** UnitTest for operator() */ void SetValueTest::operatorTest() { SetValue other(indices, OTHER); // operator-= other -= *value; CPPUNIT_ASSERT_EQUAL( (int)OTHER - (int)VALUE, other.getValue() ); CPPUNIT_ASSERT_EQUAL( (int)VALUE, value->getValue() ); // operator+= *value -= other; CPPUNIT_ASSERT_EQUAL( (int)OTHER - (int)VALUE, other.getValue() ); CPPUNIT_ASSERT_EQUAL( (int)VALUE - ((int)OTHER - (int)VALUE), value->getValue() ); }; void SetValueTest::getContributiontest() { IndexSet set; set += 1,2,3; IndexSet_ptr otherindices(new IndexSet(set)); SetValue::ptr othervalue(new SetValue(otherindices, OTHER)); LV.LookupMap.insert( std::make_pair(otherindices, othervalue) ); // connect as subset LS.LookupMap[indices].reset(new IndexSetContainer(otherindices)); std::cout << "The following error is intended and does not constitute a failure of the test." << std::endl; CPPUNIT_ASSERT_EQUAL( (int)OTHER, othervalue->getContribution() ); CPPUNIT_ASSERT_EQUAL( 2, value->getContribution() ); LS.LookupMap.erase( indices ); }