| 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 | rndA_1 = NULL; | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | void FactoryTest::tearDown() | 
|---|
| 81 | { | 
|---|
| 82 | delete rndA; | 
|---|
| 83 | delete rndB; | 
|---|
| 84 | delete rndA_1; | 
|---|
| 85 | FactoryStub::purgeInstance(); | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | void FactoryTest::DistributionTest() | 
|---|
| 89 | { | 
|---|
| 90 | // check the injectiveness of enum and string map | 
|---|
| 91 | for (FactoryStub::NameMap::const_iterator | 
|---|
| 92 | iter = FactoryStub::getInstance().names.begin(); | 
|---|
| 93 | iter != FactoryStub::getInstance().names.end(); | 
|---|
| 94 | ++iter) { | 
|---|
| 95 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 96 | iter->second, | 
|---|
| 97 | FactoryStub::getInstance().getName( | 
|---|
| 98 | FactoryStub::getInstance().getEnum( | 
|---|
| 99 | iter->second | 
|---|
| 100 | ) | 
|---|
| 101 | ) | 
|---|
| 102 | ); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | // check distributions in the table | 
|---|
| 106 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 107 | std::string(typeid(teststubs::Aclass).name()), | 
|---|
| 108 | rndA->name() | 
|---|
| 109 | ); | 
|---|
| 110 | CPPUNIT_ASSERT_EQUAL( | 
|---|
| 111 | std::string(typeid(teststubs::Bclass).name()), | 
|---|
| 112 | rndB->name() | 
|---|
| 113 | ); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 |  | 
|---|
| 117 | void FactoryTest::getProductEnumTest() | 
|---|
| 118 | { | 
|---|
| 119 | rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass); | 
|---|
| 120 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | void FactoryTest::getProductNameTest() | 
|---|
| 124 | { | 
|---|
| 125 | rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass")); | 
|---|
| 126 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | void FactoryTest::getProductTypeTest() | 
|---|
| 130 | { | 
|---|
| 131 | rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); | 
|---|
| 132 | CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); | 
|---|
| 133 | } | 
|---|