Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresCalculation.cs =================================================================== diff -u -r7d42e59aadbea2c27f2f6eb97640c5d8ecc56e1c -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresCalculation.cs (.../HeightStructuresCalculation.cs) (revision 7d42e59aadbea2c27f2f6eb97640c5d8ecc56e1c) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresCalculation.cs (.../HeightStructuresCalculation.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -86,7 +86,7 @@ private void AddDemoInput() { - InputParameters.LevelOfCrestOfStructure.Mean = (RoundedDouble) 3.5; + InputParameters.LevelOfCrestOfStructure.Mean = (RoundedDouble) 5.74; InputParameters.OrientationOfTheNormalOfTheStructure = (RoundedDouble) 115; InputParameters.AllowableIncreaseOfLevelForStorage.Mean = (RoundedDouble) 1.0; InputParameters.FlowWidthAtBottomProtection.Mean = (RoundedDouble) 18; Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs =================================================================== diff -u -re1157c221217ef3b5ade6034183a7da0e620eb05 -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs (.../HeightStructuresInput.cs) (revision e1157c221217ef3b5ade6034183a7da0e620eb05) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresInput.cs (.../HeightStructuresInput.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -19,10 +19,12 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.HeightStructures.Data.Properties; using Ringtoets.HydraRing.Data; namespace Ringtoets.HeightStructures.Data @@ -41,14 +43,16 @@ private readonly NormalDistribution widthOfFlowApertures; private readonly LogNormalDistribution stormDuration; private RoundedDouble orientationOfTheNormalOfTheStructure; - private RoundedDouble failureProbabilityOfStructureGivenErosion; private RoundedDouble deviationOfTheWaveDirection; + private RoundedDouble failureProbabilityOfStructureGivenErosion; /// /// Creates a new instance of the class. /// public HeightStructuresInput() { + failureProbabilityOfStructureGivenErosion = (RoundedDouble) 1; + levelOfCrestOfStructure = new NormalDistribution(2) { StandardDeviation = (RoundedDouble) 0.05 @@ -86,8 +90,6 @@ }; criticalOvertoppingDischarge.SetStandardDeviationFromVariationCoefficient(0.15); - failureProbabilityOfStructureGivenErosion = new RoundedDouble(2); - widthOfFlowApertures = new NormalDistribution(2) { StandardDeviation = (RoundedDouble) 0.05 @@ -260,6 +262,7 @@ /// /// Gets or sets the failure probability of structure given erosion. /// + /// Thrown when is not in range [0, 1]. public RoundedDouble FailureProbabilityOfStructureGivenErosion { get @@ -268,8 +271,11 @@ } set { - failureProbabilityOfStructureGivenErosion = value.ToPrecision( - failureProbabilityOfStructureGivenErosion.NumberOfDecimalPlaces); + if (value < 0 || value > 1) + { + throw new ArgumentException(Resources.FailureProbabilityOfStructureGivenErosion_Value_needs_to_be_between_0_and_1); + } + failureProbabilityOfStructureGivenErosion = value; } } Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.Designer.cs =================================================================== diff -u -r14de3deecd2cff7f6abe41ed6dc5dc016c4c81e0 -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 14de3deecd2cff7f6abe41ed6dc5dc016c4c81e0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -61,6 +61,15 @@ } /// + /// Looks up a localized string similar to De waarde voor de faalkans moet in het bereik [0, 1] liggen.. + /// + public static string FailureProbabilityOfStructureGivenErosion_Value_needs_to_be_between_0_and_1 { + get { + return ResourceManager.GetString("FailureProbabilityOfStructureGivenErosion_Value_needs_to_be_between_0_and_1", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Nieuwe berekening. /// public static string HeightStructuresCalculation_DefaultName { Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.resx =================================================================== diff -u -r14de3deecd2cff7f6abe41ed6dc5dc016c4c81e0 -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.resx (.../Resources.resx) (revision 14de3deecd2cff7f6abe41ed6dc5dc016c4c81e0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Properties/Resources.resx (.../Resources.resx) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -129,4 +129,7 @@ De waarde voor 'N' moet in interval [1, 20] liggen. + + De waarde voor de faalkans moet in het bereik [0, 1] liggen. + \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r5a36c286d8fba3ece9cf48061c66958a1feaa33e -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 5a36c286d8fba3ece9cf48061c66958a1feaa33e) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -143,6 +143,15 @@ } /// + /// Looks up a localized string similar to De waarde voor de faalkans kon niet geïnterpreteerd worden als een getal.. + /// + public static string FailureProbabilityOfStructureGivenErosion_Could_not_parse_string_to_double_value { + get { + return ResourceManager.GetString("FailureProbabilityOfStructureGivenErosion_Could_not_parse_string_to_double_value", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De faalkans van het kunstwerk gegeven de erosie in de bodem.. /// public static string FailureProbabilityOfStructureGivenErosion_Description { @@ -161,6 +170,24 @@ } /// + /// Looks up a localized string similar to De waarde voor de faalkans moet ingevuld zijn.. + /// + public static string FailureProbabilityOfStructureGivenErosion_Value_cannot_be_null { + get { + return ResourceManager.GetString("FailureProbabilityOfStructureGivenErosion_Value_cannot_be_null", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De waarde voor de faalkans is te groot of te klein.. + /// + public static string FailureProbabilityOfStructureGivenErosion_Value_too_large { + get { + return ResourceManager.GetString("FailureProbabilityOfStructureGivenErosion_Value_too_large", resourceCulture); + } + } + + /// /// Looks up a localized string similar to De stroomvoerende breedte bij bodembescherming die gebruikt wordt tijdens de berekening.. /// public static string FlowWidthAtBottomProtection_Description { @@ -402,7 +429,7 @@ } /// - /// Looks up a localized string similar to Stormduur [uren]. + /// Looks up a localized string similar to Stormduur [uur]. /// public static string StormDuration_DisplayName { get { Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.resx =================================================================== diff -u -r5a36c286d8fba3ece9cf48061c66958a1feaa33e -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.resx (.../Resources.resx) (revision 5a36c286d8fba3ece9cf48061c66958a1feaa33e) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/Properties/Resources.resx (.../Resources.resx) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -230,12 +230,21 @@ De duur van de storm dat gebruikt wordt tijdens de berekening. - Stormduur [uren] + Stormduur [uur] De breedte van de kruin van het kunstwerk die gebruikt wordt tijdens de berekening. Breedte van de kruin van het kunstwerk [m] + + De waarde voor de faalkans kon niet geïnterpreteerd worden als een getal. + + + De waarde voor de faalkans is te groot of te klein. + + + De waarde voor de faalkans moet ingevuld zijn. + \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs =================================================================== diff -u -r5a36c286d8fba3ece9cf48061c66958a1feaa33e -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision 5a36c286d8fba3ece9cf48061c66958a1feaa33e) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Forms/PropertyClasses/HeightStructuresInputContextProperties.cs (.../HeightStructuresInputContextProperties.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; @@ -75,7 +76,7 @@ /// /// Returns the available hydraulic boundary locations in order for the user to select one to - /// set . + /// set . /// The available hydraulic boundary locations. public IEnumerable GetAvailableHydraulicBoundaryLocations() { @@ -84,15 +85,10 @@ private static string ToProbabilityFormat(RoundedDouble probability) { - return string.Format(CoreCommonBasePropertiesResources.ProbabilityPerYearFormat, probability); + var d = (RoundedDouble) (1/probability); + return string.Format(CoreCommonBasePropertiesResources.ProbabilityPerYearFormat, d); } - private static double FromProbabilityFormat(string probabilityFormat) - { - var value = probabilityFormat.Replace("1/", ""); - return double.Parse(value); - } - #region Schematisation [PropertyOrder(orientationOfTheNormalOfTheStructurePropertyIndex)] @@ -220,7 +216,22 @@ } set { - data.WrappedData.FailureProbabilityOfStructureGivenErosion = (RoundedDouble) FromProbabilityFormat(value); + if (value == null) + { + throw new ArgumentNullException("value", Resources.FailureProbabilityOfStructureGivenErosion_Value_cannot_be_null); + } + try + { + data.WrappedData.FailureProbabilityOfStructureGivenErosion = (RoundedDouble) double.Parse(value); + } + catch (OverflowException) + { + throw new ArgumentException(Resources.FailureProbabilityOfStructureGivenErosion_Value_too_large); + } + catch (FormatException) + { + throw new ArgumentException(Resources.FailureProbabilityOfStructureGivenErosion_Could_not_parse_string_to_double_value); + } data.WrappedData.NotifyObservers(); } } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresCalculationTest.cs =================================================================== diff -u -r7d42e59aadbea2c27f2f6eb97640c5d8ecc56e1c -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresCalculationTest.cs (.../HeightStructuresCalculationTest.cs) (revision 7d42e59aadbea2c27f2f6eb97640c5d8ecc56e1c) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresCalculationTest.cs (.../HeightStructuresCalculationTest.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -20,6 +20,7 @@ // All rights reserved. using Core.Common.Base; +using Core.Common.Base.Data; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probability; @@ -138,7 +139,7 @@ private void AssertDemoInput(HeightStructuresInput inputParameters) { Assert.AreEqual(2, inputParameters.LevelOfCrestOfStructure.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(3.5, inputParameters.LevelOfCrestOfStructure.Mean.Value); + Assert.AreEqual(5.74, inputParameters.LevelOfCrestOfStructure.Mean.Value); Assert.AreEqual(2, inputParameters.OrientationOfTheNormalOfTheStructure.NumberOfDecimalPlaces); Assert.AreEqual(115, inputParameters.OrientationOfTheNormalOfTheStructure.Value); Assert.AreEqual(2, inputParameters.AllowableIncreaseOfLevelForStorage.Mean.NumberOfDecimalPlaces); @@ -153,7 +154,7 @@ Assert.AreEqual(18, inputParameters.WidthOfFlowApertures.Mean.Value); Assert.AreEqual(2, inputParameters.DeviationOfTheWaveDirection.NumberOfDecimalPlaces); Assert.AreEqual(0.0, inputParameters.DeviationOfTheWaveDirection.Value); - Assert.AreEqual(2, inputParameters.FailureProbabilityOfStructureGivenErosion.NumberOfDecimalPlaces); + Assert.AreEqual(RoundedDouble.MaximumNumberOfDecimalPlaces, inputParameters.FailureProbabilityOfStructureGivenErosion.NumberOfDecimalPlaces); Assert.AreEqual(1, inputParameters.FailureProbabilityOfStructureGivenErosion.Value); } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs =================================================================== diff -u -r9f9e6d0ed59b60fd6b686989f028fc588df8e4ea -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs (.../HeightStructuresInputTest.cs) (revision 9f9e6d0ed59b60fd6b686989f028fc588df8e4ea) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresInputTest.cs (.../HeightStructuresInputTest.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -22,10 +22,12 @@ using System; using Core.Common.Base; using Core.Common.Base.Data; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data.Properties; using Ringtoets.HydraRing.Data; namespace Ringtoets.HeightStructures.Data.Test @@ -252,22 +254,37 @@ } [Test] - public void Properties_FailureProbabilityOfStructureGivenErosion_ExpectedValues() + [TestCase(0)] + [TestCase(0.5)] + [TestCase(1)] + public void Properties_ValidFailureProbabilityOfStructureGivenErosion_ExpectedValues(double failureProbabilityOfStructureGivenErosion) { // Setup var input = new HeightStructuresInput(); - var random = new Random(22); - RoundedDouble failureProbabilityOfStructureGivenErosion = new RoundedDouble(5, random.NextDouble()); - // Call - input.FailureProbabilityOfStructureGivenErosion = failureProbabilityOfStructureGivenErosion; + input.FailureProbabilityOfStructureGivenErosion = (RoundedDouble)failureProbabilityOfStructureGivenErosion; // Assert AssertAreEqual(failureProbabilityOfStructureGivenErosion, input.FailureProbabilityOfStructureGivenErosion); } [Test] + [TestCase(-0.1)] + [TestCase(1.1)] + public void Properties_InvalidFailureProbabilityOfStructureGivenErosion_ExpectedValues(double failureProbabilityOfStructureGivenErosion) + { + // Setup + var input = new HeightStructuresInput(); + + // Call + TestDelegate call = () => input.FailureProbabilityOfStructureGivenErosion = (RoundedDouble)failureProbabilityOfStructureGivenErosion; + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call,Resources.FailureProbabilityOfStructureGivenErosion_Value_needs_to_be_between_0_and_1); + } + + [Test] public void Properties_WidthOfFlowApertures_ExpectedValues() { // Setup Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs =================================================================== diff -u -r5a36c286d8fba3ece9cf48061c66958a1feaa33e -rb4b7570863a54297e406e5c604b5e7fb64681db4 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision 5a36c286d8fba3ece9cf48061c66958a1feaa33e) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Forms.Test/PropertyClasses/HeightStructuresInputContextPropertiesTest.cs (.../HeightStructuresInputContextPropertiesTest.cs) (revision b4b7570863a54297e406e5c604b5e7fb64681db4) @@ -21,16 +21,19 @@ using System; using System.ComponentModel; +using System.Globalization; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Gui.PropertyBag; +using Core.Common.TestUtil; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; +using Ringtoets.HeightStructures.Forms.Properties; using Ringtoets.HeightStructures.Forms.PropertyClasses; using Ringtoets.HydraRing.Data; using CoreCommonBasePropertiesResources = Core.Common.Base.Properties.Resources; @@ -161,21 +164,96 @@ var random = new Random(100); var newOrientationOfTheNormalOfTheStructure = new RoundedDouble(2, random.NextDouble()); - var newFailureProbabilityOfStructureGivenErosion = "100"; + var newFailureProbabilityOfStructureGivenErosion = 0.01; // Call properties.OrientationOfTheNormalOfTheStructure = newOrientationOfTheNormalOfTheStructure; - properties.FailureProbabilityOfStructureGivenErosion = newFailureProbabilityOfStructureGivenErosion; + properties.FailureProbabilityOfStructureGivenErosion = newFailureProbabilityOfStructureGivenErosion.ToString(CultureInfo.InvariantCulture); properties.HydraulicBoundaryLocation = hydraulicBoundaryLocation; // Assert Assert.AreEqual(newOrientationOfTheNormalOfTheStructure, properties.OrientationOfTheNormalOfTheStructure); - Assert.AreEqual(string.Format("1/{0}", newFailureProbabilityOfStructureGivenErosion), properties.FailureProbabilityOfStructureGivenErosion); + Assert.AreEqual(string.Format("1/{0}", 1/newFailureProbabilityOfStructureGivenErosion), properties.FailureProbabilityOfStructureGivenErosion); Assert.AreSame(hydraulicBoundaryLocation, properties.HydraulicBoundaryLocation); mockRepository.VerifyAll(); } [Test] + [TestCase(double.MaxValue)] + public void SetFailureProbabilityOfStructureGivenErosion_InvalidValues_ThrowsArgumentException(double newValue) + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + var calculationMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var input = new HeightStructuresInput(); + var inputContext = new HeightStructuresInputContext(input, calculationMock, failureMechanism, assessmentSectionMock); + + var properties = new HeightStructuresInputContextProperties + { + Data = inputContext + }; + + // Call + TestDelegate call = () => properties.FailureProbabilityOfStructureGivenErosion = newValue.ToString(CultureInfo.InvariantCulture); + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, Resources.FailureProbabilityOfStructureGivenErosion_Value_too_large); + } + + [Test] + [TestCase("no double value")] + [TestCase("")] + public void SetFailureProbabilityOfStructureGivenErosion_ValuesUnableToParse_ThrowsArgumentException(string newValue) + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + var calculationMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var input = new HeightStructuresInput(); + var inputContext = new HeightStructuresInputContext(input, calculationMock, failureMechanism, assessmentSectionMock); + + var properties = new HeightStructuresInputContextProperties + { + Data = inputContext + }; + + // Call + TestDelegate call = () => properties.FailureProbabilityOfStructureGivenErosion = newValue; + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, Resources.FailureProbabilityOfStructureGivenErosion_Could_not_parse_string_to_double_value); + } + + [Test] + public void SetFailureProbabilityOfStructureGivenErosion_NullValue_ThrowsArgumentException() + { + // Setup + var assessmentSectionMock = mockRepository.StrictMock(); + var calculationMock = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + + var failureMechanism = new HeightStructuresFailureMechanism(); + var input = new HeightStructuresInput(); + var inputContext = new HeightStructuresInputContext(input, calculationMock, failureMechanism, assessmentSectionMock); + + var properties = new HeightStructuresInputContextProperties + { + Data = inputContext + }; + + // Call + TestDelegate call = () => properties.FailureProbabilityOfStructureGivenErosion = null; + + // Assert + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, Resources.FailureProbabilityOfStructureGivenErosion_Value_cannot_be_null); + } + + [Test] public void PropertyAttributes_ReturnExpectedValues() { // Setup @@ -253,7 +331,7 @@ PropertyDescriptor stormDurationProperty = dynamicProperties[stormDurationPropertyIndex]; Assert.AreEqual("Hydraulische gegevens", stormDurationProperty.Category); - Assert.AreEqual("Stormduur [uren]", stormDurationProperty.DisplayName); + Assert.AreEqual("Stormduur [uur]", stormDurationProperty.DisplayName); Assert.AreEqual("De duur van de storm dat gebruikt wordt tijdens de berekening.", stormDurationProperty.Description); mockRepository.VerifyAll();