source: src/Patterns/unittests/CreatorUnitTest.cpp@ 8e24ef

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

FIX: some unittests declared variables anew although defined in header, NULL'd in setup, deleted in tearDown().

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