source: src/Patterns/unittests/FactoryUnitTest.cpp@ 746ff1

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

Added Creator and Factory pattern.

  • unittests added.
  • new subfolder stubs that contains stubs for Creator and Factory.
  • the only preprocessor stuff is in Factory_impl.hpp.
  • FactoryTypeList.hpp is necessary as long as no variadic template argument lists are possible.
  • library version is 2:0:0, API version is 1.0.2.
  • Property mode set to 100644
File size: 3.1 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 * 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/FactoryStub.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( FactoryTest );
67
68void FactoryTest::setUp()
69{
70 FactoryStub::getInstance();
71}
72
73void FactoryTest::tearDown()
74{
75 FactoryStub::purgeInstance();
76}
77
78void FactoryTest::DistributionTest()
79{
80 // check the injectiveness of enum and string map
81 for (FactoryStub::NameMap::const_iterator
82 iter = FactoryStub::getInstance().names.begin();
83 iter != FactoryStub::getInstance().names.end();
84 ++iter) {
85 CPPUNIT_ASSERT_EQUAL(
86 iter->second,
87 FactoryStub::getInstance().getName(
88 FactoryStub::getInstance().getEnum(
89 iter->second
90 )
91 )
92 );
93 }
94
95 // check one of the distributions in the table
96 ICreatorStub * rnd =
97 FactoryStub::getInstance().
98 PrototypeTable[FactoryStub::Aclass]->create();
99 CPPUNIT_ASSERT_EQUAL(
100 std::string(typeid(teststubs::Aclass).name()),
101 rnd->name()
102 );
103 delete rnd;
104}
Note: See TracBrowser for help on using the repository browser.