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
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[bcf653]5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[b2cfdb]8/*
9 * manipulateAtomsTest.cpp
10 *
11 * Created on: Feb 18, 2010
12 * Author: crueger
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[b2cfdb]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"
[975a11]31#include "Actions/ActionHistory.hpp"
[b2cfdb]32
33#include "World.hpp"
[6f0841]34#include "Atom/atom.hpp"
[b2cfdb]35
[fdcd1b]36#include "stubs/DummyUI.hpp"
[efd61b]37
38#include "ManipulateAtomsUnitTest.hpp"
[112f90]39
[ce7fdc]40using namespace MoleCuilder;
41
[7ca806]42#ifdef HAVE_TESTRUNNER
43#include "UnitTestMain.hpp"
44#endif /*HAVE_TESTRUNNER*/
45
[b2cfdb]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(),
[23b547]54 manipulated(false),
55 id(_id)
[b2cfdb]56 {}
57
[57adc7]58 virtual atomId_t getId(){
[b2cfdb]59 return id;
60 }
61
62 virtual void doSomething(){
63 manipulated = true;
64 }
65
66 bool manipulated;
67private:
[57adc7]68 atomId_t id;
[b2cfdb]69};
70
[afb47f]71class countObserver : public Observer{
72public:
73 countObserver() :
[cd5047]74 Observer("countObserver"),
[afb47f]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};
[b2cfdb]88
89// set up and tear down
90void manipulateAtomsTest::setUp(){
[694d84]91 hasDescriptor = false;
[975a11]92 ActionHistory::init();
[23b547]93 World::getInstance();
[112f90]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");
[b2cfdb]100 for(int i=0;i<ATOM_COUNT;++i){
101 atoms[i]= new AtomStub(i);
[23b547]102 World::getInstance().registerAtom(atoms[i]);
[b2cfdb]103 }
104}
105void manipulateAtomsTest::tearDown(){
[23b547]106 World::purgeInstance();
[e73a8a2]107 ActionRegistry::purgeInstance();
[975a11]108 ActionHistory::purgeInstance();
[694d84]109 {
110 UIFactory::purgeInstance();
111 hasDescriptor = false;
112 }
[b2cfdb]113}
114
[a1510d]115static void operation(atom* _atom){
[b2cfdb]116 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
[6d574a]117 CPPUNIT_ASSERT(atom);
[b2cfdb]118 atom->doSomething();
119}
120
121
122void manipulateAtomsTest::testManipulateSimple(){
[23b547]123 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
[b2cfdb]124 proc->call();
[23b547]125 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
[b2cfdb]126 std::vector<atom*>::iterator iter;
127 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
128 AtomStub *atom;
129 atom = dynamic_cast<AtomStub*>(*iter);
[6d574a]130 CPPUNIT_ASSERT(atom);
[b2cfdb]131 CPPUNIT_ASSERT(atom->manipulated);
132 }
133}
134
135void manipulateAtomsTest::testManipulateExcluded(){
[229e3c]136
[23b547]137 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
[b2cfdb]138 proc->call();
[23b547]139 std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
[b2cfdb]140 std::vector<atom*>::iterator iter;
141 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
142 AtomStub *atom;
143 atom = dynamic_cast<AtomStub*>(*iter);
[6d574a]144 CPPUNIT_ASSERT(atom);
[b2cfdb]145 if(atom->getId()!=(int)ATOM_COUNT/2)
146 CPPUNIT_ASSERT(atom->manipulated);
147 else
148 CPPUNIT_ASSERT(!atom->manipulated);
149 }
150}
151
[afb47f]152void manipulateAtomsTest::testObserver(){
153 countObserver *obs = new countObserver();
[23b547]154 World::getInstance().signOn(obs);
[6e97e5]155 ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
[afb47f]156 proc->call();
157
158 CPPUNIT_ASSERT_EQUAL(1,obs->count);
[23b547]159 World::getInstance().signOff(obs);
[afb47f]160 delete obs;
161}
Note: See TracBrowser for help on using the repository browser.