| 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 | * CreatorUnitTest.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 |  | 
|---|
| 18 | #include "CreatorUnitTest.hpp" | 
|---|
| 19 |  | 
|---|
| 20 | #include <cppunit/CompilerOutputter.h> | 
|---|
| 21 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
| 22 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
| 23 |  | 
|---|
| 24 | #include "Assert.hpp" | 
|---|
| 25 |  | 
|---|
| 26 | #include "Creator.hpp" | 
|---|
| 27 | #include "stubs/CreatorStub.hpp" | 
|---|
| 28 |  | 
|---|
| 29 | #include <boost/nondet_random.hpp> | 
|---|
| 30 | #include <boost/random.hpp> | 
|---|
| 31 | #include <boost/random/additive_combine.hpp> | 
|---|
| 32 | #include <boost/random/discard_block.hpp> | 
|---|
| 33 | #include <boost/random/inversive_congruential.hpp> | 
|---|
| 34 | #include <boost/random/lagged_fibonacci.hpp> | 
|---|
| 35 | #include <boost/random/linear_congruential.hpp> | 
|---|
| 36 | #include <boost/random/linear_feedback_shift.hpp> | 
|---|
| 37 | #include <boost/random/mersenne_twister.hpp> | 
|---|
| 38 | #include <boost/random/random_number_generator.hpp> | 
|---|
| 39 | #include <boost/random/ranlux.hpp> | 
|---|
| 40 | #include <boost/random/shuffle_output.hpp> | 
|---|
| 41 | #include <boost/random/subtract_with_carry.hpp> | 
|---|
| 42 | #include <boost/random/xor_combine.hpp> | 
|---|
| 43 | #include <boost/random/bernoulli_distribution.hpp> | 
|---|
| 44 | #include <boost/random/binomial_distribution.hpp> | 
|---|
| 45 | #include <boost/random/cauchy_distribution.hpp> | 
|---|
| 46 | #include <boost/random/exponential_distribution.hpp> | 
|---|
| 47 | #include <boost/random/gamma_distribution.hpp> | 
|---|
| 48 | #include <boost/random/geometric_distribution.hpp> | 
|---|
| 49 | #include <boost/random/linear_congruential.hpp> | 
|---|
| 50 | #include <boost/random/lognormal_distribution.hpp> | 
|---|
| 51 | #include <boost/random/normal_distribution.hpp> | 
|---|
| 52 | #include <boost/random/poisson_distribution.hpp> | 
|---|
| 53 | #include <boost/random/triangle_distribution.hpp> | 
|---|
| 54 | #include <boost/random/uniform_01.hpp> | 
|---|
| 55 | #include <boost/random/uniform_int.hpp> | 
|---|
| 56 | #include <boost/random/uniform_on_sphere.hpp> | 
|---|
| 57 | #include <boost/random/uniform_real.hpp> | 
|---|
| 58 | #include <boost/random/uniform_smallint.hpp> | 
|---|
| 59 |  | 
|---|
| 60 | #include <typeinfo> | 
|---|
| 61 |  | 
|---|
| 62 | #ifdef HAVE_TESTRUNNER | 
|---|
| 63 | #include "UnitTestMain.hpp" | 
|---|
| 64 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 65 |  | 
|---|
| 66 | /********************************************** Test classes **************************************/ | 
|---|
| 67 |  | 
|---|
| 68 | // Registers the fixture into the 'registry' | 
|---|
| 69 | CPPUNIT_TEST_SUITE_REGISTRATION( CreatorTest ); | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 | void CreatorTest::setUp() | 
|---|
| 73 | { | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | void CreatorTest::tearDown() | 
|---|
| 77 | { | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | void CreatorTest::CreationTest() | 
|---|
| 81 | { | 
|---|
| 82 | class CreatorStub<teststubs::Aclass> teststubA; | 
|---|
| 83 | class CreatorStub<teststubs::Bclass> teststubB; | 
|---|
| 84 |  | 
|---|
| 85 | ICreatorStub* testingA1 = teststubA.create(); | 
|---|
| 86 | ICreatorStub* testingA2 = teststubA.create(); | 
|---|
| 87 | ICreatorStub* testingB = teststubB.create(); | 
|---|
| 88 |  | 
|---|
| 89 | // instance is different | 
|---|
| 90 | CPPUNIT_ASSERT( &teststubA != testingA1 ); | 
|---|
| 91 | CPPUNIT_ASSERT( &teststubA != testingA2 ); | 
|---|
| 92 | CPPUNIT_ASSERT( testingA1 != testingA2 ); | 
|---|
| 93 | CPPUNIT_ASSERT( &teststubB != testingB ); | 
|---|
| 94 |  | 
|---|
| 95 | // type is the same ... | 
|---|
| 96 | CPPUNIT_ASSERT_EQUAL( typeid(teststubA).name(), typeid(*testingA1).name() ); | 
|---|
| 97 | CPPUNIT_ASSERT_EQUAL( typeid(*testingA1).name(), typeid(*testingA2).name() ); | 
|---|
| 98 | CPPUNIT_ASSERT_EQUAL( typeid(teststubB).name(), typeid(*testingB).name() ); | 
|---|
| 99 |  | 
|---|
| 100 | // ... for the same particular type only! | 
|---|
| 101 | // (RTTI knows about the true complex type!) | 
|---|
| 102 | CPPUNIT_ASSERT( typeid(*testingB).name() != typeid(*testingA1).name() ); | 
|---|
| 103 | CPPUNIT_ASSERT( typeid(*testingB).name() != typeid(*testingA2).name() ); | 
|---|
| 104 |  | 
|---|
| 105 | // but not for different encapsulated types | 
|---|
| 106 | CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB).name() ); | 
|---|
| 107 | CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA1).name() ); | 
|---|
| 108 | CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA2).name() ); | 
|---|
| 109 |  | 
|---|
| 110 | delete testingA1; | 
|---|
| 111 | delete testingA2; | 
|---|
| 112 | delete testingB; | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | void CreatorTest::IndividualityTest() | 
|---|
| 116 | { | 
|---|
| 117 | class CreatorStub<teststubs::Aclass> teststubA; | 
|---|
| 118 | class CreatorStub<teststubs::Bclass> teststubB; | 
|---|
| 119 | teststubA.count(); | 
|---|
| 120 | teststubB.count(); | 
|---|
| 121 | teststubB.count(); | 
|---|
| 122 |  | 
|---|
| 123 | ICreatorStub* testingA1 = teststubA.create(); | 
|---|
| 124 | ICreatorStub* testingA2 = teststubA.create(); | 
|---|
| 125 | ICreatorStub* testingB1 = teststubB.create(); | 
|---|
| 126 | ICreatorStub* testingB2 = teststubB.create(); | 
|---|
| 127 |  | 
|---|
| 128 | // content is the same (prototype has been copied) | 
|---|
| 129 | CPPUNIT_ASSERT( teststubA.getcount() != testingA1->getcount()); | 
|---|
| 130 | CPPUNIT_ASSERT( teststubA.getcount() != testingA2->getcount()); | 
|---|
| 131 | CPPUNIT_ASSERT( teststubB.getcount() != testingB1->getcount()); | 
|---|
| 132 | CPPUNIT_ASSERT( teststubB.getcount() != testingB2->getcount()); | 
|---|
| 133 |  | 
|---|
| 134 | // but each copy is independent | 
|---|
| 135 | testingA1->count(); | 
|---|
| 136 | CPPUNIT_ASSERT( testingA1->getcount() != testingA2->getcount()); | 
|---|
| 137 | testingB1->count(); | 
|---|
| 138 | testingB2->count(); | 
|---|
| 139 | testingB2->count(); | 
|---|
| 140 | CPPUNIT_ASSERT( testingB1->getcount() != testingB2->getcount()); | 
|---|
| 141 |  | 
|---|
| 142 | delete testingA1; | 
|---|
| 143 | delete testingA2; | 
|---|
| 144 | delete testingB1; | 
|---|
| 145 | delete testingB2; | 
|---|
| 146 | } | 
|---|