Changeset bd58fb for src/unittests


Ignore:
Timestamp:
Mar 4, 2010, 3:20:51 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
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
Children:
e87acf
Parents:
57adc7
Message:

Added an iterator pattern for observed Data structures

Location:
src/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ObserverTest.cpp

    r57adc7 rbd58fb  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13#include <set>
    1314
    1415#include "Patterns/Observer.hpp"
     16#include "Patterns/ObservedIterator.hpp"
    1517
    1618#include <iostream>
     
    8385};
    8486
     87class ObservableCollection : public Observable {
     88public:
     89  typedef std::set<SimpleObservable*> set;
     90  typedef ObservedIterator<set> iterator;
     91
     92  ObservableCollection(int num){
     93    for(int i=0; i<num; ++i){
     94      SimpleObservable *content = new SimpleObservable();
     95      content->signOn(this);
     96      theSet.insert(content);
     97    }
     98  }
     99
     100  ~ObservableCollection(){
     101    set::iterator iter;
     102    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
     103      delete (*iter);
     104    }
     105  }
     106
     107  iterator begin(){
     108    return iterator(theSet.begin(),this);
     109  }
     110
     111  iterator end(){
     112    return iterator(theSet.end(),this);
     113  }
     114
     115private:
     116  set theSet;
     117};
     118
    85119/******************* actuall tests ***************/
    86120
     
    95129  observer3 = new UpdateCountObserver();
    96130  observer4 = new UpdateCountObserver();
     131
     132  collection = new ObservableCollection(5);
    97133}
    98134
     
    107143  delete observer3;
    108144  delete observer4;
     145
     146  delete collection;
    109147}
    110148
     
    163201}
    164202
     203void ObserverTest::iteratorTest(){
     204  collection->signOn(observer1);
     205  {
     206    ObservableCollection::iterator iter;
     207    for(iter=collection->begin(); iter!=collection->end(); ++iter){
     208      (*iter)->changeMethod();
     209    }
     210    // At this point no change should have been propagated
     211    CPPUNIT_ASSERT_EQUAL( 0, observer1->updates);
     212  }
     213  // After the Iterator has died the propagation should take place
     214  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     215  collection->signOff(observer1);
     216}
     217
    165218
    166219void ObserverTest::CircleDetectionTest() {
  • src/unittests/ObserverTest.hpp

    r57adc7 rbd58fb  
    1616class CallObservable;
    1717class SuperObservable;
     18class ObservableCollection;
    1819
    1920
     
    2425  CPPUNIT_TEST ( doesBlockUpdateTest );
    2526  CPPUNIT_TEST ( doesSubObservableTest );
     27  CPPUNIT_TEST ( iteratorTest );
    2628  CPPUNIT_TEST ( CircleDetectionTest );
    2729  CPPUNIT_TEST_SUITE_END();
     
    3436  void doesBlockUpdateTest();
    3537  void doesSubObservableTest();
     38  void iteratorTest();
    3639  void CircleDetectionTest();
    3740
     
    4649  CallObservable *callObservable;
    4750  SuperObservable *superObservable;
     51
     52  ObservableCollection *collection;
    4853};
    4954
Note: See TracChangeset for help on using the changeset viewer.