/*
 * 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 .
 */
/*
 * RandomNumberDistributionFactoryUnitTest.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 "RandomNumberDistributionFactoryUnitTest.hpp"
#include "RandomNumbers/RandomNumberDistribution.hpp"
#include "RandomNumbers/RandomNumberDistribution_Encapsulation.hpp"
#include "RandomNumbers/RandomNumberDistributionFactory.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( RandomNumberDistributionFactoryTest );
void RandomNumberDistributionFactoryTest::setUp()
{
  rndA = NULL;
  rndA_1 = NULL;
  rndA_2 = NULL;
  rndA_3 = NULL;
  RandomNumberDistributionFactory::getInstance();
}
void RandomNumberDistributionFactoryTest::tearDown()
{
  delete rndA;
  delete rndA_1;
  delete rndA_2;
  delete rndA_3;
  RandomNumberDistributionFactory::purgeInstance();
}
void RandomNumberDistributionFactoryTest::DistributionTest()
{
  // check the injectiveness of enum and string map
  for (RandomNumberDistributionFactory::NameMap::const_iterator
      iter = RandomNumberDistributionFactory::getInstance().names.begin();
      iter != RandomNumberDistributionFactory::getInstance().names.end();
      ++iter) {
    CPPUNIT_ASSERT_EQUAL(
        iter->second,
        RandomNumberDistributionFactory::getInstance().getName(
            RandomNumberDistributionFactory::getInstance().getEnum(
                iter->second
            )
        )
    );
  }
  // check one of the distributions in the table
  rndA = RandomNumberDistributionFactory::getInstance().
      ManipulablePrototypeTable[RandomNumberDistributionFactory::uniform_smallint]->clone();
  CPPUNIT_ASSERT_EQUAL(
      std::string(typeid(boost::uniform_smallint<> ).name()),
      rndA->name()
  );
  // check min and max of uniform_smallint
  CPPUNIT_ASSERT_EQUAL( 0., rndA->min() );
  CPPUNIT_ASSERT_EQUAL( 9., rndA->max() );
}
void RandomNumberDistributionFactoryTest::PrototypeManipulationTest()
{
  // make unmodified clone
  rndA_1 = RandomNumberDistributionFactory::getInstance().
      getProduct(RandomNumberDistributionFactory::uniform_smallint);
  // do something with the prototype
  RandomNumberDistribution_Parameters *params =
      rndA_1->getParameterSet();
  CPPUNIT_ASSERT( 20. != rndA_1->max() );
  params->max = 20.;
  RandomNumberDistributionFactory::getInstance().
      manipulatePrototype(RandomNumberDistributionFactory::uniform_smallint, *params);
  // ... and check max
  rndA_2 = RandomNumberDistributionFactory::getInstance().
      getProduct(RandomNumberDistributionFactory::uniform_smallint);
  CPPUNIT_ASSERT_EQUAL( 20., rndA_2->max());
  CPPUNIT_ASSERT( rndA_1->max() != rndA_2->max());
  // ... and check min (remains the same)
  CPPUNIT_ASSERT( rndA_1->min() == rndA_2->min());
  // do something with the prototype again
  params->max = 25.;
  RandomNumberDistributionFactory::getInstance().
      manipulatePrototype(std::string("uniform_smallint"), *params);
  // ... and check
  rndA_3 = RandomNumberDistributionFactory::getInstance().
      getProduct(RandomNumberDistributionFactory::uniform_smallint);
  CPPUNIT_ASSERT_EQUAL( 25., rndA_3->max());
  CPPUNIT_ASSERT( rndA_1->max() != rndA_3->max());
  CPPUNIT_ASSERT( rndA_2->max() != rndA_3->max());
  delete params;
}