source: src/unittests/manipulateAtomsTest.cpp@ bcf653

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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