source: src/unittests/atomsCalculationTest.cpp@ a1510d

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 a1510d was a1510d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * atomsCalculationTest.cpp
3 *
4 * Created on: Feb 19, 2010
5 * Author: crueger
6 */
7
8#include "atomsCalculationTest.hpp"
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13#include <iostream>
14#include <boost/bind.hpp>
15
16#include "Descriptors/AtomDescriptor.hpp"
17#include "Descriptors/AtomIdDescriptor.hpp"
18#include "Actions/AtomsCalculation.hpp"
19#include "Actions/AtomsCalculation_impl.hpp"
20#include "Actions/ActionRegistry.hpp"
21
22#include "World.hpp"
23#include "World_calculations.hpp"
24#include "atom.hpp"
25
26// Registers the fixture into the 'registry'
27CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest );
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// set up and tear down
52void atomsCalculationTest::setUp(){
53 World::get();
54 for(int i=0;i<ATOM_COUNT;++i){
55 atoms[i]= new AtomStub(i);
56 World::get()->registerAtom(atoms[i]);
57 }
58}
59void atomsCalculationTest::tearDown(){
60 World::destroy();
61 ActionRegistry::purgeRegistry();
62}
63
64// some helper functions
65static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){
66 for(int i=min;i<max;++i){
67 if(!excluded.count(i)){
68 std::vector<int>::iterator iter;
69 bool res=false;
70 for(iter=ids.begin();iter!=ids.end();++iter){
71 res |= (*iter) == i;
72 }
73 if(!res) {
74 cout << "Atom " << i << " missing in returned list" << endl;
75 return false;
76 }
77 }
78 }
79 return true;
80}
81
82static bool hasNoDuplicates(std::vector<int> ids){
83 std::set<int> found;
84 std::vector<int>::iterator iter;
85 for(iter=ids.begin();iter!=ids.end();++iter){
86 int id = (*iter);
87 if(found.count(id))
88 return false;
89 found.insert(id);
90 }
91 return true;
92}
93
94static void operation(atom* _atom){
95 AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
96 assert(atom);
97 atom->doSomething();
98}
99
100
101void atomsCalculationTest::testCalculateSimple(){
102 AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
103 std::vector<int> allIds = (*calc)();
104 CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT));
105 CPPUNIT_ASSERT(hasNoDuplicates(allIds));
106}
107
108void atomsCalculationTest::testCalculateExcluded(){
109 int excluded = ATOM_COUNT/2;
110 AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
111 std::vector<int> allIds = (*calc)();
112 std::set<int> excluded_set;
113 excluded_set.insert(excluded);
114 CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT,excluded_set));
115 CPPUNIT_ASSERT(hasNoDuplicates(allIds));
116 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
117}
Note: See TracBrowser for help on using the repository browser.