source: src/Actions/unittests/ManipulateAtomsUnitTest.cpp@ 66fd49

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 66fd49 was efd61b, checked in by Frederik Heber <heber@…>, 14 years ago

Moved manipulateAtomsTest to Actions/unittests/ManipulateAtomsUnitTest.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * manipulateAtomsTest.cpp
10 *
11 * Created on: Feb 18, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20
21#include <cppunit/CompilerOutputter.h>
22#include <cppunit/extensions/TestFactoryRegistry.h>
23#include <cppunit/ui/text/TestRunner.h>
24#include <iostream>
25#include <boost/bind.hpp>
26
27#include "Descriptors/AtomDescriptor.hpp"
28#include "Descriptors/AtomIdDescriptor.hpp"
29#include "Actions/ManipulateAtomsProcess.hpp"
30#include "Actions/ActionRegistry.hpp"
31#include "Actions/ActionHistory.hpp"
32
33#include "World.hpp"
34#include "atom.hpp"
35
36#include "unittests/DummyUI.hpp"
37
38#include "ManipulateAtomsUnitTest.hpp"
39
40#ifdef HAVE_TESTRUNNER
41#include "UnitTestMain.hpp"
42#endif /*HAVE_TESTRUNNER*/
43
44// Registers the fixture into the 'registry'
45CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
46
47// some stubs
48class AtomStub : public atom {
49public:
50 AtomStub(int _id) :
51 atom(),
52 manipulated(false),
53 id(_id)
54 {}
55
56 virtual atomId_t getId(){
57 return id;
58 }
59
60 virtual void doSomething(){
61 manipulated = true;
62 }
63
64 bool manipulated;
65private:
66 atomId_t id;
67};
68
69class countObserver : public Observer{
70public:
71 countObserver() :
72 Observer("countObserver"),
73 count(0)
74 {}
75 virtual ~countObserver(){}
76
77 void update(Observable *){
78 count++;
79 }
80
81 void subjectKilled(Observable *)
82 {}
83
84 int count;
85};
86
87// set up and tear down
88void manipulateAtomsTest::setUp(){
89 hasDescriptor = false;
90 ActionHistory::init();
91 World::getInstance();
92 // TODO: find a way to really reset the factory to a clean state in tear-down
93 if(!hasDescriptor){
94 UIFactory::registerFactory(new DummyUIFactory::description());
95 hasDescriptor = true;
96 }
97 UIFactory::makeUserInterface("Dummy");
98 for(int i=0;i<ATOM_COUNT;++i){
99 atoms[i]= new AtomStub(i);
100 World::getInstance().registerAtom(atoms[i]);
101 }
102}
103void manipulateAtomsTest::tearDown(){
104 World::purgeInstance();
105 ActionRegistry::purgeInstance();
106 ActionHistory::purgeInstance();
107 {
108 UIFactory::purgeInstance();
109 hasDescriptor = false;
110 }
111}
112
113static void operation(atom* _atom){
114 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
115 CPPUNIT_ASSERT(atom);
116 atom->doSomething();
117}
118
119
120void manipulateAtomsTest::testManipulateSimple(){
121 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
122 proc->call();
123 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
124 std::vector<atom*>::iterator iter;
125 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
126 AtomStub *atom;
127 atom = dynamic_cast<AtomStub*>(*iter);
128 CPPUNIT_ASSERT(atom);
129 CPPUNIT_ASSERT(atom->manipulated);
130 }
131}
132
133void manipulateAtomsTest::testManipulateExcluded(){
134
135 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
136 proc->call();
137 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
138 std::vector<atom*>::iterator iter;
139 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
140 AtomStub *atom;
141 atom = dynamic_cast<AtomStub*>(*iter);
142 CPPUNIT_ASSERT(atom);
143 if(atom->getId()!=(int)ATOM_COUNT/2)
144 CPPUNIT_ASSERT(atom->manipulated);
145 else
146 CPPUNIT_ASSERT(!atom->manipulated);
147 }
148}
149
150void manipulateAtomsTest::testObserver(){
151 countObserver *obs = new countObserver();
152 World::getInstance().signOn(obs);
153 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
154 proc->call();
155
156 CPPUNIT_ASSERT_EQUAL(1,obs->count);
157 World::getInstance().signOff(obs);
158 delete obs;
159}
Note: See TracBrowser for help on using the repository browser.