| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 | /*
|
|---|
| 8 | * FactoryUnitTest.cpp
|
|---|
| 9 | *
|
|---|
| 10 | * Created on: Jan 03, 2011
|
|---|
| 11 | * Author: heber
|
|---|
| 12 | */
|
|---|
| 13 | // include config.h
|
|---|
| 14 | #ifdef HAVE_CONFIG_H
|
|---|
| 15 | #include <config.h>
|
|---|
| 16 | #endif
|
|---|
| 17 | #include <cppunit/CompilerOutputter.h>
|
|---|
| 18 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
|---|
| 19 | #include <cppunit/ui/text/TestRunner.h>
|
|---|
| 20 | #include "Assert.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include "FactoryUnitTest.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include "stubs/CommonStub.hpp"
|
|---|
| 25 | #include "stubs/FactoryStub.hpp"
|
|---|
| 26 |
|
|---|
| 27 | #include <boost/nondet_random.hpp>
|
|---|
| 28 | #include <boost/random.hpp>
|
|---|
| 29 | #include <boost/random/additive_combine.hpp>
|
|---|
| 30 | #include <boost/random/discard_block.hpp>
|
|---|
| 31 | #include <boost/random/inversive_congruential.hpp>
|
|---|
| 32 | #include <boost/random/lagged_fibonacci.hpp>
|
|---|
| 33 | #include <boost/random/linear_congruential.hpp>
|
|---|
| 34 | #include <boost/random/linear_feedback_shift.hpp>
|
|---|
| 35 | #include <boost/random/mersenne_twister.hpp>
|
|---|
| 36 | #include <boost/random/random_number_generator.hpp>
|
|---|
| 37 | #include <boost/random/ranlux.hpp>
|
|---|
| 38 | #include <boost/random/shuffle_output.hpp>
|
|---|
| 39 | #include <boost/random/subtract_with_carry.hpp>
|
|---|
| 40 | #include <boost/random/xor_combine.hpp>
|
|---|
| 41 | #include <boost/random/bernoulli_distribution.hpp>
|
|---|
| 42 | #include <boost/random/binomial_distribution.hpp>
|
|---|
| 43 | #include <boost/random/cauchy_distribution.hpp>
|
|---|
| 44 | #include <boost/random/exponential_distribution.hpp>
|
|---|
| 45 | #include <boost/random/gamma_distribution.hpp>
|
|---|
| 46 | #include <boost/random/geometric_distribution.hpp>
|
|---|
| 47 | #include <boost/random/linear_congruential.hpp>
|
|---|
| 48 | #include <boost/random/lognormal_distribution.hpp>
|
|---|
| 49 | #include <boost/random/normal_distribution.hpp>
|
|---|
| 50 | #include <boost/random/poisson_distribution.hpp>
|
|---|
| 51 | #include <boost/random/triangle_distribution.hpp>
|
|---|
| 52 | #include <boost/random/uniform_01.hpp>
|
|---|
| 53 | #include <boost/random/uniform_int.hpp>
|
|---|
| 54 | #include <boost/random/uniform_on_sphere.hpp>
|
|---|
| 55 | #include <boost/random/uniform_real.hpp>
|
|---|
| 56 | #include <boost/random/uniform_smallint.hpp>
|
|---|
| 57 |
|
|---|
| 58 | #include <typeinfo>
|
|---|
| 59 |
|
|---|
| 60 | #ifdef HAVE_TESTRUNNER
|
|---|
| 61 | #include "UnitTestMain.hpp"
|
|---|
| 62 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 63 |
|
|---|
| 64 | /********************************************** Test classes **************************************/
|
|---|
| 65 |
|
|---|
| 66 | // Registers the fixture into the 'registry'
|
|---|
| 67 | CPPUNIT_TEST_SUITE_REGISTRATION( FactoryTest );
|
|---|
| 68 |
|
|---|
| 69 | void FactoryTest::setUp()
|
|---|
| 70 | {
|
|---|
| 71 | rndA =
|
|---|
| 72 | FactoryStub::getInstance().
|
|---|
| 73 | PrototypeTable[FactoryStub::Aclass]->create();
|
|---|
| 74 | rndB =
|
|---|
| 75 | FactoryStub::getInstance().
|
|---|
| 76 | PrototypeTable[FactoryStub::Bclass]->create();
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void FactoryTest::tearDown()
|
|---|
| 80 | {
|
|---|
| 81 | delete rndA;
|
|---|
| 82 | delete rndB;
|
|---|
| 83 | FactoryStub::purgeInstance();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void FactoryTest::DistributionTest()
|
|---|
| 87 | {
|
|---|
| 88 | // check the injectiveness of enum and string map
|
|---|
| 89 | for (FactoryStub::NameMap::const_iterator
|
|---|
| 90 | iter = FactoryStub::getInstance().names.begin();
|
|---|
| 91 | iter != FactoryStub::getInstance().names.end();
|
|---|
| 92 | ++iter) {
|
|---|
| 93 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 94 | iter->second,
|
|---|
| 95 | FactoryStub::getInstance().getName(
|
|---|
| 96 | FactoryStub::getInstance().getEnum(
|
|---|
| 97 | iter->second
|
|---|
| 98 | )
|
|---|
| 99 | )
|
|---|
| 100 | );
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | // check distributions in the table
|
|---|
| 104 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 105 | std::string(typeid(teststubs::Aclass).name()),
|
|---|
| 106 | rndA->name()
|
|---|
| 107 | );
|
|---|
| 108 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 109 | std::string(typeid(teststubs::Bclass).name()),
|
|---|
| 110 | rndB->name()
|
|---|
| 111 | );
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | void FactoryTest::getProductEnumTest()
|
|---|
| 116 | {
|
|---|
| 117 | ICreatorStub * rndA_1 =
|
|---|
| 118 | FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
|
|---|
| 119 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 120 | delete rndA_1;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | void FactoryTest::getProductNameTest()
|
|---|
| 124 | {
|
|---|
| 125 | ICreatorStub * rndA_1 =
|
|---|
| 126 | FactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 127 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 128 | delete rndA_1;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void FactoryTest::getProductTypeTest()
|
|---|
| 132 | {
|
|---|
| 133 | ICreatorStub * rndA_1 =
|
|---|
| 134 | FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
|
|---|
| 135 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 136 | delete rndA_1;
|
|---|
| 137 | }
|
|---|