| [c9bc2b7] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [d103d3] | 4 | * Copyright (C)  2010-2011 University of Bonn. All rights reserved. | 
|---|
| [c9bc2b7] | 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 | 
|---|
| [63839f] | 52 | * from the RandomNumberGeneratorFactory is truely the prototype | 
|---|
|  | 53 | * itself. | 
|---|
| [c9bc2b7] | 54 | */ | 
|---|
| [63839f] | 55 | void RandomNumberGeneratorTest::PrototypeNonCopyTest() | 
|---|
| [c9bc2b7] | 56 | { | 
|---|
| [63839f] | 57 | RandomNumberGenerator &rng1 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator(); | 
|---|
|  | 58 | RandomNumberGenerator &rng2 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator(); | 
|---|
| [c9bc2b7] | 59 |  | 
|---|
| [63839f] | 60 | // compare addresses in memory, have to be the same | 
|---|
|  | 61 | CPPUNIT_ASSERT( &rng1 == &rng2 ); | 
|---|
| [c9bc2b7] | 62 | } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | void RandomNumberGeneratorTest::Range_uniform_smallint_Test() | 
|---|
|  | 65 | { | 
|---|
|  | 66 | // obtain some random values for uniform_smallint | 
|---|
|  | 67 | RandomNumberGeneratorFactory::getInstance().setDistribution("uniform_smallint"); | 
|---|
| [63839f] | 68 | RandomNumberGenerator& rng = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator(); | 
|---|
| [c9bc2b7] | 69 | for (size_t i=0; i < 1000; ++i) { | 
|---|
| [63839f] | 70 | const int testint = rng(); | 
|---|
| [c9bc2b7] | 71 | CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint >= 0); | 
|---|
|  | 72 | CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint <= 9); | 
|---|
|  | 73 | } | 
|---|
|  | 74 | } | 
|---|