Ignore:
Timestamp:
May 20, 2014, 8:47:03 AM (11 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:
cc6e5c
Parents:
c09f94
git-author:
Frederik Heber <heber@…> (08/28/13 23:05:38)
git-committer:
Frederik Heber <heber@…> (05/20/14 08:47:03)
Message:

Allow setting of invalid values in Value class, Action::performCall() catches ParameterExceptions.

Value changes:

  • Values are now checked with get().
  • having the Actions fill their parameters on instantiation may lead to invalid values because actions that, e.g. add an atom and thereby make a so far invalid atomic id now valid, still have to get executed.
  • hence, we allow setting of invalid values. Validity is check/enforced on get(), i.e. when the Action is actually performed and not before. This is also the very moment where the parameters are first required to be valid.
  • Parameter::clone() and copy cstor must not use get() as invalid values are there still allowed.
  • TESTFIX: Value behavior changed.
  • TESTFIX: regression test add atom outside boundary is working again.
  • TESTFIX: regression tests load/store-session would be skipped as loading non-present file fails now. We use --help --actionname instead.

Action changes:

  • are turned into Action::failure.
  • ActionQueue calling an Action wrapped in try/catch-block for ActionFailure.
  • removed try/catch in doUI().
  • as exception (will) occur in ActionQueue's queue_thread, we need to catch it there. As the only thing we do is set the exit flag of the World. We can do this in ActionQueue as well.
Location:
src/Parameters/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parameters/unittests/ContinuousValueTest.cpp

    rc09f94 r0d4168  
    145145void ContinuousValueTest::settergetterIntAsStringTest()
    146146{
     147  // unset calling of get, throws ParameterValueException
     148  {
     149    Value<int> test(*ValidIntRange);
     150    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     151    CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
     152  }
     153
     154  // setting invalid and getting it, throws ParameterValueException
     155  {
     156    Value<int> test(*ValidIntRange);
     157    test.setAsString(toString(5));
     158    CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
     159    test.setAsString(toString(0));
     160    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     161    CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
     162  }
     163
     164  // checking all valid ones
     165  {
     166    Value<int> test(*ValidIntRange);
     167    CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     168    for (int i=1; i<=4;++i) {
     169      test.setAsString(toString(i));
     170      CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
     171      CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
     172    }
     173  }
     174}
     175
     176/** Unit test for setters and getters.
     177 *
     178 */
     179void ContinuousValueTest::settergetterIntTest()
     180{
    147181  // create instance
    148182  Value<int> test(*ValidIntRange);
     
    150184  // unset calling of get, throws ParameterValueException
    151185  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    152   CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
    153 
    154   // setting invalid, throws ParameterValueException
    155   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    156   CPPUNIT_ASSERT_THROW(test.setAsString(toString(5)), ParameterValueException);
    157   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    158   CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
    159 
    160   CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
    161   // checking all valid ones
    162   for (int i=1; i<=4;++i) {
    163     test.setAsString(toString(i));
    164     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    165     CPPUNIT_ASSERT_EQUAL(toString(i), test.getAsString());
    166   }
    167 }
    168 
    169 /** Unit test for setters and getters.
    170  *
    171  */
    172 void ContinuousValueTest::settergetterIntTest()
    173 {
    174   // create instance
    175   Value<int> test(*ValidIntRange);
    176 
    177   // unset calling of get, throws ParameterValueException
    178   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    179186  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
    180187
    181   // setting invalid, throws ParameterValueException
    182   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    183   CPPUNIT_ASSERT_THROW(test.set(5), ParameterValueException);
    184   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    185   CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
     188  // setting invalid and getting it, throws ParameterValueException
     189  test.set(5);
     190  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     191  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
     192  test.set(0);
     193  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     194  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
    186195
    187196  // checking all valid ones
     
    381390void ContinuousValueTest::settergetterVectorTest()
    382391{
    383   // create instance
    384   Value<Vector> test(*ValidVectorRange);
    385 
    386392  // unset calling of get, throws
    387   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    388   CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
    389 
    390   // setting invalid, throws
    391   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    392   CPPUNIT_ASSERT_THROW(test.set(Vector(5,0,0)), ParameterValueException);
    393   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    394   CPPUNIT_ASSERT_THROW(test.set(Vector(5,20,5)), ParameterValueException);
    395 
    396   CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     393  {
     394    Value<Vector> test(*ValidVectorRange);
     395    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     396    CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
     397  }
     398
     399  // setting invalid and getting it, throws
     400  {
     401    Value<Vector> test(*ValidVectorRange);
     402    test.set(Vector(5,0,0));
     403    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     404    CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
     405    test.set(Vector(5,20,5));
     406    std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     407    CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
     408  }
     409
    397410  // checking some valid ones
    398   for (int i=1; i<=4;++i) {
    399     Vector v(i,5,5);
    400     test.set(v);
    401     CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
    402     CPPUNIT_ASSERT_EQUAL(v, test.get());
     411  {
     412    Value<Vector> test(*ValidVectorRange);
     413    CPPUNIT_ASSERT_EQUAL(false, test.ValueSet);
     414    for (int i=1; i<=4;++i) {
     415      Vector v(i,5,5);
     416      test.set(v);
     417      CPPUNIT_ASSERT_EQUAL(true, test.ValueSet);
     418      CPPUNIT_ASSERT_EQUAL(v, test.get());
     419    }
    403420  }
    404421}
  • src/Parameters/unittests/DiscreteValueTest.cpp

    rc09f94 r0d4168  
    174174  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
    175175
    176   // setting invalid, throws
    177   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    178   CPPUNIT_ASSERT_THROW(test.set(4), ParameterValueException);
    179   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    180   CPPUNIT_ASSERT_THROW(test.set(0), ParameterValueException);
     176  // setting invalid and getting it, throws
     177  test.set(4);
     178  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     179  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
     180  test.set(0);
     181  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     182  CPPUNIT_ASSERT_THROW(test.get(), ParameterValueException);
    181183
    182184  // checking all valid ones
     
    200202  CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
    201203
    202   // setting invalid, throws
    203   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    204   CPPUNIT_ASSERT_THROW(test.setAsString(toString(4)), ParameterValueException);
    205   std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
    206   CPPUNIT_ASSERT_THROW(test.setAsString(toString(0)), ParameterValueException);
     204  // setting invalid and getting it, throws
     205  test.setAsString(toString(4));
     206  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     207  CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
     208  test.setAsString(toString(0));
     209  std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl;
     210  CPPUNIT_ASSERT_THROW(test.getAsString(), ParameterValueException);
    207211
    208212  // checking all valid ones
Note: See TracChangeset for help on using the changeset viewer.