source: src/Atom/unittests/AtomObserverUnitTest.cpp@ 97c2550

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 97c2550 was 97c2550, checked in by Frederik Heber <heber@…>, 13 years ago

Added unit test for AtomObserver.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * AtomObserverUnitTest.cpp
10 *
11 * Created on: Dec 19, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "AtomObserverUnitTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25#include <iostream>
26
27#include "CodePatterns/Log.hpp"
28
29#include "World.hpp"
30#include "Atom/atom.hpp"
31#include "Atom/AtomObserver.hpp"
32#include "Element/element.hpp"
33#include "Element/periodentafel.hpp"
34
35#include "stubs/ObserverStub.hpp"
36
37#ifdef HAVE_TESTRUNNER
38#include "UnitTestMain.hpp"
39#endif /*HAVE_TESTRUNNER*/
40
41/********************************************** Test classes **************************************/
42// Registers the fixture into the 'registry'
43CPPUNIT_TEST_SUITE_REGISTRATION( AtomObserverTest );
44
45// set up and tear down
46void AtomObserverTest::setUp(){
47 World::getInstance();
48 AtomObserver::getInstance();
49
50 setVerbosity(3);
51
52 // observer checks that we don't receive general updates ...
53 observer = new UpdateCountObserver;
54 // but only specific notifications in observer1 and observer2
55 observer1 = new NotificationObserver(
56 AtomObserver::getInstance().getChannel(AtomObservable::PositionChanged)
57 );
58 observer2 = new NotificationObserver(
59 AtomObserver::getInstance().getChannel(AtomObservable::ElementChanged)
60 );
61
62 AtomObserver::getInstance().signOn(observer);
63 AtomObserver::getInstance().signOn(observer1, AtomObservable::PositionChanged);
64 AtomObserver::getInstance().signOn(observer2, AtomObservable::ElementChanged);
65
66 for(int i=0;i<ATOM_COUNT;++i){
67 atoms[i]= World::getInstance().createAtom();
68 atomIds[i]= atoms[i]->getId();
69 }
70}
71
72void AtomObserverTest::tearDown()
73{
74 AtomObserver::getInstance().signOff(observer);
75 AtomObserver::getInstance().signOff(observer1, AtomObservable::PositionChanged);
76 AtomObserver::getInstance().signOff(observer2, AtomObservable::ElementChanged);
77
78 delete observer;
79 delete observer1;
80 delete observer2;
81
82 AtomObserver::purgeInstance();
83 World::purgeInstance();
84}
85
86/** Unit test on whether adding/removing atoms informs relay and onward.
87 *
88 */
89void AtomObserverTest::AtomAddTest()
90{
91 // check for zero update
92 CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
93 CPPUNIT_ASSERT_EQUAL( false, observer1->wasNotified );
94 CPPUNIT_ASSERT_EQUAL( false, observer2->wasNotified );
95}
96
97/** Unit test on whether moving atoms informs relay and onward.
98 *
99 */
100void AtomObserverTest::AtomMoveTest()
101{
102 // move an atom
103 atoms[0]->setPosition(Vector(1.,0.,0.));
104
105 // check for update
106 CPPUNIT_ASSERT_EQUAL( true, observer1->wasNotified );
107 CPPUNIT_ASSERT_EQUAL( false, observer2->wasNotified );
108 CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
109}
110
111/** Unit test on whether changing atom's element informs relay and onward.
112 *
113 */
114void AtomObserverTest::AtomElementTest()
115{
116 atoms[0]->setType(1);
117
118 // check for update
119 CPPUNIT_ASSERT_EQUAL( false, observer1->wasNotified );
120 CPPUNIT_ASSERT_EQUAL( true, observer2->wasNotified );
121 CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates );
122}
Note: See TracBrowser for help on using the repository browser.