| 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 | * CloneUnitTest.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 "CloneUnitTest.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 "Clone.hpp" | 
|---|
| 27 | #include "stubs/CloneStub.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( CloneTest ); | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 | void CloneTest::setUp() | 
|---|
| 73 | { | 
|---|
| 74 | ip1 = &p1; | 
|---|
| 75 | CPPUNIT_ASSERT( ip1 == &p1 ); | 
|---|
| 76 | ip2 = &p2; | 
|---|
| 77 | CPPUNIT_ASSERT( ip2 == &p2 ); | 
|---|
| 78 |  | 
|---|
| 79 | ip1_1 = NULL; | 
|---|
| 80 | ip1_2 = NULL; | 
|---|
| 81 | ip2_1 = NULL; | 
|---|
| 82 | ip2_2 = NULL; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | void CloneTest::tearDown() | 
|---|
| 86 | { | 
|---|
| 87 | // NULL pointer may be deleted. | 
|---|
| 88 | delete ip1_1; | 
|---|
| 89 | delete ip1_2; | 
|---|
| 90 | delete ip2_1; | 
|---|
| 91 | delete ip2_2; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | void CloneTest::CreationTest() | 
|---|
| 95 | { | 
|---|
| 96 | // test that new instances have been created. | 
|---|
| 97 | ip1_1 = p1.clone(); | 
|---|
| 98 | ip1_2 = p1.clone(); | 
|---|
| 99 | CPPUNIT_ASSERT( ip1 != ip1_1 ); | 
|---|
| 100 | CPPUNIT_ASSERT( ip1 != ip1_2 ); | 
|---|
| 101 |  | 
|---|
| 102 | ip2_1 = p2.clone(); | 
|---|
| 103 | ip2_2 = p2.clone(); | 
|---|
| 104 | CPPUNIT_ASSERT( ip2 != ip2_1 ); | 
|---|
| 105 | CPPUNIT_ASSERT( ip2 != ip2_2 ); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | void CloneTest::IndividualityTest() | 
|---|
| 109 | { | 
|---|
| 110 | CPPUNIT_ASSERT( typeid(p1).name() != typeid(p2).name() ); | 
|---|
| 111 | p1.count(); | 
|---|
| 112 | p2.count(); | 
|---|
| 113 | p2.count(); | 
|---|
| 114 |  | 
|---|
| 115 | // make refs to interface | 
|---|
| 116 | ip1 = &p1; | 
|---|
| 117 | CPPUNIT_ASSERT( ip1 == &p1 ); | 
|---|
| 118 | ip2 = &p2; | 
|---|
| 119 | CPPUNIT_ASSERT( ip2 == &p2 ); | 
|---|
| 120 |  | 
|---|
| 121 | // clone (i.e. counter = p?.counter ), ... | 
|---|
| 122 | ip1_1 = p1.clone(); | 
|---|
| 123 | ip1_2 = p1.clone(); | 
|---|
| 124 | ip2_1 = p2.clone(); | 
|---|
| 125 | ip2_2 = p2.clone(); | 
|---|
| 126 |  | 
|---|
| 127 | // check that each is individual | 
|---|
| 128 | CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_1->getcount() ); | 
|---|
| 129 | CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_2->getcount() ); | 
|---|
| 130 | CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_1->getcount() ); | 
|---|
| 131 | CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_2->getcount() ); | 
|---|
| 132 |  | 
|---|
| 133 | // increase individual counters and check against others | 
|---|
| 134 | ip1_1->count(); | 
|---|
| 135 | CPPUNIT_ASSERT( ip1->getcount() != ip1_1->getcount() ); | 
|---|
| 136 | CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() ); | 
|---|
| 137 | CPPUNIT_ASSERT( ip1->getcount() == ip1_2->getcount() ); | 
|---|
| 138 |  | 
|---|
| 139 | ip1_2->count(); | 
|---|
| 140 | CPPUNIT_ASSERT( ip1_1->getcount() == ip1_2->getcount() ); | 
|---|
| 141 | CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() ); | 
|---|
| 142 |  | 
|---|
| 143 | ip1_2->count(); | 
|---|
| 144 | CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() ); | 
|---|
| 145 | CPPUNIT_ASSERT( ip1->getcount()   != ip1_2->getcount() ); | 
|---|
| 146 | } | 
|---|