Changeset 99f4ee for src/unittests


Ignore:
Timestamp:
Jan 2, 2012, 1:34:58 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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:
4a8169
Parents:
9ed706
git-author:
Frederik Heber <heber@…> (12/21/11 18:02:07)
git-committer:
Frederik Heber <heber@…> (01/02/12 13:34:58)
Message:

Class Box is now also an Observable.

  • it has two channels to notify about changes in its Matrix and boundary conditions.
Location:
src/unittests
Files:
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • src/unittests/BoxUnitTest.cpp

    r9ed706 r99f4ee  
    2828
    2929#include "BoxUnitTest.hpp"
     30
     31#include "stubs/ObserverStub.hpp"
    3032
    3133#ifdef HAVE_TESTRUNNER
     
    16171619
    16181620}
     1621
     1622/** Unit test on whether observer is working.
     1623 *
     1624 */
     1625void BoxUnittest::ObserverTest()
     1626{
     1627  // create some observers
     1628  UpdateCountObserver *observer_general = new UpdateCountObserver();
     1629  NotificationObserver *observer_matrix = new NotificationObserver(
     1630      unitBox->getChannel(Box::MatrixChanged));
     1631  NotificationObserver *observer_bc = new NotificationObserver(
     1632      unitBox->getChannel(Box::BoundaryConditionsChanged));
     1633  CPPUNIT_ASSERT_EQUAL((int)0, observer_general->updates);
     1634  CPPUNIT_ASSERT_EQUAL(false, observer_matrix->wasNotified);
     1635  CPPUNIT_ASSERT_EQUAL(false, observer_bc->wasNotified);
     1636  unitBox->signOn(observer_general);
     1637  unitBox->signOn(observer_matrix, Box::MatrixChanged);
     1638  unitBox->signOn(observer_bc, Box::BoundaryConditionsChanged);
     1639
     1640  // create update MatrixChanged
     1641  unitBox->setM(*unit);
     1642  CPPUNIT_ASSERT_EQUAL((int)1, observer_general->updates);
     1643  CPPUNIT_ASSERT_EQUAL(true, observer_matrix->wasNotified);
     1644  CPPUNIT_ASSERT_EQUAL(false, observer_bc->wasNotified);
     1645  observer_matrix->wasNotified = false;
     1646
     1647  // create update BoundaryConditionsChanged
     1648  unitBox->setCondition(0, Box::Wrap);
     1649  CPPUNIT_ASSERT_EQUAL((int)2, observer_general->updates);
     1650  CPPUNIT_ASSERT_EQUAL(false, observer_matrix->wasNotified);
     1651  CPPUNIT_ASSERT_EQUAL(true, observer_bc->wasNotified);
     1652
     1653  // remove observers again
     1654  unitBox->signOff(observer_general);
     1655  unitBox->signOff(observer_matrix, Box::MatrixChanged);
     1656  unitBox->signOff(observer_bc, Box::BoundaryConditionsChanged);
     1657  delete observer_general;
     1658  delete observer_matrix;
     1659  delete observer_bc;
     1660}
  • src/unittests/BoxUnitTest.hpp

    r9ed706 r99f4ee  
    3030  CPPUNIT_TEST ( BoundaryIgnoreTest );
    3131  CPPUNIT_TEST ( BoundaryMixedTest );
     32  CPPUNIT_TEST ( ObserverTest );
    3233  CPPUNIT_TEST_SUITE_END();
    3334
     
    4344  void BoundaryIgnoreTest();
    4445  void BoundaryMixedTest();
     46  void ObserverTest();
    4547
    4648  RealSpaceMatrix *unit;
  • src/unittests/Makefile.am

    r9ed706 r99f4ee  
    7373        $(UIELEMENTSCOMMANDLINEPARSERTESTSSOURCES) \
    7474        ${UIELEMENTSMENUTESTSSOURCES} \
     75        stubs/ObserverStub.cpp \
    7576  BoxUnitTest.cpp \
    7677  FormulaUnitTest.cpp \
     
    9394        $(UIELEMENTSCOMMANDLINEPARSERTESTSHEADERS) \
    9495        ${UIELEMENTSMENUTESTSHEADERS} \
     96        stubs/ObserverStub.hpp \
    9597  BoxUnitTest.hpp \
    9698  FormulaUnitTest.hpp \
     
    101103BoxUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    102104        BoxUnitTest.cpp \
    103         BoxUnitTest.hpp
     105        BoxUnitTest.hpp \
     106        stubs/ObserverStub.cpp \
     107        stubs/ObserverStub.hpp 
    104108BoxUnitTest_LDADD = \
    105109        ../libMolecuilder.la \
  • src/unittests/stubs/ObserverStub.cpp

    r9ed706 r99f4ee  
    4343}
    4444
     45/*********** NotificationObserver **************/
     46
    4547NotificationObserver::NotificationObserver(Notification_ptr notification) :
    4648  Observer("NotificationObserver"),
     
    4850  wasNotified(false)
    4951{}
    50 
    51 /*********** NotificationObserver **************/
    5252
    5353NotificationObserver::~NotificationObserver()
Note: See TracChangeset for help on using the changeset viewer.