source: src/unittests/manipulateAtomsTest.cpp@ 13e3c3

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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