source: src/Actions/unittests/ManipulateAtomsUnitTest.cpp@ 311137

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

Updated all source files's copyright note to current year 2012.

  • 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-2012 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/atom.hpp"
35
36#include "stubs/DummyUI.hpp"
37
38#include "ManipulateAtomsUnitTest.hpp"
39
40using namespace MoleCuilder;
41
42#ifdef HAVE_TESTRUNNER
43#include "UnitTestMain.hpp"
44#endif /*HAVE_TESTRUNNER*/
45
46// Registers the fixture into the 'registry'
47CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
48
49// some stubs
50class AtomStub : public atom {
51public:
52 AtomStub(int _id) :
53 atom(),
54 manipulated(false),
55 id(_id)
56 {}
57
58 virtual atomId_t getId(){
59 return id;
60 }
61
62 virtual void doSomething(){
63 manipulated = true;
64 }
65
66 bool manipulated;
67private:
68 atomId_t id;
69};
70
71class countObserver : public Observer{
72public:
73 countObserver() :
74 Observer("countObserver"),
75 count(0)
76 {}
77 virtual ~countObserver(){}
78
79 void update(Observable *){
80 count++;
81 }
82
83 void subjectKilled(Observable *)
84 {}
85
86 int count;
87};
88
89// set up and tear down
90void manipulateAtomsTest::setUp(){
91 hasDescriptor = false;
92 ActionHistory::init();
93 World::getInstance();
94 // TODO: find a way to really reset the factory to a clean state in tear-down
95 if(!hasDescriptor){
96 UIFactory::registerFactory(new DummyUIFactory::description());
97 hasDescriptor = true;
98 }
99 UIFactory::makeUserInterface("Dummy");
100 for(int i=0;i<ATOM_COUNT;++i){
101 atoms[i]= new AtomStub(i);
102 World::getInstance().registerAtom(atoms[i]);
103 }
104}
105void manipulateAtomsTest::tearDown(){
106 World::purgeInstance();
107 ActionRegistry::purgeInstance();
108 ActionHistory::purgeInstance();
109 {
110 UIFactory::purgeInstance();
111 hasDescriptor = false;
112 }
113}
114
115static void operation(atom* _atom){
116 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
117 CPPUNIT_ASSERT(atom);
118 atom->doSomething();
119}
120
121
122void manipulateAtomsTest::testManipulateSimple(){
123 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
124 proc->call();
125 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
126 std::vector<atom*>::iterator iter;
127 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
128 AtomStub *atom;
129 atom = dynamic_cast<AtomStub*>(*iter);
130 CPPUNIT_ASSERT(atom);
131 CPPUNIT_ASSERT(atom->manipulated);
132 }
133}
134
135void manipulateAtomsTest::testManipulateExcluded(){
136
137 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
138 proc->call();
139 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
140 std::vector<atom*>::iterator iter;
141 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
142 AtomStub *atom;
143 atom = dynamic_cast<AtomStub*>(*iter);
144 CPPUNIT_ASSERT(atom);
145 if(atom->getId()!=(int)ATOM_COUNT/2)
146 CPPUNIT_ASSERT(atom->manipulated);
147 else
148 CPPUNIT_ASSERT(!atom->manipulated);
149 }
150}
151
152void manipulateAtomsTest::testObserver(){
153 countObserver *obs = new countObserver();
154 World::getInstance().signOn(obs);
155 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
156 proc->call();
157
158 CPPUNIT_ASSERT_EQUAL(1,obs->count);
159 World::getInstance().signOff(obs);
160 delete obs;
161}
Note: See TracBrowser for help on using the repository browser.