source: ThirdParty/CodePatterns/src/Patterns/unittests/CacheableUnitTest.cpp@ a844d8

Candidate_v1.6.1
Last change on this file since a844d8 was 41e8e2, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '084729c5923f0123e695fbe2548b393288c1f13d' as 'ThirdParty/CodePatterns'

  • Property mode set to 100644
File size: 2.6 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/*
9 * CacheableUnitTest.cpp
10 *
11 * Created on: Feb 2, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CacheableUnitTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <boost/bind.hpp>
27
28#include "CodePatterns/Cacheable.hpp"
29
30#include "stubs/Cacheable_threeNumbers.hpp"
31
32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36/********************************************** Test classes **************************************/
37
38// Registers the fixture into the 'registry'
39CPPUNIT_TEST_SUITE_REGISTRATION( CacheableTest );
40
41void CacheableTest::setUp(){
42 numbers = new Cacheable_threeNumbers(1,2,3);
43 Observable::channels_t ychannel(1, Cacheable_threeNumbers::YChanged);
44 YChange_numbers = new Cacheable_threeNumbers(1,2,3, ychannel);
45}
46
47void CacheableTest::tearDown(){
48 delete numbers;
49}
50
51void CacheableTest::doesRecalcTest()
52{
53 CPPUNIT_ASSERT_EQUAL( 6, *(numbers->sum));
54 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
55 numbers->hasRecalced=false;
56 numbers->setX(4);
57 CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced);
58 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
59 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
60 numbers->hasRecalced=false;
61 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
62#ifndef NO_CACHING
63 CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced);
64#else
65 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
66#endif
67
68 CPPUNIT_ASSERT_EQUAL( 6, *(YChange_numbers->sum));
69 CPPUNIT_ASSERT_EQUAL( true, YChange_numbers->hasRecalced);
70 YChange_numbers->hasRecalced=false;
71 YChange_numbers->setX(4);
72 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
73 CPPUNIT_ASSERT_EQUAL( 6, *(YChange_numbers->sum));
74 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
75 YChange_numbers->hasRecalced=false;
76 YChange_numbers->setY(4);
77 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
78 CPPUNIT_ASSERT_EQUAL( 11, *(YChange_numbers->sum));
79 CPPUNIT_ASSERT_EQUAL( true, YChange_numbers->hasRecalced);
80 YChange_numbers->hasRecalced=false;
81 CPPUNIT_ASSERT_EQUAL( 11, *(YChange_numbers->sum));
82#ifndef NO_CACHING
83 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
84#else
85 CPPUNIT_ASSERT_EQUAL( true, YChange_numbers->hasRecalced);
86#endif
87}
Note: See TracBrowser for help on using the repository browser.