| 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 | * ManipulablePrototypeFactoryUnitTest.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 "ManipulablePrototypeFactoryUnitTest.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #include "stubs/CommonStub.hpp"
|
|---|
| 25 | #include "stubs/ManipulableCloneStub.hpp"
|
|---|
| 26 | #include "stubs/ManipulablePrototypeFactoryStub.hpp"
|
|---|
| 27 |
|
|---|
| 28 | #include <boost/nondet_random.hpp>
|
|---|
| 29 | #include <boost/random.hpp>
|
|---|
| 30 | #include <boost/random/additive_combine.hpp>
|
|---|
| 31 | #include <boost/random/discard_block.hpp>
|
|---|
| 32 | #include <boost/random/inversive_congruential.hpp>
|
|---|
| 33 | #include <boost/random/lagged_fibonacci.hpp>
|
|---|
| 34 | #include <boost/random/linear_congruential.hpp>
|
|---|
| 35 | #include <boost/random/linear_feedback_shift.hpp>
|
|---|
| 36 | #include <boost/random/mersenne_twister.hpp>
|
|---|
| 37 | #include <boost/random/random_number_generator.hpp>
|
|---|
| 38 | #include <boost/random/ranlux.hpp>
|
|---|
| 39 | #include <boost/random/shuffle_output.hpp>
|
|---|
| 40 | #include <boost/random/subtract_with_carry.hpp>
|
|---|
| 41 | #include <boost/random/xor_combine.hpp>
|
|---|
| 42 | #include <boost/random/bernoulli_distribution.hpp>
|
|---|
| 43 | #include <boost/random/binomial_distribution.hpp>
|
|---|
| 44 | #include <boost/random/cauchy_distribution.hpp>
|
|---|
| 45 | #include <boost/random/exponential_distribution.hpp>
|
|---|
| 46 | #include <boost/random/gamma_distribution.hpp>
|
|---|
| 47 | #include <boost/random/geometric_distribution.hpp>
|
|---|
| 48 | #include <boost/random/linear_congruential.hpp>
|
|---|
| 49 | #include <boost/random/lognormal_distribution.hpp>
|
|---|
| 50 | #include <boost/random/normal_distribution.hpp>
|
|---|
| 51 | #include <boost/random/poisson_distribution.hpp>
|
|---|
| 52 | #include <boost/random/triangle_distribution.hpp>
|
|---|
| 53 | #include <boost/random/uniform_01.hpp>
|
|---|
| 54 | #include <boost/random/uniform_int.hpp>
|
|---|
| 55 | #include <boost/random/uniform_on_sphere.hpp>
|
|---|
| 56 | #include <boost/random/uniform_real.hpp>
|
|---|
| 57 | #include <boost/random/uniform_smallint.hpp>
|
|---|
| 58 |
|
|---|
| 59 | #include <typeinfo>
|
|---|
| 60 |
|
|---|
| 61 | #ifdef HAVE_TESTRUNNER
|
|---|
| 62 | #include "UnitTestMain.hpp"
|
|---|
| 63 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 64 |
|
|---|
| 65 | /********************************************** Test classes **************************************/
|
|---|
| 66 |
|
|---|
| 67 | // Registers the fixture into the 'registry'
|
|---|
| 68 | CPPUNIT_TEST_SUITE_REGISTRATION( ManipulablePrototypeFactoryTest );
|
|---|
| 69 |
|
|---|
| 70 | void ManipulablePrototypeFactoryTest::setUp()
|
|---|
| 71 | {
|
|---|
| 72 | rndA =
|
|---|
| 73 | ManipulablePrototypeFactoryStub::getInstance().
|
|---|
| 74 | ManipulablePrototypeTable[ManipulablePrototypeFactoryStub::Aclass]->clone();
|
|---|
| 75 | CPPUNIT_ASSERT_EQUAL( 0, rndA->getcount() );
|
|---|
| 76 | rndB =
|
|---|
| 77 | ManipulablePrototypeFactoryStub::getInstance().
|
|---|
| 78 | ManipulablePrototypeTable[ManipulablePrototypeFactoryStub::Bclass]->clone();
|
|---|
| 79 | CPPUNIT_ASSERT_EQUAL( 0, rndB->getcount() );
|
|---|
| 80 |
|
|---|
| 81 | rndA_1 = NULL;
|
|---|
| 82 | rndA_2 = NULL;
|
|---|
| 83 | rndA_3 = NULL;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void ManipulablePrototypeFactoryTest::tearDown()
|
|---|
| 87 | {
|
|---|
| 88 | delete rndA;
|
|---|
| 89 | delete rndA_1;
|
|---|
| 90 | delete rndA_2;
|
|---|
| 91 | delete rndA_3;
|
|---|
| 92 | delete rndB;
|
|---|
| 93 | ManipulablePrototypeFactoryStub::purgeInstance();
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void ManipulablePrototypeFactoryTest::DistributionTest()
|
|---|
| 97 | {
|
|---|
| 98 | // check the injectiveness of enum and string map
|
|---|
| 99 | for (ManipulablePrototypeFactoryStub::NameMap::const_iterator
|
|---|
| 100 | iter = ManipulablePrototypeFactoryStub::getInstance().names.begin();
|
|---|
| 101 | iter != ManipulablePrototypeFactoryStub::getInstance().names.end();
|
|---|
| 102 | ++iter) {
|
|---|
| 103 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 104 | iter->second,
|
|---|
| 105 | ManipulablePrototypeFactoryStub::getInstance().getName(
|
|---|
| 106 | ManipulablePrototypeFactoryStub::getInstance().getEnum(
|
|---|
| 107 | iter->second
|
|---|
| 108 | )
|
|---|
| 109 | )
|
|---|
| 110 | );
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // check distributions in the table
|
|---|
| 114 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 115 | std::string(typeid(ManipulablePrototype<teststubs::Aclass>).name()),
|
|---|
| 116 | std::string(typeid(*rndA).name())
|
|---|
| 117 | );
|
|---|
| 118 | CPPUNIT_ASSERT_EQUAL(
|
|---|
| 119 | std::string(typeid(ManipulablePrototype<teststubs::Bclass>).name()),
|
|---|
| 120 | std::string(typeid(*rndB).name())
|
|---|
| 121 | );
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | void ManipulablePrototypeFactoryTest::getProductEnumTest()
|
|---|
| 125 | {
|
|---|
| 126 | rndA_1 =
|
|---|
| 127 | ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 128 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void ManipulablePrototypeFactoryTest::getProductNameTest()
|
|---|
| 132 | {
|
|---|
| 133 | rndA_1 =
|
|---|
| 134 | ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 135 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void ManipulablePrototypeFactoryTest::getProductTypeTest()
|
|---|
| 139 | {
|
|---|
| 140 | rndA_1 =
|
|---|
| 141 | ManipulablePrototypeFactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
|
|---|
| 142 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | void ManipulablePrototypeFactoryTest::Individualitytest()
|
|---|
| 146 | {
|
|---|
| 147 | // increasing this does not change the prototype
|
|---|
| 148 | rndA->count();
|
|---|
| 149 |
|
|---|
| 150 | rndA_1 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 151 | CPPUNIT_ASSERT_EQUAL( 0, rndA_1->getcount() );
|
|---|
| 152 | CPPUNIT_ASSERT( rndA->getcount() != rndA_1->getcount() );
|
|---|
| 153 | rndA_1->count();
|
|---|
| 154 | CPPUNIT_ASSERT( rndA->getcount() == rndA_1->getcount() );
|
|---|
| 155 |
|
|---|
| 156 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 157 | CPPUNIT_ASSERT_EQUAL( 0, rndA_2->getcount() );
|
|---|
| 158 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
|
|---|
| 159 | rndA_2->count();
|
|---|
| 160 | CPPUNIT_ASSERT( rndA->getcount() == rndA_2->getcount() );
|
|---|
| 161 | CPPUNIT_ASSERT( rndA_1->getcount() == rndA_2->getcount() );
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | void ManipulablePrototypeFactoryTest::getPrototypetest()
|
|---|
| 165 | {
|
|---|
| 166 | // this method is protected and only friends may access it.
|
|---|
| 167 | IManipulablePrototype &rndA_1c = ManipulablePrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass"));
|
|---|
| 168 | CPPUNIT_ASSERT_EQUAL( 0, rndA_1c.getcount() );
|
|---|
| 169 |
|
|---|
| 170 | // clone the type and check whether new default values holds
|
|---|
| 171 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 172 | CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() );
|
|---|
| 173 | rndA_2->count();
|
|---|
| 174 | CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() );
|
|---|
| 175 |
|
|---|
| 176 | // the following is possible (with PrototypeFactory not!)
|
|---|
| 177 | rndA_1c.count();
|
|---|
| 178 | CPPUNIT_ASSERT_EQUAL( 1, rndA_1c.getcount() );
|
|---|
| 179 |
|
|---|
| 180 | // rndA has been cloned before we have manipulated the prototype
|
|---|
| 181 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
|
|---|
| 182 |
|
|---|
| 183 | // prototype is at 1, has been manipulated!
|
|---|
| 184 | rndA_3 = ManipulablePrototypeFactoryStub::getInstance().getProduct(ManipulablePrototypeFactoryStub::Aclass);
|
|---|
| 185 | CPPUNIT_ASSERT_EQUAL( 1, rndA_3->getcount() );
|
|---|
| 186 |
|
|---|
| 187 | // rndA is older, before manipulation, hence still at 0
|
|---|
| 188 | CPPUNIT_ASSERT( rndA->getcount() != rndA_3->getcount() );
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | void ManipulablePrototypeFactoryTest::manipulatePrototypetest()
|
|---|
| 192 | {
|
|---|
| 193 | teststubs::classParameters params;
|
|---|
| 194 | params.counter = 100;
|
|---|
| 195 | ManipulablePrototypeFactoryStub::getInstance().manipulatePrototype(std::string("Aclass"), params);
|
|---|
| 196 |
|
|---|
| 197 | rndA_1 = ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 198 | CPPUNIT_ASSERT( 100 == rndA_1->getcount() );
|
|---|
| 199 |
|
|---|
| 200 | rndA_1->count();
|
|---|
| 201 | CPPUNIT_ASSERT( 101 == rndA_1->getcount() );
|
|---|
| 202 |
|
|---|
| 203 | rndA_2 = ManipulablePrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
|
|---|
| 204 | CPPUNIT_ASSERT( 100 == rndA_2->getcount() );
|
|---|
| 205 | CPPUNIT_ASSERT( rndA_1->getcount() != rndA_2->getcount() );
|
|---|
| 206 | }
|
|---|