source: src/unittests/CacheableTest.cpp@ 02ee15

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 02ee15 was 2ba827, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Changed all observed places to new observer structure

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 * CacheableTest.cpp
3 *
4 * Created on: Feb 2, 2010
5 * Author: crueger
6 */
7
8#include "CacheableTest.hpp"
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <boost/bind.hpp>
15
16#include "Patterns/Cacheable.hpp"
17
18// Registers the fixture into the 'registry'
19CPPUNIT_TEST_SUITE_REGISTRATION( CacheableTest );
20
21class threeNumbers : public Observable {
22public:
23 bool hasRecalced;
24 int x;
25 int y;
26 int z;
27
28 void setX(int _x){
29 OBSERVE;
30 x = _x;
31 }
32
33 void setY
34 (int _y){
35 OBSERVE;
36 y = _y;
37 }
38
39 void setZ(int _z){
40 OBSERVE;
41 z = _z;
42 }
43
44 int calcSum(){
45 hasRecalced = true;
46 return x+y+z;
47 }
48
49 threeNumbers(int _x,int _y, int _z) :
50 sum(this,boost::bind(&threeNumbers::calcSum,this)),
51 x(_x),y(_y),z(_z),
52 hasRecalced(false)
53 {}
54
55 Cacheable<int> sum;
56};
57
58
59
60
61void CacheableTest::setUp(){
62 numbers = new threeNumbers(1,2,3);
63}
64
65void CacheableTest::tearDown(){
66 delete numbers;
67}
68
69void CacheableTest::doesRecalcTest()
70{
71 CPPUNIT_ASSERT_EQUAL( 6, *(numbers->sum));
72 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
73 numbers->hasRecalced=false;
74 numbers->setX(4);
75 CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced);
76 CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum));
77 CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced);
78}
79
80
81
82/********************************************** Main routine **************************************/
83
84int main(int argc, char **argv)
85{
86 // Get the top level suite from the registry
87 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
88
89 // Adds the test to the list of test to run
90 CppUnit::TextUi::TestRunner runner;
91 runner.addTest( suite );
92
93 // Change the default outputter to a compiler error format outputter
94 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
95 std::cerr ) );
96 // Run the tests.
97 bool wasSucessful = runner.run();
98
99 // Return error code 1 if the one of test failed.
100 return wasSucessful ? 0 : 1;
101};
102
Note: See TracBrowser for help on using the repository browser.