/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * RandomNumberGeneratorFactoryUnitTest.cpp * * Created on: Dec 31, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "CodePatterns/Assert.hpp" #include "RandomNumberGeneratorFactoryUnitTest.hpp" #include "RandomNumbers/RandomNumberDistribution_Encapsulation.hpp" #include "RandomNumbers/RandomNumberEngine_Encapsulation.hpp" #include "RandomNumbers/RandomNumberGenerator_Encapsulation.hpp" #include "RandomNumbers/RandomNumberGeneratorFactory.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( RandomNumberGeneratorFactoryTest ); void RandomNumberGeneratorFactoryTest::setUp() { RandomNumberGeneratorFactory::getInstance(); } void RandomNumberGeneratorFactoryTest::tearDown() { RandomNumberGeneratorFactory::purgeInstance(); } void RandomNumberGeneratorFactoryTest::EngineTest() { // check default value CPPUNIT_ASSERT_EQUAL( std::string("minstd_rand0"), RandomNumberGeneratorFactory::getInstance().getEngine()); // check one of the engines in the table CPPUNIT_ASSERT_EQUAL( std::string(typeid(boost::minstd_rand0).name()), RandomNumberGeneratorFactory::getInstance(). EnginePrototypeTable[RandomNumberGeneratorFactory::minstd_rand0]->name() ); } void RandomNumberGeneratorFactoryTest::DistributionTest() { // check default value CPPUNIT_ASSERT_EQUAL( std::string("uniform_smallint"), RandomNumberGeneratorFactory::getInstance().getDistribution()); // check one of the distributions in the table CPPUNIT_ASSERT_EQUAL( std::string(typeid(boost::uniform_smallint<> ).name()), RandomNumberGeneratorFactory::getInstance(). DistributionPrototypeTable[RandomNumberGeneratorFactory::uniform_smallint]->name() ); } void RandomNumberGeneratorFactoryTest::GeneratorTest() { // check one of the engines and distributions CPPUNIT_ASSERT_EQUAL( std::string(typeid(boost::minstd_rand0).name()), RandomNumberGeneratorFactory::getInstance(). GeneratorPrototypeTable[RandomNumberGeneratorFactory::minstd_rand0][RandomNumberGeneratorFactory::uniform_smallint] ->EngineName() ); CPPUNIT_ASSERT_EQUAL( std::string(typeid(boost::uniform_smallint<> ).name()), RandomNumberGeneratorFactory::getInstance(). GeneratorPrototypeTable[RandomNumberGeneratorFactory::minstd_rand0][RandomNumberGeneratorFactory::uniform_smallint] ->DistributionName() ); // obtain some random values for uniform_smallint RandomNumberGeneratorFactory::getInstance().setDistribution("uniform_smallint"); RandomNumberGenerator &rng = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator(); for (size_t i=0; i < 1000; ++i) { const int testint = rng(); CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint >= 0); CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint <= 9); } }