Changeset 498ddd for src/Parser


Ignore:
Timestamp:
Oct 17, 2011, 2:45:04 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:
c4afd1
Parents:
84e752
git-author:
Frederik Heber <heber@…> (09/30/11 12:26:44)
git-committer:
Frederik Heber <heber@…> (10/17/11 14:45:04)
Message:

Added operator==() and operator!=() to Continuous- and DiscreteValue.

  • ValueInterface is now inherited virtually.
  • this is preparatory for class Parameter which is a clonable ...Value.
  • we need comparators for the unit tests on that.
  • unit test added for comparators.
Location:
src/Parser/Parameters
Files:
8 edited

Legend:

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

    r84e752 r498ddd  
    2727 */
    2828template <class T>
    29 class ContinuousValue : public ValueInterface
     29class ContinuousValue : virtual public ValueInterface
    3030{
    3131  //!> unit test needs to have access to internal values
     
    4040  const std::string get() const;
    4141  void set(const std::string _value);
     42
     43  // comparator
     44  bool operator==(const ContinuousValue<T> &_instance) const;
     45  bool operator!=(const ContinuousValue<T> &_instance) const
     46      { return !((*this)==(_instance)); }
    4247
    4348  // getter/setter for valid ranges
  • src/Parser/Parameters/ContinuousValue_impl.hpp

    r84e752 r498ddd  
    6464//  LOG(0, "Converted value reads " << castvalue <<".");
    6565  return isValidValue(castvalue);
     66}
     67
     68/** Compares this continuous value against another \a _instance.
     69 *
     70 * @param _instance other value to compare to
     71 * @return true - if value and valid ranges are the same, false - else
     72 */
     73template <class T>
     74bool ContinuousValue<T>::operator==(const ContinuousValue<T> &_instance) const
     75{
     76  bool status = true;
     77  status = status && (ValidRange == _instance.ValidRange);
     78  status = status && (ValueSet == _instance.ValueSet);
     79  if (ValueSet && _instance.ValueSet)
     80    status = status && (value == _instance.value);
     81  return status;
    6682}
    6783
  • src/Parser/Parameters/DiscreteValue.hpp

    r84e752 r498ddd  
    2727 */
    2828template <class T>
    29 class DiscreteValue : public ValueInterface
     29class DiscreteValue : virtual public ValueInterface
    3030{
    3131  //!> unit test needs to have access to internal values
     
    4040  const std::string get() const;
    4141  void set(const std::string _value);
     42
     43  // comparator
     44  bool operator==(const DiscreteValue<T> &_instance) const;
     45  bool operator!=(const DiscreteValue<T> &_instance) const
     46      { return !((*this)==(_instance)); }
    4247
    4348  // setter/getter for valid values
  • src/Parser/Parameters/DiscreteValue_impl.hpp

    r84e752 r498ddd  
    5959  return isValidValue(castvalue);
    6060}
     61
     62/** Compares this discrete value against another \a _instance.
     63 *
     64 * @param _instance other value to compare to
     65 * @return true - if value and valid ranges are the same, false - else
     66 */
     67template <class T>
     68bool DiscreteValue<T>::operator==(const DiscreteValue<T> &_instance) const
     69{
     70  bool status = true;
     71  status = status && (ValidValues == _instance.ValidValues);
     72  status = status && (ValueSet == _instance.ValueSet);
     73  if (ValueSet && _instance.ValueSet)
     74    status = status && (value == _instance.value);
     75  return status;
     76}
     77
    6178
    6279/** Getter of value, returning string.
  • src/Parser/Parameters/unittests/ContinuousValueUnitTest.cpp

    r84e752 r498ddd  
    193193}
    194194
     195/** Unit test for comparator.
     196 *
     197 */
     198void ContinuousValueTest::comparatorTest()
     199{
     200  {
     201    // create instance
     202    ContinuousValue<int> test(*ValidRange);
     203    ContinuousValue<int> instance(*ValidRange);
     204    test.setValue(1);
     205    instance.setValue(1);
     206
     207    // same value, same range
     208    {
     209      CPPUNIT_ASSERT(test == instance);
     210    }
     211
     212    // different value, same range
     213    {
     214      const int oldvalue = instance.getValue();
     215      instance.setValue(2);
     216      CPPUNIT_ASSERT(test != instance);
     217      instance.setValue(oldvalue);
     218    }
     219  }
     220  {
     221    ContinuousValue<int> test(*ValidRange);
     222    range<int> OtherValidRange(1,5);
     223    ContinuousValue<int> instance(OtherValidRange);
     224
     225    test.setValue(1);
     226    instance.setValue(1);
     227
     228    // same value, same range
     229    {
     230      CPPUNIT_ASSERT(test != instance);
     231    }
     232
     233    // different value, same range
     234    {
     235      const int oldvalue = instance.getValue();
     236      instance.setValue(2);
     237      CPPUNIT_ASSERT(test != instance);
     238      instance.setValue(oldvalue);
     239    }
     240  }
     241}
  • src/Parser/Parameters/unittests/ContinuousValueUnitTest.hpp

    r84e752 r498ddd  
    2727  CPPUNIT_TEST ( settergetterValueTest );
    2828  CPPUNIT_TEST ( settergetterTest );
     29  CPPUNIT_TEST ( comparatorTest );
    2930  CPPUNIT_TEST_SUITE_END();
    3031
     
    3839  void settergetterValueTest();
    3940  void settergetterTest();
     41  void comparatorTest();
    4042
    4143private:
  • src/Parser/Parameters/unittests/DiscreteValueUnitTest.cpp

    r84e752 r498ddd  
    212212  }
    213213}
     214
     215/** Unit test for comparator.
     216 *
     217 */
     218void DiscreteValueTest::comparatorTest()
     219{
     220  {
     221    // create instance
     222    DiscreteValue<int> test(ValidValues);
     223    DiscreteValue<int> instance(ValidValues);
     224    test.setValue(1);
     225    instance.setValue(1);
     226
     227    // same value, same range
     228    {
     229      CPPUNIT_ASSERT(test == instance);
     230    }
     231
     232    // different value, same range
     233    {
     234      const int oldvalue = instance.getValue();
     235      instance.setValue(2);
     236      CPPUNIT_ASSERT(test != instance);
     237      instance.setValue(oldvalue);
     238    }
     239  }
     240  {
     241    DiscreteValue<int> test(ValidValues);
     242    DiscreteValue<int> instance(ValidValues);
     243    instance.appendValidValue(4);
     244
     245    test.setValue(1);
     246    instance.setValue(1);
     247
     248    // same value, same range
     249    {
     250      CPPUNIT_ASSERT(test != instance);
     251    }
     252
     253    // different value, same range
     254    {
     255      const int oldvalue = instance.getValue();
     256      instance.setValue(2);
     257      CPPUNIT_ASSERT(test != instance);
     258      instance.setValue(oldvalue);
     259    }
     260  }
     261}
  • src/Parser/Parameters/unittests/DiscreteValueUnitTest.hpp

    r84e752 r498ddd  
    2626  CPPUNIT_TEST ( settergetterTest );
    2727  CPPUNIT_TEST ( settergetterValueTest );
     28  CPPUNIT_TEST ( comparatorTest );
    2829  CPPUNIT_TEST_SUITE_END();
    2930
     
    3839  void settergetterTest();
    3940  void settergetterValueTest();
     41  void comparatorTest();
    4042
    4143private:
Note: See TracChangeset for help on using the changeset viewer.