[c9bc2b7] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[c9bc2b7] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * RandomNumberEngineFactoryUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Jan 03, 2011
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include <cppunit/CompilerOutputter.h>
|
---|
| 36 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 37 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 38 |
|
---|
| 39 | #include "CodePatterns/Assert.hpp"
|
---|
| 40 |
|
---|
| 41 | #include "RandomNumberEngineFactoryUnitTest.hpp"
|
---|
| 42 |
|
---|
[9b3476] | 43 | #include "RandomNumbers/RandomNumberEngine.hpp"
|
---|
[c9bc2b7] | 44 | #include "RandomNumbers/RandomNumberEngine_Encapsulation.hpp"
|
---|
| 45 | #include "RandomNumbers/RandomNumberEngineFactory.hpp"
|
---|
| 46 |
|
---|
| 47 | #include <boost/nondet_random.hpp>
|
---|
| 48 | #include <boost/random.hpp>
|
---|
| 49 | #include <boost/random/additive_combine.hpp>
|
---|
| 50 | #include <boost/random/discard_block.hpp>
|
---|
| 51 | #include <boost/random/inversive_congruential.hpp>
|
---|
| 52 | #include <boost/random/lagged_fibonacci.hpp>
|
---|
| 53 | #include <boost/random/linear_congruential.hpp>
|
---|
| 54 | #include <boost/random/linear_feedback_shift.hpp>
|
---|
| 55 | #include <boost/random/mersenne_twister.hpp>
|
---|
| 56 | #include <boost/random/random_number_generator.hpp>
|
---|
| 57 | #include <boost/random/ranlux.hpp>
|
---|
| 58 | #include <boost/random/shuffle_output.hpp>
|
---|
| 59 | #include <boost/random/subtract_with_carry.hpp>
|
---|
| 60 | #include <boost/random/xor_combine.hpp>
|
---|
| 61 | #include <boost/random/bernoulli_distribution.hpp>
|
---|
| 62 | #include <boost/random/binomial_distribution.hpp>
|
---|
| 63 | #include <boost/random/cauchy_distribution.hpp>
|
---|
| 64 | #include <boost/random/exponential_distribution.hpp>
|
---|
| 65 | #include <boost/random/gamma_distribution.hpp>
|
---|
| 66 | #include <boost/random/geometric_distribution.hpp>
|
---|
| 67 | #include <boost/random/linear_congruential.hpp>
|
---|
| 68 | #include <boost/random/lognormal_distribution.hpp>
|
---|
| 69 | #include <boost/random/normal_distribution.hpp>
|
---|
| 70 | #include <boost/random/poisson_distribution.hpp>
|
---|
| 71 | #include <boost/random/triangle_distribution.hpp>
|
---|
| 72 | #include <boost/random/uniform_01.hpp>
|
---|
| 73 | #include <boost/random/uniform_int.hpp>
|
---|
| 74 | #include <boost/random/uniform_on_sphere.hpp>
|
---|
| 75 | #include <boost/random/uniform_real.hpp>
|
---|
| 76 | #include <boost/random/uniform_smallint.hpp>
|
---|
| 77 |
|
---|
| 78 | #include <typeinfo>
|
---|
| 79 |
|
---|
| 80 | #ifdef HAVE_TESTRUNNER
|
---|
| 81 | #include "UnitTestMain.hpp"
|
---|
| 82 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 83 |
|
---|
| 84 | /********************************************** Test classes **************************************/
|
---|
| 85 |
|
---|
| 86 | // Registers the fixture into the 'registry'
|
---|
| 87 | CPPUNIT_TEST_SUITE_REGISTRATION( RandomNumberEngineFactoryTest );
|
---|
| 88 |
|
---|
| 89 | void RandomNumberEngineFactoryTest::setUp()
|
---|
| 90 | {
|
---|
[9b3476] | 91 | rndA = NULL;
|
---|
| 92 | rndA_1 = NULL;
|
---|
| 93 | rndA_2 = NULL;
|
---|
[0275ad] | 94 | rndA_3 = NULL;
|
---|
[c9bc2b7] | 95 | RandomNumberEngineFactory::getInstance();
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void RandomNumberEngineFactoryTest::tearDown()
|
---|
| 99 | {
|
---|
[9b3476] | 100 | delete rndA;
|
---|
| 101 | delete rndA_1;
|
---|
| 102 | delete rndA_2;
|
---|
[0275ad] | 103 | delete rndA_3;
|
---|
[c9bc2b7] | 104 | RandomNumberEngineFactory::purgeInstance();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | void RandomNumberEngineFactoryTest::EngineTest()
|
---|
| 108 | {
|
---|
| 109 | // check the injectiveness of enum and string map
|
---|
[1d5a871] | 110 | for (RandomNumberEngineFactory::NameMap::const_iterator
|
---|
| 111 | iter = RandomNumberEngineFactory::getInstance().names.begin();
|
---|
| 112 | iter != RandomNumberEngineFactory::getInstance().names.end();
|
---|
[c9bc2b7] | 113 | ++iter) {
|
---|
| 114 | CPPUNIT_ASSERT_EQUAL(
|
---|
| 115 | iter->second,
|
---|
| 116 | RandomNumberEngineFactory::getInstance().getName(
|
---|
| 117 | RandomNumberEngineFactory::getInstance().getEnum(
|
---|
| 118 | iter->second
|
---|
| 119 | )
|
---|
| 120 | )
|
---|
| 121 | );
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | // check one of the engines in the table
|
---|
[9b3476] | 125 | rndA = RandomNumberEngineFactory::getInstance().
|
---|
[0275ad] | 126 | ManipulablePrototypeTable[RandomNumberEngineFactory::minstd_rand0]->clone();
|
---|
[c9bc2b7] | 127 | CPPUNIT_ASSERT_EQUAL(
|
---|
| 128 | std::string(typeid(boost::minstd_rand0).name()),
|
---|
[9b3476] | 129 | rndA->name()
|
---|
[c9bc2b7] | 130 | );
|
---|
[081e5d] | 131 |
|
---|
| 132 | // range of minstd_rand0 with c=0 is [1,m)
|
---|
| 133 | CPPUNIT_ASSERT_EQUAL( 1., rndA->min() );
|
---|
[c9bc2b7] | 134 | }
|
---|
[9b3476] | 135 |
|
---|
[0275ad] | 136 | void RandomNumberEngineFactoryTest::PrototypeManipulationTest()
|
---|
| 137 | {
|
---|
| 138 | // make unmodified clone
|
---|
| 139 | rndA_1 = RandomNumberEngineFactory::getInstance().
|
---|
| 140 | getProduct(RandomNumberEngineFactory::minstd_rand0);
|
---|
| 141 |
|
---|
| 142 | // obtain manipulator
|
---|
| 143 | RandomNumberEngine &prototype = RandomNumberEngineFactory::getInstance().
|
---|
| 144 | getPrototype(RandomNumberEngineFactory::minstd_rand0);
|
---|
| 145 |
|
---|
| 146 | // change the prototype directly
|
---|
[c14c78] | 147 | CPPUNIT_ASSERT ( 2 != prototype.getseed() );
|
---|
| 148 | prototype.seed(2); // note for this prototype seed of 0 is not allowd by boost::random
|
---|
[0275ad] | 149 |
|
---|
| 150 | // check that prototype has indeed been manipulated
|
---|
| 151 | rndA_2 = RandomNumberEngineFactory::getInstance().
|
---|
| 152 | getProduct(RandomNumberEngineFactory::minstd_rand0);
|
---|
[c14c78] | 153 | CPPUNIT_ASSERT_EQUAL( (unsigned int)2, rndA_2->getseed() );
|
---|
[0275ad] | 154 | CPPUNIT_ASSERT( rndA_2->getseed() != rndA_1->getseed());
|
---|
| 155 |
|
---|
| 156 | // manipulate prototype
|
---|
| 157 | RandomNumberEngine_Parameters *params = rndA_1->getParameterSet();
|
---|
| 158 | CPPUNIT_ASSERT ( rndA_1->getseed() != (unsigned int)3 );
|
---|
| 159 | params->seed = 3;
|
---|
| 160 | RandomNumberEngineFactory::getInstance().
|
---|
| 161 | manipulatePrototype(RandomNumberEngineFactory::minstd_rand0, *params);
|
---|
| 162 |
|
---|
| 163 | //
|
---|
| 164 | rndA_3 = RandomNumberEngineFactory::getInstance().
|
---|
| 165 | getProduct(RandomNumberEngineFactory::minstd_rand0);
|
---|
| 166 | CPPUNIT_ASSERT_EQUAL( (unsigned int)3, rndA_3->getseed() );
|
---|
| 167 | CPPUNIT_ASSERT( rndA_3->getseed() != rndA_1->getseed());
|
---|
| 168 |
|
---|
| 169 | delete params;
|
---|
| 170 | }
|
---|
| 171 |
|
---|