| 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 | * PrototypeFactoryUnitTest.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 "PrototypeFactoryUnitTest.hpp" | 
|---|
| 23 |  | 
|---|
| 24 | #include "stubs/CommonStub.hpp" | 
|---|
| 25 | #include "stubs/PrototypeFactoryStub.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( PrototypeFactoryTest ); | 
|---|
| 68 |  | 
|---|
| 69 | void PrototypeFactoryTest::setUp() | 
|---|
| 70 | { | 
|---|
| 71 | rndA = | 
|---|
| 72 | PrototypeFactoryStub::getInstance(). | 
|---|
| 73 | PrototypeTable[PrototypeFactoryStub::Aclass]->clone(); | 
|---|
| 74 | CPPUNIT_ASSERT_EQUAL( 0,  rndA->getcount() ); | 
|---|
| 75 | rndB = | 
|---|
| 76 | PrototypeFactoryStub::getInstance(). | 
|---|
| 77 | PrototypeTable[PrototypeFactoryStub::Bclass]->clone(); | 
|---|
| 78 | CPPUNIT_ASSERT_EQUAL( 0,  rndB->getcount() ); | 
|---|
| 79 |  | 
|---|
| 80 | rndA_1 = NULL; | 
|---|
| 81 | rndA_2 = NULL; | 
|---|
| 82 | rndA_3 = NULL; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | void PrototypeFactoryTest::tearDown() | 
|---|
| 86 | { | 
|---|
| 87 | delete rndA; | 
|---|
| 88 | delete rndA_1; | 
|---|
| 89 | delete rndA_2; | 
|---|
| 90 | delete rndA_3; | 
|---|
| 91 | delete rndB; | 
|---|
| 92 | PrototypeFactoryStub::purgeInstance(); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | void PrototypeFactoryTest::DistributionTest() | 
|---|
| 96 | { | 
|---|
| 97 | // check the injectiveness of enum and string map | 
|---|
| 98 | for (PrototypeFactoryStub::NameMap::const_iterator | 
|---|
| 99 | iter = PrototypeFactoryStub::getInstance().names.begin(); | 
|---|
| 100 | iter != PrototypeFactoryStub::getInstance().names.end(); | 
|---|
| 101 | ++iter) { | 
|---|
| 102 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 103 | iter->second, | 
|---|
| 104 | PrototypeFactoryStub::getInstance().getName( | 
|---|
| 105 | PrototypeFactoryStub::getInstance().getEnum( | 
|---|
| 106 | iter->second | 
|---|
| 107 | ) | 
|---|
| 108 | ) | 
|---|
| 109 | ); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | // check distributions in the table | 
|---|
| 113 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 114 | std::string(typeid(Prototype<teststubs::Aclass>).name()), | 
|---|
| 115 | std::string(typeid(*rndA).name()) | 
|---|
| 116 | ); | 
|---|
| 117 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 118 | std::string(typeid(Prototype<teststubs::Bclass>).name()), | 
|---|
| 119 | std::string(typeid(*rndB).name()) | 
|---|
| 120 | ); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | void PrototypeFactoryTest::getProductEnumTest() | 
|---|
| 124 | { | 
|---|
| 125 | rndA_1 = | 
|---|
| 126 | PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); | 
|---|
| 127 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | void PrototypeFactoryTest::getProductNameTest() | 
|---|
| 131 | { | 
|---|
| 132 | rndA_1 = | 
|---|
| 133 | PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass")); | 
|---|
| 134 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | void PrototypeFactoryTest::getProductTypeTest() | 
|---|
| 138 | { | 
|---|
| 139 | rndA_1 = | 
|---|
| 140 | PrototypeFactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); | 
|---|
| 141 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | void PrototypeFactoryTest::Individualitytest() | 
|---|
| 145 | { | 
|---|
| 146 | // increasing this does not change the prototype | 
|---|
| 147 | rndA->count(); | 
|---|
| 148 |  | 
|---|
| 149 | rndA_1 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); | 
|---|
| 150 | CPPUNIT_ASSERT_EQUAL( 0,  rndA_1->getcount() ); | 
|---|
| 151 | CPPUNIT_ASSERT( rndA->getcount() != rndA_1->getcount() ); | 
|---|
| 152 | rndA_1->count(); | 
|---|
| 153 | CPPUNIT_ASSERT( rndA->getcount() == rndA_1->getcount() ); | 
|---|
| 154 |  | 
|---|
| 155 | rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); | 
|---|
| 156 | CPPUNIT_ASSERT_EQUAL( 0,  rndA_2->getcount() ); | 
|---|
| 157 | CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() ); | 
|---|
| 158 | rndA_2->count(); | 
|---|
| 159 | CPPUNIT_ASSERT( rndA->getcount() == rndA_2->getcount() ); | 
|---|
| 160 | CPPUNIT_ASSERT( rndA_1->getcount() == rndA_2->getcount() ); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | void PrototypeFactoryTest::getPrototypetest() | 
|---|
| 164 | { | 
|---|
| 165 | // this method is protected and only friends may access it. | 
|---|
| 166 | const IPrototype& rndA_1c = PrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass")); | 
|---|
| 167 |  | 
|---|
| 168 | // clone the type and check whether new default values holds | 
|---|
| 169 | rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); | 
|---|
| 170 | CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() ); | 
|---|
| 171 | rndA_2->count(); | 
|---|
| 172 | CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() ); | 
|---|
| 173 |  | 
|---|
| 174 | // the following is not possible | 
|---|
| 175 | //rndA_1c.count(); | 
|---|
| 176 |  | 
|---|
| 177 | rndA_3 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass); | 
|---|
| 178 | CPPUNIT_ASSERT_EQUAL( 0, rndA_3->getcount() ); | 
|---|
| 179 | CPPUNIT_ASSERT( rndA->getcount() == rndA_3->getcount() ); | 
|---|
| 180 | } | 
|---|