source: src/unittests/atomsCalculationTest.cpp@ aee1a3

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

Changed ActionRegistry to use the new Singleton Mechanism

  • 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#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30// Registers the fixture into the 'registry'
31CPPUNIT_TEST_SUITE_REGISTRATION( atomsCalculationTest );
32
33// some stubs
34class AtomStub : public atom {
35public:
36 AtomStub(atomId_t _id) :
37 atom(),
38 id(_id),
39 manipulated(false)
40 {}
41
42 virtual atomId_t getId(){
43 return id;
44 }
45
46 virtual void doSomething(){
47 manipulated = true;
48 }
49
50 bool manipulated;
51private:
52 atomId_t id;
53};
54
55// set up and tear down
56void atomsCalculationTest::setUp(){
57 World::getInstance();
58 for(int i=0;i<ATOM_COUNT;++i){
59 atoms[i]= new AtomStub(i);
60 World::getInstance().registerAtom(atoms[i]);
61 }
62}
63void atomsCalculationTest::tearDown(){
64 World::purgeInstance();
65 ActionRegistry::purgeInstance();
66}
67
68// some helper functions
69static bool hasAll(std::vector<int> ids,int min, int max, std::set<int> excluded = std::set<int>()){
70 for(int i=min;i<max;++i){
71 if(!excluded.count(i)){
72 std::vector<int>::iterator iter;
73 bool res=false;
74 for(iter=ids.begin();iter!=ids.end();++iter){
75 res |= (*iter) == i;
76 }
77 if(!res) {
78 cout << "Atom " << i << " missing in returned list" << endl;
79 return false;
80 }
81 }
82 }
83 return true;
84}
85
86static bool hasNoDuplicates(std::vector<int> ids){
87 std::set<int> found;
88 std::vector<int>::iterator iter;
89 for(iter=ids.begin();iter!=ids.end();++iter){
90 int id = (*iter);
91 if(found.count(id))
92 return false;
93 found.insert(id);
94 }
95 return true;
96}
97
98void atomsCalculationTest::testCalculateSimple(){
99 AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
100 std::vector<int> allIds = (*calc)();
101 CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT));
102 CPPUNIT_ASSERT(hasNoDuplicates(allIds));
103}
104
105void atomsCalculationTest::testCalculateExcluded(){
106 int excluded = ATOM_COUNT/2;
107 AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
108 std::vector<int> allIds = (*calc)();
109 std::set<int> excluded_set;
110 excluded_set.insert(excluded);
111 CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT,excluded_set));
112 CPPUNIT_ASSERT(hasNoDuplicates(allIds));
113 CPPUNIT_ASSERT_EQUAL((size_t)(ATOM_COUNT-1),allIds.size());
114}
Note: See TracBrowser for help on using the repository browser.