/*
 * Project: MoleCuilder
 * Description: creates and alters molecular systems
 * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 * 
 *
 *   This file is part of MoleCuilder.
 *
 *    MoleCuilder is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MoleCuilder is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MoleCuilder.  If not, see .
 */
/*
 * RandomNumberGeneratorUnitTest.cpp
 *
 *  Created on: Jan 03, 2011
 *      Author: heber
 */
// include config.h
#ifdef HAVE_CONFIG_H
#include 
#endif
#include 
#include 
#include 
#include "CodePatterns/Assert.hpp"
#include "RandomNumberGeneratorUnitTest.hpp"
#include "RandomNumbers/RandomNumberGenerator.hpp"
#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( RandomNumberGeneratorTest );
void RandomNumberGeneratorTest::setUp()
{
}
void RandomNumberGeneratorTest::tearDown()
{
  RandomNumberDistributionFactory::purgeInstance();
  RandomNumberEngineFactory::purgeInstance();
  RandomNumberGeneratorFactory::purgeInstance();
}
/** We check that the RandomNumberGenerator instance received
 * from the RandomNumberGeneratorFactory is truely the prototype
 * itself.
 */
void RandomNumberGeneratorTest::PrototypeNonCopyTest()
{
  RandomNumberGenerator &rng1 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
  RandomNumberGenerator &rng2 = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
  // compare addresses in memory, have to be the same
  CPPUNIT_ASSERT( &rng1 == &rng2 );
}
void RandomNumberGeneratorTest::Range_uniform_smallint_Test()
{
  // 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);
  }
}