Changeset 047cad for src


Ignore:
Timestamp:
May 31, 2012, 1:25:03 PM (13 years ago)
Author:
Michael Ankele <ankele@…>
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:
9b5eb0
Parents:
30ebdd
git-author:
Michael Ankele <ankele@…> (04/16/12 12:30:32)
git-committer:
Michael Ankele <ankele@…> (05/31/12 13:25:03)
Message:

added string functions to ValueInterface

Location:
src/Parameters
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/ContinuousParameter_impl.hpp

    r30ebdd r047cad  
    6262  ContinuousValue<T>(_ValidRange)
    6363{
    64   setValue(_value);
     64  set(_value);
    6565};
    6666
  • src/Parameters/ContinuousValue.hpp

    r30ebdd r047cad  
    5353  const range<T> & getValidRange() const;
    5454
    55   // internal functions alike to ValueInterface
    56   bool isValidValue(const T &_value) const;
    57   void setValue(const T &_value);
    58   const T &getValue() const;
     55  // string functions for ValueInterface
     56  bool isValidAsString(const std::string _value) const;
     57  const std::string getAsString() const;
     58  void setAsString(const std::string _value);
    5959
    6060private:
  • src/Parameters/ContinuousValue_impl.hpp

    r30ebdd r047cad  
    5858bool ContinuousValue<T>::isValid(const T & _value) const
    5959{
    60   return isValidValue(_value);
     60  bool isBefore = true;
     61  bool isBeyond = true;
     62  // check left boundary
     63  isBefore = !((!ValidRangeSet.first) || (!ValidRange.isBefore(_value)));
     64//  if (isBefore)
     65//    LOG(0, "INFO: " << _value << " is before " << ValidRange.first << ".");
     66  // check right boundary
     67  isBeyond = !((!ValidRangeSet.last) || (!ValidRange.isBeyond(_value)) || (_value == ValidRange.last));
     68//  if (isBeyond)
     69//    LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << ".");
     70  return (!isBefore) && (!isBeyond);
    6171}
    6272
     
    96106void ContinuousValue<T>::set(const T & _value)
    97107{
    98   setValue(_value);
     108  ASSERT(isValid(_value),
     109      "ContinuousValue<T>::setValue() - trying to set invalid value "+toString(_value)+".");
     110  if (!ValueSet)
     111    ValueSet = true;
     112  value = _value;
    99113//  LOG(0, "STATUS: Value is now set to " << value << ".");
    100114}
     
    143157 */
    144158template <class T>
    145 bool ContinuousValue<T>::isValidValue(const T &_value) const
    146 {
    147   bool isBefore = true;
     159bool ContinuousValue<T>::isValidAsString(const std::string _value) const
     160{
     161  /*bool isBefore = true;
    148162  bool isBeyond = true;
    149163  // check left boundary
     
    155169//  if (isBeyond)
    156170//    LOG(0, "INFO: " << _value << " is beyond " << ValidRange.last << ".");
    157   return (!isBefore) && (!isBeyond);
     171  return (!isBefore) && (!isBeyond);*/
     172  return true;
    158173}
    159174
     
    166181 */
    167182template <class T>
    168 void ContinuousValue<T>::setValue(const T &_value)
    169 {
    170   ASSERT(isValidValue(_value),
     183void ContinuousValue<T>::setAsString(const std::string _value)
     184{
     185  /*ASSERT(isValidAsString(_value),
    171186      "ContinuousValue<T>::setValue() - trying to set invalid value "+toString(_value)+".");
    172187  if (!ValueSet)
    173188    ValueSet = true;
    174   value = _value;
     189  value = _value;*/
    175190}
    176191
     
    182197 */
    183198template <class T>
    184 const T &ContinuousValue<T>::getValue() const
     199const std::string ContinuousValue<T>::getAsString() const
    185200{
    186201  ASSERT(ValueSet,
    187202      "ContinuousValue<T>::get() - value has never been set.");
    188   return value;
     203  return toString(value);
    189204}
    190205
  • src/Parameters/DiscreteValue.hpp

    r30ebdd r047cad  
    5252  const std::vector<T> &getValidValues() const;
    5353
    54   // internal getter and setter
    55   bool isValidValue(const T &_value) const;
    56   void setValue(const T &_value);
    57   const T & getValue() const;
     54  // string functions for ValueInterface
     55  bool isValidAsString(const std::string _value) const;
     56  const std::string getAsString() const;
     57  void setAsString(const std::string _value);
    5858  const size_t getIndexOfValue() const { return value; }
    5959
  • src/Parameters/DiscreteValue_impl.hpp

    r30ebdd r047cad  
    5353bool DiscreteValue<T>::isValid(const T & _value) const
    5454{
    55   return isValidValue(_value);
     55  typename ValidRange::const_iterator iter = std::find(ValidValues.begin(), ValidValues.end(), _value);
     56  if (iter != ValidValues.end()) {
     57    //std::cout << "Found " << _value << ":" << *iter << std::endl;
     58    return true;
     59  } else {
     60    //std::cout << "Did not find " << _value << "." << std::endl;
     61    return false;
     62  }
    5663}
    5764
     
    8188{
    8289  ASSERT(ValueSet,
    83       "DiscreteValue<T>::get() - requesting unset value.");
    84   return getValue();
     90      "DiscreteValue<>::get() - value has never been set.");
     91  return ValidValues[value];
    8592}
    8693
     
    9299void DiscreteValue<T>::set(const T & _value)
    93100{
    94   setValue(_value);
     101  const size_t index = findIndexOfValue(_value);
     102  ASSERT(index != (size_t)-1,
     103      "DiscreteValue<>::set() - value "+toString(_value)+" is not valid.");
     104  if (!ValueSet)
     105    ValueSet = true;
     106  value = index;
    95107}
    96108
     
    128140void DiscreteValue<T>::appendValidValue(const T &_value)
    129141{
    130   ASSERT(!isValidValue(_value),
     142  ASSERT(!isValid(_value),
    131143      "DiscreteValue<>::appendValidValue() - value "+toString(_value)+" is already among the valid");
    132144  ValidValues.push_back(_value);
     
    150162 */
    151163template <class T>
    152 void DiscreteValue<T>::setValue(const T &_value)
    153 {
    154   const size_t index = findIndexOfValue(_value);
     164void DiscreteValue<T>::setAsString(const std::string _value)
     165{
     166  /*const size_t index = findIndexOfValue(_value);
    155167  ASSERT(index != (size_t)-1,
    156168      "DiscreteValue<>::set() - value "+toString(_value)+" is not valid.");
    157169  if (!ValueSet)
    158170    ValueSet = true;
    159   value = index;
     171  value = index;*/
    160172}
    161173
     
    167179 */
    168180template <class T>
    169 const T & DiscreteValue<T>::getValue() const
     181const std::string DiscreteValue<T>::getAsString() const
    170182{
    171183  ASSERT(ValueSet,
    172184      "DiscreteValue<>::get() - value has never been set.");
    173   return ValidValues[value];
     185  return toString(ValidValues[value]);
    174186}
    175187
     
    179191 */
    180192template <class T>
    181 bool DiscreteValue<T>::isValidValue(const T &_value) const
    182 {
    183   typename ValidRange::const_iterator iter = std::find(ValidValues.begin(), ValidValues.end(), _value);
     193bool DiscreteValue<T>::isValidAsString(const std::string _value) const
     194{
     195  /*typename ValidRange::const_iterator iter = std::find(ValidValues.begin(), ValidValues.end(), _value);
    184196  if (iter != ValidValues.end()) {
    185197    //std::cout << "Found " << _value << ":" << *iter << std::endl;
     
    188200    //std::cout << "Did not find " << _value << "." << std::endl;
    189201    return false;
    190   }
     202  }*/
     203  return true;
    191204}
    192205
  • src/Parameters/Value.hpp

    r30ebdd r047cad  
    2222
    2323#include "CodePatterns/Range.hpp"
     24#include "CodePatterns/toString.hpp"
    2425
    2526class ValueTest;
     
    4546  void set(const T & _value);
    4647
     48  // string functions for ValueInterface
     49  bool isValidAsString(const std::string _value) const;
     50  const std::string getAsString() const;
     51  void setAsString(const std::string _value);
     52
    4753  // comfortable setter
    4854  void operator=(const T &_value)
     
    5460      { return !((*this)==(_instance)); }
    5561
    56   // setter/getter for valid values
    57   /*void appendValidValue(const T &_value);
    58   const std::vector<T> &getValidValues() const;
    59 
    60   // internal getter and setter
    61   bool isValidValue(const T &_value) const;
    62   void setValue(const T &_value);
    63   const T & getValue() const;
    64   const size_t getIndexOfValue() const { return value; }
    65 
    66 private:
    67   const size_t findIndexOfValue(const T &_value) const;*/
    68 
    6962  const Validator<T> & getValidator() const;
    7063  Validator<T> & getValidator();
    7164
    7265private:
     66  //!> Internal converter from string to internal type
     67  static ConvertTo<T> Converter;
    7368
    7469  //!> whether a value has been set or not
  • src/Parameters/ValueInterface.hpp

    r30ebdd r047cad  
    1414#endif
    1515
     16#include <string>
     17
    1618/** Interface definition for general parameter values.
    1719 *
     
    2325  virtual ~ValueInterface() {};
    2426
     27  // direct functions
    2528  virtual bool isValid(const T & _value) const=0;
    2629  virtual const T & get() const=0;
    2730  virtual void set(const T & _value)=0;
     31
     32  // string functions
     33  virtual bool isValidAsString(const std::string _value) const=0;
     34  virtual const std::string getAsString() const=0;
     35  virtual void setAsString(const std::string _value)=0;
    2836};
    2937
  • src/Parameters/Value_impl.hpp

    r30ebdd r047cad  
    2424#include "Validators/DiscreteValidator.hpp"
    2525#include "Validators/RangeValidator.hpp"
     26
     27// static member
     28template <class T> ConvertTo<T> Value<T>::Converter;
    2629
    2730/** Constructor of class Value.
     
    131134}
    132135
     136
     137
     138/** Checks whether \a _value is a valid value.
     139 * \param _value value to check for validity.
     140 * \return true - \a _value is valid, false - is not
     141 */
     142template <class T>
     143bool Value<T>::isValidAsString(const std::string _value) const
     144{
     145  const T castvalue = Converter(_value);
     146//  LOG(0, "Converted value reads " << castvalue <<".");
     147  return isValid(castvalue);
     148}
     149
     150/** Getter of value, returning string.
     151 *
     152 * @return string value
     153 */
     154template <class T>
     155const std::string Value<T>::getAsString() const
     156{
     157  ASSERT(ValueSet,
     158      "Value<T>::getAsString() - requesting unset value.");
     159  return toString(value);
     160}
     161
     162/** Setter of value for string
     163 *
     164 * @param _value string containing new value
     165 */
     166template <class T>
     167void Value<T>::setAsString(const std::string _value)
     168{
     169  const T castvalue = Converter(_value);
     170//  LOG(0, "Converted value reads " << castvalue <<".");
     171  set(castvalue);
     172//  LOG(0, "STATUS: Value is now set to " << value << ".");
     173}
     174
    133175/** Returns the validator as a const reference.
    134176 *
  • src/Parameters/unittests/ContinuousValueTest.cpp

    r30ebdd r047cad  
    5454 *
    5555 */
    56 void ContinuousValueTest::isValidIntValueTest()
     56void ContinuousValueTest::isValidIntAsStringTest()
    5757{
    5858  // create instance
     
    6060
    6161  // checking valid values
    62   for (int i=1; i<=4;++i)
    63     CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
     62  /*for (int i=1; i<=4;++i)
     63    CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
    6464
    6565  // checking invalid values
    6666  for (int i=-10; i<=0;++i)
    67     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     67    CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
    6868  for (int i=5; i<=0;++i)
    69     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     69    CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));*/
    7070}
    7171
     
    100100    // extending range and checking
    101101    for (int i=5; i<=6;++i)
    102       CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     102      CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
    103103    test.setValidRange(range<int>(1,6));
    104104    for (int i=5; i<=6;++i)
    105       CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
     105      CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
    106106  }
    107107
     
    111111
    112112    // lowering range with set value
    113     test.setValue(4);
     113    test.set(4);
    114114    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    115115#ifndef NDEBUG
     
    132132 *
    133133 */
    134 void ContinuousValueTest::settergetterIntValueTest()
     134void ContinuousValueTest::settergetterIntAsStringTest()
    135135{
    136136  // create instance
     
    140140#ifndef NDEBUG
    141141  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    142   CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
     142  CPPUNIT_ASSERT_THROW(test.getAsString(), Assert::AssertionFailure);
    143143#endif
    144144
    145145  // setting invalid, throws
    146 #ifndef NDEBUG
    147   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    148   CPPUNIT_ASSERT_THROW(test.setValue(5), Assert::AssertionFailure);
    149 #endif
    150 #ifndef NDEBUG
    151   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    152   CPPUNIT_ASSERT_THROW(test.setValue(0), Assert::AssertionFailure);
     146/*#ifndef NDEBUG
     147  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     148  CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), Assert::AssertionFailure);
     149#endif
     150#ifndef NDEBUG
     151  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     152  CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), Assert::AssertionFailure);
    153153#endif
    154154
     
    156156  // checking all valid ones
    157157  for (int i=1; i<=4;++i) {
    158     test.setValue(i);
     158    test.setAsString(toString(i));
    159159    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    160     CPPUNIT_ASSERT_EQUAL(i, test.getValue());
    161   }
     160    CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
     161  }*/
    162162}
    163163
     
    202202    ContinuousValue<int> test(*ValidIntRange);
    203203    ContinuousValue<int> instance(*ValidIntRange);
    204     test.setValue(1);
    205     instance.setValue(1);
     204    test.set(1);
     205    instance.set(1);
    206206
    207207    // same value, same range
     
    212212    // different value, same range
    213213    {
    214       const int oldvalue = instance.getValue();
    215       instance.setValue(2);
    216       CPPUNIT_ASSERT(test != instance);
    217       instance.setValue(oldvalue);
     214      const int oldvalue = instance.get();
     215      instance.set(2);
     216      CPPUNIT_ASSERT(test != instance);
     217      instance.set(oldvalue);
    218218    }
    219219  }
     
    223223    ContinuousValue<int> instance(OtherValidIntRange);
    224224
    225     test.setValue(1);
    226     instance.setValue(1);
     225    test.set(1);
     226    instance.set(1);
    227227
    228228    // same value, same range
     
    233233    // different value, same range
    234234    {
    235       const int oldvalue = instance.getValue();
    236       instance.setValue(2);
    237       CPPUNIT_ASSERT(test != instance);
    238       instance.setValue(oldvalue);
     235      const int oldvalue = instance.get();
     236      instance.set(2);
     237      CPPUNIT_ASSERT(test != instance);
     238      instance.set(oldvalue);
    239239    }
    240240  }
     
    248248 *
    249249 */
    250 void ContinuousValueTest::isValidVectorValueTest()
    251 {
    252   // create instance
    253   ContinuousValue<Vector> test(*ValidVectorRange);
     250void ContinuousValueTest::isValidVectorAsStringTest()
     251{
     252  // create instance
     253  /*ContinuousValue<Vector> test(*ValidVectorRange);
    254254
    255255  // checking valid values
     
    273273  CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(5,20,20)));
    274274  CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,5,20)));
    275   CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));
     275  CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(20,20,5)));*/
    276276}
    277277
     
    318318    // extending range and checking
    319319    for (int i=15; i<=16;++i)
    320       CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(Vector(i,5,5)));
     320      CPPUNIT_ASSERT_EQUAL(false, test.isValid(Vector(i,5,5)));
    321321    test.setValidRange(range<Vector>(Vector(0,1,2),Vector(20,11,12)));
    322322    for (int i=15; i<=16;++i)
    323       CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(Vector(i,5,5)));
     323      CPPUNIT_ASSERT_EQUAL(true, test.isValid(Vector(i,5,5)));
    324324  }
    325325
     
    329329
    330330    // lowering range with set value
    331     test.setValue(Vector(4,4,4));
     331    test.set(Vector(4,4,4));
    332332    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    333333#ifndef NDEBUG
     
    350350 *
    351351 */
    352 void ContinuousValueTest::settergetterVectorValueTest()
    353 {
    354   // create instance
    355   ContinuousValue<Vector> test(*ValidVectorRange);
     352void ContinuousValueTest::settergetterVectorAsStringTest()
     353{
     354  // create instance
     355  /*ContinuousValue<Vector> test(*ValidVectorRange);
    356356
    357357  // unset calling of get, throws
     
    378378    CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    379379    CPPUNIT_ASSERT_EQUAL(v, test.getValue());
    380   }
     380  }*/
    381381}
    382382
     
    424424    ContinuousValue<Vector> test(*ValidVectorRange);
    425425    ContinuousValue<Vector> instance(*ValidVectorRange);
    426     test.setValue(Vector(5,6,7));
    427     instance.setValue(Vector(5,6,7));
     426    test.set(Vector(5,6,7));
     427    instance.set(Vector(5,6,7));
    428428
    429429    // same value, same range
     
    434434    // different value, same range
    435435    {
    436       const Vector oldvalue = instance.getValue();
    437       instance.setValue(Vector(2,3,4));
    438       CPPUNIT_ASSERT(test != instance);
    439       instance.setValue(oldvalue);
     436      const Vector oldvalue = instance.get();
     437      instance.set(Vector(2,3,4));
     438      CPPUNIT_ASSERT(test != instance);
     439      instance.set(oldvalue);
    440440    }
    441441  }
     
    445445    ContinuousValue<Vector> instance(OtherValidVectorRange);
    446446
    447     test.setValue(Vector(1,2,3));
    448     instance.setValue(Vector(1,2,3));
     447    test.set(Vector(1,2,3));
     448    instance.set(Vector(1,2,3));
    449449
    450450    // same value, same range
     
    455455    // different value, same range
    456456    {
    457       const Vector oldvalue = instance.getValue();
    458       instance.setValue(Vector(2,3,4));
    459       CPPUNIT_ASSERT(test != instance);
    460       instance.setValue(oldvalue);
    461     }
    462   }
    463 }
     457      const Vector oldvalue = instance.get();
     458      instance.set(Vector(2,3,4));
     459      CPPUNIT_ASSERT(test != instance);
     460      instance.set(oldvalue);
     461    }
     462  }
     463}
  • src/Parameters/unittests/ContinuousValueTest.hpp

    r30ebdd r047cad  
    2525{
    2626  CPPUNIT_TEST_SUITE( ContinuousValueTest ) ;
    27   CPPUNIT_TEST ( isValidIntValueTest );
     27  CPPUNIT_TEST ( isValidIntAsStringTest );
    2828  CPPUNIT_TEST ( isValidIntTest );
    2929  CPPUNIT_TEST ( setgetValidIntRangeTest );
    30   CPPUNIT_TEST ( settergetterIntValueTest );
     30  CPPUNIT_TEST ( settergetterIntAsStringTest );
    3131  CPPUNIT_TEST ( settergetterIntTest );
    3232  CPPUNIT_TEST ( comparatorIntTest );
    33   CPPUNIT_TEST ( isValidVectorValueTest );
     33  CPPUNIT_TEST ( isValidVectorAsStringTest );
    3434  CPPUNIT_TEST ( isValidVectorTest );
    3535  CPPUNIT_TEST ( setgetValidVectorRangeTest );
    36   CPPUNIT_TEST ( settergetterVectorValueTest );
     36  CPPUNIT_TEST ( settergetterVectorAsStringTest );
    3737  CPPUNIT_TEST ( settergetterVectorTest );
    3838  CPPUNIT_TEST ( comparatorVectorTest );
     
    4343  void tearDown();
    4444
    45   void isValidIntValueTest();
     45  void isValidIntAsStringTest();
    4646  void isValidIntTest();
    4747  void setgetValidIntRangeTest();
    48   void settergetterIntValueTest();
     48  void settergetterIntAsStringTest();
    4949  void settergetterIntTest();
    5050  void comparatorIntTest();
    5151
    52   void isValidVectorValueTest();
     52  void isValidVectorAsStringTest();
    5353  void isValidVectorTest();
    5454  void setgetValidVectorRangeTest();
    55   void settergetterVectorValueTest();
     55  void settergetterVectorAsStringTest();
    5656  void settergetterVectorTest();
    5757  void comparatorVectorTest();
  • src/Parameters/unittests/DiscreteValueTest.cpp

    r30ebdd r047cad  
    7676 *
    7777 */
    78 void DiscreteValueTest::isValidValueTest()
     78void DiscreteValueTest::isValidAsStringTest()
    7979{
    8080  // create instance
     
    8282
    8383  // checking valid values
    84   for (int i=1; i<=3;++i)
    85     CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
    86 
    87   // checking invalid values
    88   for (int i=-10; i<=0;++i)
    89     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     84  /*for (int i=1; i<=3;++i)
     85    CPPUNIT_ASSERT_EQUAL(true, test.isValidAsString(toString(i)));
     86
     87  // checking invalid values
     88  for (int i=-10; i<=0;++i)
     89    CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));
    9090  for (int i=4; i<=0;++i)
    91     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     91    CPPUNIT_ASSERT_EQUAL(false, test.isValidAsString(toString(i)));*/
    9292}
    9393
     
    121121  // adding values 4,5,6
    122122  for (int i=4; i<=6;++i) {
    123     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     123    CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
    124124    test.appendValidValue(i);
    125     CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
     125    CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
    126126  }
    127127
     
    137137  // checking valid values
    138138  for (int i=1; i<=6;++i)
    139     CPPUNIT_ASSERT_EQUAL(true, test.isValidValue(i));
    140 
    141   // checking invalid values
    142   for (int i=-10; i<=0;++i)
    143     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     139    CPPUNIT_ASSERT_EQUAL(true, test.isValid(i));
     140
     141  // checking invalid values
     142  for (int i=-10; i<=0;++i)
     143    CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
    144144
    145145  // checking invalid values
    146146  for (int i=7; i<=10;++i)
    147     CPPUNIT_ASSERT_EQUAL(false, test.isValidValue(i));
     147    CPPUNIT_ASSERT_EQUAL(false, test.isValid(i));
    148148}
    149149
     
    183183 *
    184184 */
    185 void DiscreteValueTest::settergetterValueTest()
     185void DiscreteValueTest::settergetterAsStringTest()
    186186{
    187187  // create instance
     
    191191#ifndef NDEBUG
    192192  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    193   CPPUNIT_ASSERT_THROW(test.getValue(), Assert::AssertionFailure);
     193  CPPUNIT_ASSERT_THROW(test.getAsString(), Assert::AssertionFailure);
    194194#endif
    195195
    196196  // setting invalid, throws
    197 #ifndef NDEBUG
    198   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    199   CPPUNIT_ASSERT_THROW(test.setValue(4), Assert::AssertionFailure);
    200 #endif
    201 #ifndef NDEBUG
    202   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    203   CPPUNIT_ASSERT_THROW(test.setValue(0), Assert::AssertionFailure);
     197/*#ifndef NDEBUG
     198  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     199  CPPUNIT_ASSERT_THROW(test.setAsString(toString(4)), Assert::AssertionFailure);
     200#endif
     201#ifndef NDEBUG
     202  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     203  CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), Assert::AssertionFailure);
    204204#endif
    205205
    206206  // checking all valid ones
    207207  for (int i=1; i<=3;++i) {
    208     test.setValue(i);
    209     CPPUNIT_ASSERT_EQUAL(i, test.getValue());
    210   }
     208    test.setAsString(toString(i));
     209    CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
     210  }*/
    211211}
    212212
     
    220220    DiscreteValue<int> test(ValidValues);
    221221    DiscreteValue<int> instance(ValidValues);
    222     test.setValue(1);
    223     instance.setValue(1);
     222    test.set(1);
     223    instance.set(1);
    224224
    225225    // same value, same range
     
    230230    // different value, same range
    231231    {
    232       const int oldvalue = instance.getValue();
    233       instance.setValue(2);
     232      const int oldvalue = instance.get();
     233      instance.set(2);
    234234      CPPUNIT_ASSERT(test != instance);
    235       instance.setValue(oldvalue);
     235      instance.set(oldvalue);
    236236    }
    237237  }
     
    241241    instance.appendValidValue(4);
    242242
    243     test.setValue(1);
    244     instance.setValue(1);
     243    test.set(1);
     244    instance.set(1);
    245245
    246246    // same value, same range
     
    251251    // different value, same range
    252252    {
    253       const int oldvalue = instance.getValue();
    254       instance.setValue(2);
     253      const int oldvalue = instance.get();
     254      instance.set(2);
    255255      CPPUNIT_ASSERT(test != instance);
    256       instance.setValue(oldvalue);
    257     }
    258   }
    259 }
     256      instance.set(oldvalue);
     257    }
     258  }
     259}
  • src/Parameters/unittests/DiscreteValueTest.hpp

    r30ebdd r047cad  
    2121  CPPUNIT_TEST_SUITE( DiscreteValueTest ) ;
    2222  CPPUNIT_TEST ( findIndexOfValueTest );
    23   CPPUNIT_TEST ( isValidValueTest );
     23  CPPUNIT_TEST ( isValidAsStringTest );
    2424  CPPUNIT_TEST ( isValidTest );
    2525  CPPUNIT_TEST ( appendValidValueTest );
    2626  CPPUNIT_TEST ( settergetterTest );
    27   CPPUNIT_TEST ( settergetterValueTest );
     27  CPPUNIT_TEST ( settergetterAsStringTest );
    2828  CPPUNIT_TEST ( comparatorTest );
    2929  CPPUNIT_TEST_SUITE_END();
     
    3434
    3535  void findIndexOfValueTest();
    36   void isValidValueTest();
     36  void isValidAsStringTest();
    3737  void isValidTest();
    3838  void appendValidValueTest();
    3939  void settergetterTest();
    40   void settergetterValueTest();
     40  void settergetterAsStringTest();
    4141  void comparatorTest();
    4242
Note: See TracChangeset for help on using the changeset viewer.