source: src/Patterns/unittests/ManipulableCloneUnitTest.cpp@ fe056c

Last change on this file since fe056c was 8dd38e, checked in by Frederik Heber <heber@…>, 15 years ago

New patterns ManipulableClone and ManipulablePrototypeFactory, changed PrototypeFactory.

  • ManipulableClone is a Clone that can spawn a manipulated copy varied by given parameters.
  • prototypes in PrototypeFactory cannot be manipulated anymore.
  • PrototypeFactory::getPrototypeManipulator() -> getPrototype() and returned reference is const (and a ref, no pointer. Preventing its accidental deletion).
  • ManipulablePrototypeFactory then has non-const references returned by getProduct().
  • ManipulablePrototypeFactory::manipulatePrototype() allows direct manipulation of the prototype by a given parameter set.
  • Added unit tests for the new patterns.
  • Changed unit tests for PrototypeFactory.
  • Library version is now 4:0:0, API version is 1.0.7.
  • Property mode set to 100644
File size: 4.5 KB
Line 
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 * ManipulableCloneUnitTest.cpp
9 *
10 * Created on: Jan 06, 2011
11 * Author: heber
12 */
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "ManipulableCloneUnitTest.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 "ManipulableClone.hpp"
27#include "stubs/ManipulableCloneStub.hpp"
28#include "stubs/CommonParametersStub.hpp"
29
30#include <boost/nondet_random.hpp>
31#include <boost/random.hpp>
32#include <boost/random/additive_combine.hpp>
33#include <boost/random/discard_block.hpp>
34#include <boost/random/inversive_congruential.hpp>
35#include <boost/random/lagged_fibonacci.hpp>
36#include <boost/random/linear_congruential.hpp>
37#include <boost/random/linear_feedback_shift.hpp>
38#include <boost/random/mersenne_twister.hpp>
39#include <boost/random/random_number_generator.hpp>
40#include <boost/random/ranlux.hpp>
41#include <boost/random/shuffle_output.hpp>
42#include <boost/random/subtract_with_carry.hpp>
43#include <boost/random/xor_combine.hpp>
44#include <boost/random/bernoulli_distribution.hpp>
45#include <boost/random/binomial_distribution.hpp>
46#include <boost/random/cauchy_distribution.hpp>
47#include <boost/random/exponential_distribution.hpp>
48#include <boost/random/gamma_distribution.hpp>
49#include <boost/random/geometric_distribution.hpp>
50#include <boost/random/linear_congruential.hpp>
51#include <boost/random/lognormal_distribution.hpp>
52#include <boost/random/normal_distribution.hpp>
53#include <boost/random/poisson_distribution.hpp>
54#include <boost/random/triangle_distribution.hpp>
55#include <boost/random/uniform_01.hpp>
56#include <boost/random/uniform_int.hpp>
57#include <boost/random/uniform_on_sphere.hpp>
58#include <boost/random/uniform_real.hpp>
59#include <boost/random/uniform_smallint.hpp>
60
61#include <typeinfo>
62
63#ifdef HAVE_TESTRUNNER
64#include "UnitTestMain.hpp"
65#endif /*HAVE_TESTRUNNER*/
66
67/********************************************** Test classes **************************************/
68
69// Registers the fixture into the 'registry'
70CPPUNIT_TEST_SUITE_REGISTRATION( ManipulableCloneTest );
71
72
73void ManipulableCloneTest::setUp()
74{
75 ip1 = &p1;
76 CPPUNIT_ASSERT( ip1 == &p1 );
77 ip2 = &p2;
78 CPPUNIT_ASSERT( ip2 == &p2 );
79
80 ip1_1 = NULL;
81 ip1_2 = NULL;
82 ip2_1 = NULL;
83 ip2_2 = NULL;
84}
85
86void ManipulableCloneTest::tearDown()
87{
88 // NULL pointer may be deleted.
89 delete ip1_1;
90 delete ip1_2;
91 delete ip2_1;
92 delete ip2_2;
93}
94
95void ManipulableCloneTest::CreationTest()
96{
97 // test that new instances have been created.
98 ip1_1 = p1.clone();
99 ip1_2 = p1.clone();
100 CPPUNIT_ASSERT( ip1 != ip1_1 );
101 CPPUNIT_ASSERT( ip1 != ip1_2 );
102
103 ip2_1 = p2.clone();
104 ip2_2 = p2.clone();
105 CPPUNIT_ASSERT( ip2 != ip2_1 );
106 CPPUNIT_ASSERT( ip2 != ip2_2 );
107}
108
109void ManipulableCloneTest::IndividualityTest()
110{
111 CPPUNIT_ASSERT( typeid(p1).name() != typeid(p2).name() );
112 p1.count();
113 p2.count();
114 p2.count();
115
116 // make refs to interface
117 ip1 = &p1;
118 CPPUNIT_ASSERT( ip1 == &p1 );
119 ip2 = &p2;
120 CPPUNIT_ASSERT( ip2 == &p2 );
121
122 // clone (i.e. counter = p?.counter ), ...
123 ip1_1 = p1.clone();
124 ip1_2 = p1.clone();
125 ip2_1 = p2.clone();
126 ip2_2 = p2.clone();
127
128 // check that each is individual
129 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_1->getcount() );
130 CPPUNIT_ASSERT_EQUAL( ip1->getcount(), ip1_2->getcount() );
131 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_1->getcount() );
132 CPPUNIT_ASSERT_EQUAL( ip2->getcount(), ip2_2->getcount() );
133
134 // increase individual counters and check against others
135 ip1_1->count();
136 CPPUNIT_ASSERT( ip1->getcount() != ip1_1->getcount() );
137 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
138 CPPUNIT_ASSERT( ip1->getcount() == ip1_2->getcount() );
139
140 ip1_2->count();
141 CPPUNIT_ASSERT( ip1_1->getcount() == ip1_2->getcount() );
142 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
143
144 ip1_2->count();
145 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
146 CPPUNIT_ASSERT( ip1->getcount() != ip1_2->getcount() );
147}
148
149void ManipulableCloneTest::ManipulationTest()
150{
151 ip1_1 = p1.clone();
152 CPPUNIT_ASSERT_EQUAL( 0, ip1_1->getcount() );
153 teststubs::classParameters params;
154 params.counter= 100;
155 ip1_2 = p1.manipulatedclone(params);
156 CPPUNIT_ASSERT_EQUAL( 100, ip1_2->getcount() );
157
158 ip2_1 = p2.clone();
159 CPPUNIT_ASSERT_EQUAL( 0, ip2_1->getcount() );
160
161 CPPUNIT_ASSERT( ip1_1->getcount() != ip1_2->getcount() );
162}
Note: See TracBrowser for help on using the repository browser.