| [c9bc2b7] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | /*
 | 
|---|
 | 9 |  * RandomNumberGeneratorUnitTest.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Jan 03, 2011
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 22 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | #include "RandomNumberGeneratorUnitTest.hpp"
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | #include "RandomNumbers/RandomNumberGenerator.hpp"
 | 
|---|
 | 29 | #include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 32 | #include "UnitTestMain.hpp"
 | 
|---|
 | 33 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | /********************************************** Test classes **************************************/
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | // Registers the fixture into the 'registry'
 | 
|---|
 | 38 | CPPUNIT_TEST_SUITE_REGISTRATION( RandomNumberGeneratorTest );
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | void RandomNumberGeneratorTest::setUp()
 | 
|---|
 | 41 | {
 | 
|---|
 | 42 | }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 | void RandomNumberGeneratorTest::tearDown()
 | 
|---|
 | 45 | {
 | 
|---|
 | 46 |   RandomNumberDistributionFactory::purgeInstance();
 | 
|---|
 | 47 |   RandomNumberEngineFactory::purgeInstance();
 | 
|---|
 | 48 |   RandomNumberGeneratorFactory::purgeInstance();
 | 
|---|
 | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | /** We check that the RandomNumberGenerator instance received
 | 
|---|
 | 52 |  * from the RandomNumberGeneratorFactory is truely a copy and
 | 
|---|
 | 53 |  * not the prototype instance.
 | 
|---|
 | 54 |  */
 | 
|---|
 | 55 | void RandomNumberGeneratorTest::PrototypeCopyTest()
 | 
|---|
 | 56 | {
 | 
|---|
 | 57 |   RandomNumberGenerator *rng1 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
 | 
|---|
 | 58 |   RandomNumberGenerator *rng2 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 |   double random1_1 = (*rng1)();
 | 
|---|
 | 61 |   double random1_2 = (*rng1)();
 | 
|---|
 | 62 |   double random2_1 = (*rng2)();
 | 
|---|
 | 63 |   double random2_2 = (*rng2)();
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |   CPPUNIT_ASSERT(random1_1 == random2_1);
 | 
|---|
 | 66 |   CPPUNIT_ASSERT(random1_2 == random2_2);
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |   delete rng1;
 | 
|---|
 | 69 |   delete rng2;
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | void RandomNumberGeneratorTest::Range_uniform_smallint_Test()
 | 
|---|
 | 73 | {
 | 
|---|
 | 74 |   // obtain some random values for uniform_smallint
 | 
|---|
 | 75 |   RandomNumberGeneratorFactory::getInstance().setDistribution("uniform_smallint");
 | 
|---|
 | 76 |   RandomNumberGenerator* rng = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
 | 
|---|
 | 77 |   for (size_t i=0; i < 1000; ++i) {
 | 
|---|
 | 78 |     const int testint = (*rng)();
 | 
|---|
 | 79 |     CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint >= 0);
 | 
|---|
 | 80 |     CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint <= 9);
 | 
|---|
 | 81 |   }
 | 
|---|
 | 82 |   delete rng;
 | 
|---|
 | 83 | }
 | 
|---|