Ignore:
Timestamp:
Oct 17, 2011, 4:52:28 PM (13 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:
ec0acc
Parents:
39fa96
git-author:
Frederik Heber <heber@…> (10/04/11 08:35:42)
git-committer:
Frederik Heber <heber@…> (10/17/11 16:52:28)
Message:

Added operator==() to Continuous- and DiscreteParameter classes.

  • added comparator function for both Parameter types.
  • added unit tests on these.
Location:
src/Parser/Parameters
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/Parameters/ContinuousParameter.hpp

    r39fa96 r6b5228  
    3030  virtual ~ContinuousParameter();
    3131
     32  // comparator
     33  bool operator==(const ContinuousParameter<T> &_instance) const;
     34  bool operator!=(const ContinuousParameter<T> &_instance) const
     35      { return !((*this)==(_instance)); }
     36
    3237  Parameter* clone() const;
    3338
  • src/Parser/Parameters/ContinuousParameter_impl.hpp

    r39fa96 r6b5228  
    4242{};
    4343
     44/** Compares this continuous value against another \a _instance.
     45 *
     46 * @param _instance other value to compare to
     47 * @return true - if contained ContinuousValue and name are the same, false - else
     48 */
     49template <class T>
     50bool ContinuousParameter<T>::operator==(const ContinuousParameter<T> &_instance) const
     51{
     52  bool status = true;
     53  status = status &&
     54      (*dynamic_cast<const ContinuousValue<T> *>(this) == dynamic_cast<const ContinuousValue<T> &>(_instance));
     55  status = status && (Parameter::getName() == _instance.Parameter::getName());
     56  return status;
     57}
     58
    4459/** Creates a clone of this Parameter instance.
    4560 *
  • src/Parser/Parameters/DiscreteParameter.hpp

    r39fa96 r6b5228  
    3232  virtual ~DiscreteParameter();
    3333
     34  // comparator
     35  bool operator==(const DiscreteParameter<T> &_instance) const;
     36  bool operator!=(const DiscreteParameter<T> &_instance) const
     37      { return !((*this)==(_instance)); }
     38
    3439  Parameter* clone() const;
    3540
  • src/Parser/Parameters/DiscreteParameter_impl.hpp

    r39fa96 r6b5228  
    4444{};
    4545
     46/** Compares this discrete value against another \a _instance.
     47 *
     48 * @param _instance other value to compare to
     49 * @return true - if contained DiscreteValue and name are the same, false - else
     50 */
     51template <class T>
     52bool DiscreteParameter<T>::operator==(const DiscreteParameter<T> &_instance) const
     53{
     54  bool status = true;
     55  status = status &&
     56      (*dynamic_cast<const DiscreteValue<T> *>(this) == dynamic_cast<const DiscreteValue<T> &>(_instance));
     57  status = status && (Parameter::getName() == _instance.Parameter::getName());
     58  return status;
     59}
     60
    4661/** Creates a clone of this Parameter instance.
    4762 *
  • src/Parser/Parameters/unittests/ContinuousParameterUnitTest.cpp

    r39fa96 r6b5228  
    5151/************************************ tests ***********************************/
    5252
     53/** Unit test for comparator.
     54 *
     55 */
     56void ContinuousParameterTest::comparatorTest()
     57{
     58  // create instance
     59  ContinuousParameter<int> test("intParam", *ValidRange);
     60  ContinuousParameter<int> samenamedsamevalued("intParam", *ValidRange);
     61  ContinuousParameter<int> samenamedelsevalued("intParam", *ValidRange);
     62  ContinuousParameter<int> elsenamedsamevalued("int2Param", *ValidRange);
     63  ContinuousParameter<int> elsenamedelsevalued("int2Param", *ValidRange);
     64  test.setValue(1);
     65  samenamedsamevalued.setValue(1);
     66  samenamedelsevalued.setValue(2);
     67  elsenamedsamevalued.setValue(1);
     68  elsenamedelsevalued.setValue(2);
     69
     70  CPPUNIT_ASSERT( test == samenamedsamevalued );
     71  CPPUNIT_ASSERT( test != samenamedelsevalued );
     72  CPPUNIT_ASSERT( test != elsenamedsamevalued );
     73  CPPUNIT_ASSERT( test != elsenamedelsevalued );
     74}
     75
    5376/** Unit test for clone.
    5477 *
  • src/Parser/Parameters/unittests/ContinuousParameterUnitTest.hpp

    r39fa96 r6b5228  
    2222{
    2323  CPPUNIT_TEST_SUITE( ContinuousParameterTest ) ;
     24  CPPUNIT_TEST ( comparatorTest );
    2425  CPPUNIT_TEST ( cloneTest );
    2526  CPPUNIT_TEST_SUITE_END();
     
    2930  void tearDown();
    3031
     32  void comparatorTest();
    3133  void cloneTest();
    3234
  • src/Parser/Parameters/unittests/DiscreteParameterUnitTest.cpp

    r39fa96 r6b5228  
    5353/************************************ tests ***********************************/
    5454
     55/** Unit test for comparator.
     56 *
     57 */
     58void DiscreteParameterTest::comparatorTest()
     59{
     60  // create instance
     61  DiscreteParameter<int> test("intParam", ValidValues);
     62  DiscreteParameter<int> samenamedsamevalued("intParam", ValidValues);
     63  DiscreteParameter<int> samenamedelsevalued("intParam", ValidValues);
     64  DiscreteParameter<int> elsenamedsamevalued("int2Param", ValidValues);
     65  DiscreteParameter<int> elsenamedelsevalued("int2Param", ValidValues);
     66  test.setValue(1);
     67  samenamedsamevalued.setValue(1);
     68  samenamedelsevalued.setValue(2);
     69  elsenamedsamevalued.setValue(1);
     70  elsenamedelsevalued.setValue(2);
     71
     72  CPPUNIT_ASSERT( test == samenamedsamevalued );
     73  CPPUNIT_ASSERT( test != samenamedelsevalued );
     74  CPPUNIT_ASSERT( test != elsenamedsamevalued );
     75  CPPUNIT_ASSERT( test != elsenamedelsevalued );
     76}
     77
    5578/** Unit test for clone.
    5679 *
  • src/Parser/Parameters/unittests/DiscreteParameterUnitTest.hpp

    r39fa96 r6b5228  
    2020{
    2121  CPPUNIT_TEST_SUITE( DiscreteParameterTest ) ;
     22  CPPUNIT_TEST ( comparatorTest );
    2223  CPPUNIT_TEST ( cloneTest );
    2324  CPPUNIT_TEST_SUITE_END();
     
    2728  void tearDown();
    2829
     30  void comparatorTest();
    2931  void cloneTest();
    3032
Note: See TracChangeset for help on using the changeset viewer.