| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2011 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 the prototype
|
|---|
| 53 | * itself.
|
|---|
| 54 | */
|
|---|
| 55 | void RandomNumberGeneratorTest::PrototypeNonCopyTest()
|
|---|
| 56 | {
|
|---|
| 57 | RandomNumberGenerator &rng1 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
|
|---|
| 58 | RandomNumberGenerator &rng2 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
|
|---|
| 59 |
|
|---|
| 60 | // compare addresses in memory, have to be the same
|
|---|
| 61 | CPPUNIT_ASSERT( &rng1 == &rng2 );
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void RandomNumberGeneratorTest::Range_uniform_smallint_Test()
|
|---|
| 65 | {
|
|---|
| 66 | // obtain some random values for uniform_smallint
|
|---|
| 67 | RandomNumberGeneratorFactory::getInstance().setDistribution("uniform_smallint");
|
|---|
| 68 | RandomNumberGenerator& rng = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
|
|---|
| 69 | for (size_t i=0; i < 1000; ++i) {
|
|---|
| 70 | const int testint = rng();
|
|---|
| 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 | }
|
|---|