source: ThirdParty/CodePatterns/src/Patterns/unittests/ObservedValueUnitTest.cpp

Candidate_v1.6.1
Last change on this file was 70fee0, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

ObservedValue has forceUpdate() public function to externally force an update.

  • TESTS: unit test function extended to include that function.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2015 Frederik Heber. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ObservedValueUnitTest.cpp
10 *
11 * Created on: Jun 19, 2015
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "ObservedValueUnitTest.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/ObservedValue.hpp"
29
30#include "stubs/ObservedValue_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( ObservedValueTest );
40
41void ObservedValueTest::setUp(){
42 numbers = new ObservedValue_threeNumbers(1,2,3);
43 Observable::channels_t ychannel(1, ObservedValue_threeNumbers::YChanged);
44 YChange_numbers = new ObservedValue_threeNumbers(1,2,3, ychannel);
45}
46
47void ObservedValueTest::tearDown(){
48 delete numbers;
49 delete YChange_numbers;
50}
51
52void ObservedValueTest::doesRecalcTest()
53{
54 CPPUNIT_ASSERT_EQUAL( 6, (numbers->sum).get());
55 CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced);
56 numbers->hasRecalced=false;
57 numbers->setX(4);
58 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
59 CPPUNIT_ASSERT_EQUAL( 9, (numbers->sum).get());
60 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
61
62 CPPUNIT_ASSERT_EQUAL( 6, (YChange_numbers->sum).get());
63 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
64 YChange_numbers->hasRecalced=false;
65 YChange_numbers->setX(4);
66 CPPUNIT_ASSERT_EQUAL( false, YChange_numbers->hasRecalced);
67 CPPUNIT_ASSERT_EQUAL( 6, (YChange_numbers->sum).get());
68 YChange_numbers->hasRecalced=false;
69 YChange_numbers->setY(4);
70 CPPUNIT_ASSERT_EQUAL( true, YChange_numbers->hasRecalced);
71 CPPUNIT_ASSERT_EQUAL( 11, (YChange_numbers->sum).get());
72
73 numbers->hasRecalced=false;
74 numbers->sum.forceUpdate();
75 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
76}
Note: See TracBrowser for help on using the repository browser.