Ignore:
Timestamp:
Oct 5, 2009, 8:51:24 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
eaee7f
Parents:
13a574
Message:

Member functions of Vector class may be called while going over an iteration of a list containing Vectors, thanks to member function pointers.

  • Unit test ActOnAllTest is the basic class for showing, how we can use any member function of Vector:: and make it act globally over a list of vectors.
  • this is incorporated into the definition of class molecule for the vectors contained in the atoms chained list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ActOnAllUnitTest.cpp

    r13a574 r33f9f7  
    3131  temp = new Vector(0,0,1);
    3232  VL.AddVector(temp);
     33  Ref = VL;
    3334};
    3435
     
    3940};
    4041
     42/** UnitTest for VectorList::ActOnAllVectors() and Vector::AddVector(), Vector::SubtractVector(),
     43 */
     44void ActOnAllTest::AddSubtractTest()
     45{
     46  const Vector test(1.,0.,0.);
     47
     48  // adding, subtracting
     49  VL.ActOnAllVectors( &Vector::AddVector, &test );
     50  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
     51  VL.ActOnAllVectors( &Vector::SubtractVector, &test );
     52  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
     53};
     54
    4155/** UnitTest for VectorList::ActOnAllVectors()
    4256 */
    43 void ActOnAllTest::ListTest()
     57void ActOnAllTest::ScaleTest()
    4458{
    45   CPPUNIT_ASSERT_EQUAL( true, true );
     59  double factor=2.;
     60  double inverse=1./2.;
     61
     62  // scaling by value
     63  VL.ActOnAllVectors( (void (Vector::*)(double)) &Vector::Scale, 2. );
     64  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
     65
     66  VL.ActOnAllVectors( (void (Vector::*)(double)) &Vector::Scale, 0.5 );
     67  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
     68
     69  // scaling by ref
     70  VL.ActOnAllVectors( (void (Vector::*)(double *)) &Vector::Scale, &factor );
     71  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
     72
     73  VL.ActOnAllVectors( (void (Vector::*)(double *)) &Vector::Scale, &inverse );
     74  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
     75
     76  // scaling by three values
     77  double *factors = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - factors");
     78  double *inverses = Malloc<double>(NDIM, "ActOnAllTest::ScaleTest - inverses");
     79  for (int i=0;i<NDIM;++i) {
     80    factors[i] = 2.;
     81    inverses[i] = 1./factors[i];
     82  }
     83  VL.ActOnAllVectors( (void (Vector::*)(double **)) &Vector::Scale, &factors );
     84  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
     85
     86  VL.ActOnAllVectors( (void (Vector::*)(double **)) &Vector::Scale, &inverses );
     87  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
    4688};
     89
     90/** UnitTest for VectorList::ActOnAllVectors() and Vector::MakeNormalVector()
     91 */
     92void ActOnAllTest::NormalizeTest()
     93{
     94  const Vector xaxis(1.,0.,0.);
     95  const Vector yaxis(0.,1.,0.);
     96
     97  // normalize with respect to x and y axis
     98  bool (Vector::*f)(const Vector *, const Vector *) = &Vector::MakeNormalVector;
     99  VL.ActOnAllVectors( f, &xaxis, &yaxis );
     100  CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
     101
     102  // check that x and y components are zero
     103  for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) {
     104    CPPUNIT_ASSERT_EQUAL( (*Runner)->x[0] , 0. );
     105    CPPUNIT_ASSERT_EQUAL( (*Runner)->x[1] , 0. );
     106  }
     107};
     108
    47109
    48110/********************************************** Main routine **************************************/
Note: See TracChangeset for help on using the changeset viewer.