/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-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 .
*/
/*
* RandomNumberEngineFactoryUnitTest.cpp
*
* Created on: Jan 03, 2011
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include "CodePatterns/Assert.hpp"
#include "RandomNumberEngineFactoryUnitTest.hpp"
#include "RandomNumbers/RandomNumberEngine.hpp"
#include "RandomNumbers/RandomNumberEngine_Encapsulation.hpp"
#include "RandomNumbers/RandomNumberEngineFactory.hpp"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( RandomNumberEngineFactoryTest );
void RandomNumberEngineFactoryTest::setUp()
{
rndA = NULL;
rndA_1 = NULL;
rndA_2 = NULL;
rndA_3 = NULL;
RandomNumberEngineFactory::getInstance();
}
void RandomNumberEngineFactoryTest::tearDown()
{
delete rndA;
delete rndA_1;
delete rndA_2;
delete rndA_3;
RandomNumberEngineFactory::purgeInstance();
}
void RandomNumberEngineFactoryTest::EngineTest()
{
// check the injectiveness of enum and string map
for (RandomNumberEngineFactory::NameMap::const_iterator
iter = RandomNumberEngineFactory::getInstance().names.begin();
iter != RandomNumberEngineFactory::getInstance().names.end();
++iter) {
CPPUNIT_ASSERT_EQUAL(
iter->second,
RandomNumberEngineFactory::getInstance().getName(
RandomNumberEngineFactory::getInstance().getEnum(
iter->second
)
)
);
}
// check one of the engines in the table
rndA = RandomNumberEngineFactory::getInstance().
ManipulablePrototypeTable[RandomNumberEngineFactory::minstd_rand0]->clone();
CPPUNIT_ASSERT_EQUAL(
std::string(typeid(boost::minstd_rand0).name()),
rndA->name()
);
// range of minstd_rand0 with c=0 is [1,m)
CPPUNIT_ASSERT_EQUAL( 1., rndA->min() );
}
void RandomNumberEngineFactoryTest::PrototypeManipulationTest()
{
// make unmodified clone
rndA_1 = RandomNumberEngineFactory::getInstance().
getProduct(RandomNumberEngineFactory::minstd_rand0);
// obtain manipulator
RandomNumberEngine &prototype = RandomNumberEngineFactory::getInstance().
getPrototype(RandomNumberEngineFactory::minstd_rand0);
// change the prototype directly
CPPUNIT_ASSERT ( 2 != prototype.getseed() );
prototype.seed(2); // note for this prototype seed of 0 is not allowd by boost::random
// check that prototype has indeed been manipulated
rndA_2 = RandomNumberEngineFactory::getInstance().
getProduct(RandomNumberEngineFactory::minstd_rand0);
CPPUNIT_ASSERT_EQUAL( (unsigned int)2, rndA_2->getseed() );
CPPUNIT_ASSERT( rndA_2->getseed() != rndA_1->getseed());
// manipulate prototype
RandomNumberEngine_Parameters *params = rndA_1->getParameterSet();
CPPUNIT_ASSERT ( rndA_1->getseed() != (unsigned int)3 );
params->seed = 3;
RandomNumberEngineFactory::getInstance().
manipulatePrototype(RandomNumberEngineFactory::minstd_rand0, *params);
//
rndA_3 = RandomNumberEngineFactory::getInstance().
getProduct(RandomNumberEngineFactory::minstd_rand0);
CPPUNIT_ASSERT_EQUAL( (unsigned int)3, rndA_3->getseed() );
CPPUNIT_ASSERT( rndA_3->getseed() != rndA_1->getseed());
delete params;
}