source: src/unittests/manipulateAtomsTest.cpp@ 7c4e29

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 Candidate_v1.7.0 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 7c4e29 was b2cfdb, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added a method that allows manipulation of selected atoms

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * manipulateAtomsTest.cpp
3 *
4 * Created on: Feb 18, 2010
5 * Author: crueger
6 */
7
8#include "manipulateAtomsTest.hpp"
9
10#include "DescriptorUnittest.hpp"
11
12#include <cppunit/CompilerOutputter.h>
13#include <cppunit/extensions/TestFactoryRegistry.h>
14#include <cppunit/ui/text/TestRunner.h>
15#include <iostream>
16#include <boost/bind.hpp>
17
18#include "Descriptors/AtomDescriptor.hpp"
19#include "Descriptors/AtomIdDescriptor.hpp"
20#include "Actions/ManipulateAtomsProcess.hpp"
21#include "Actions/ActionRegistry.hpp"
22
23#include "World.hpp"
24#include "atom.hpp"
25
26// Registers the fixture into the 'registry'
27CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
28
29// some stubs
30class AtomStub : public atom {
31public:
32 AtomStub(int _id) :
33 atom(),
34 id(_id),
35 manipulated(false)
36 {}
37
38 virtual int getId(){
39 return id;
40 }
41
42 virtual void doSomething(){
43 manipulated = true;
44 }
45
46 bool manipulated;
47private:
48 int id;
49};
50
51
52// set up and tear down
53void manipulateAtomsTest::setUp(){
54 World::get();
55 for(int i=0;i<ATOM_COUNT;++i){
56 atoms[i]= new AtomStub(i);
57 }
58}
59void manipulateAtomsTest::tearDown(){
60 World::destroy();
61 for(int i=0;i<ATOM_COUNT;++i){
62 delete atoms[i];
63 }
64 ActionRegistry::purgeRegistry();
65}
66
67// some helper functions
68bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
69 for(int i=min;i<max;++i){
70 if(!excluded.count(i)){
71 std::vector<atom*>::iterator iter;
72 bool res=false;
73 for(iter=atoms.begin();iter!=atoms.end();++iter){
74 res |= (*iter)->getId() == i;
75 }
76 if(!res) {
77 cout << "Atom " << i << " missing in returned list" << endl;
78 return false;
79 }
80 }
81 }
82 return true;
83}
84
85bool hasNoDuplicates(std::vector<atom*> atoms){
86 std::set<int> found;
87 std::vector<atom*>::iterator iter;
88 for(iter=atoms.begin();iter!=atoms.end();++iter){
89 int id = (*iter)->getId();
90 if(found.count(id))
91 return false;
92 found.insert(id);
93 }
94 return true;
95}
96
97void operation(atom* _atom){
98 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
99 assert(atom);
100 atom->doSomething();
101}
102
103
104void manipulateAtomsTest::testManipulateSimple(){
105 ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
106 proc->call();
107 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
108 std::vector<atom*>::iterator iter;
109 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
110 AtomStub *atom;
111 atom = dynamic_cast<AtomStub*>(*iter);
112 assert(atom);
113 CPPUNIT_ASSERT(atom->manipulated);
114 }
115}
116
117void manipulateAtomsTest::testManipulateExcluded(){
118 ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
119 proc->call();
120 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
121 std::vector<atom*>::iterator iter;
122 for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
123 AtomStub *atom;
124 atom = dynamic_cast<AtomStub*>(*iter);
125 assert(atom);
126 if(atom->getId()!=(int)ATOM_COUNT/2)
127 CPPUNIT_ASSERT(atom->manipulated);
128 else
129 CPPUNIT_ASSERT(!atom->manipulated);
130 }
131}
132
133/********************************************** Main routine **************************************/
134
135int main(int argc, char **argv)
136{
137 // Get the top level suite from the registry
138 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
139
140 // Adds the test to the list of test to run
141 CppUnit::TextUi::TestRunner runner;
142 runner.addTest( suite );
143
144 // Change the default outputter to a compiler error format outputter
145 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
146 std::cerr ) );
147 // Run the tests.
148 bool wasSucessful = runner.run();
149
150 // Return error code 1 if the one of test failed.
151 return wasSucessful ? 0 : 1;
152};
Note: See TracBrowser for help on using the repository browser.