Index: Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.Designer.cs
===================================================================
diff -u -r106eeb3a0608bd85eb1fcc8fff72256fd9c3ac5f -r87a1bea2bd70c4f66957ae4b961e23f2756014ce
--- Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 106eeb3a0608bd85eb1fcc8fff72256fd9c3ac5f)
+++ Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 87a1bea2bd70c4f66957ae4b961e23f2756014ce)
@@ -362,6 +362,15 @@
}
///
+ /// Looks up a localized string similar to De waarde moet binnen het bereik [0% en 100%] liggen..
+ ///
+ public static string Contribution_must_be_within_Range_0_and_100 {
+ get {
+ return ResourceManager.GetString("Contribution_must_be_within_Range_0_and_100", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to De waarde voor de toegestane bijdrage aan de faalkans moet in het bereik {0} liggen..
///
public static string Contribution_Value_should_be_in_Range_0_ {
Index: Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.resx
===================================================================
diff -u -r397feab39b3bd3a7611c76529ade220c50aaec0d -r87a1bea2bd70c4f66957ae4b961e23f2756014ce
--- Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision 397feab39b3bd3a7611c76529ade220c50aaec0d)
+++ Riskeer/Common/src/Riskeer.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision 87a1bea2bd70c4f66957ae4b961e23f2756014ce)
@@ -420,4 +420,7 @@
Voor een of meerdere vakken kan geen resultaat worden bepaald.
+
+ De waarde moet binnen het bereik [0% en 100%] liggen.
+
\ No newline at end of file
Index: Riskeer/Piping/src/Riskeer.Piping.Data/SemiProbabilistic/SemiProbabilisticPipingCalculationScenario.cs
===================================================================
diff -u -re2b60a183f95fefe71686ac319c22bb7ad644bca -r87a1bea2bd70c4f66957ae4b961e23f2756014ce
--- Riskeer/Piping/src/Riskeer.Piping.Data/SemiProbabilistic/SemiProbabilisticPipingCalculationScenario.cs (.../SemiProbabilisticPipingCalculationScenario.cs) (revision e2b60a183f95fefe71686ac319c22bb7ad644bca)
+++ Riskeer/Piping/src/Riskeer.Piping.Data/SemiProbabilistic/SemiProbabilisticPipingCalculationScenario.cs (.../SemiProbabilisticPipingCalculationScenario.cs) (revision 87a1bea2bd70c4f66957ae4b961e23f2756014ce)
@@ -19,7 +19,9 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
+using System;
using Core.Common.Base.Data;
+using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources;
namespace Riskeer.Piping.Data.SemiProbabilistic
{
@@ -28,6 +30,9 @@
///
public class SemiProbabilisticPipingCalculationScenario : SemiProbabilisticPipingCalculation, IPipingCalculationScenario
{
+ private const int contributionNumberOfDecimalPlaces = 4;
+ private static readonly Range contributionValidityRange = new Range(new RoundedDouble(contributionNumberOfDecimalPlaces),
+ new RoundedDouble(contributionNumberOfDecimalPlaces, 1.0));
private RoundedDouble contribution;
///
@@ -44,7 +49,17 @@
public RoundedDouble Contribution
{
get => contribution;
- set => contribution = value.ToPrecision(contribution.NumberOfDecimalPlaces);
+ set
+ {
+ RoundedDouble newValue = value.ToPrecision(contributionNumberOfDecimalPlaces);
+
+ if (!contributionValidityRange.InRange(newValue))
+ {
+ throw new ArgumentOutOfRangeException(null, string.Format(RiskeerCommonDataResources.Contribution_must_be_within_Range_0_and_100));
+ }
+
+ contribution = newValue;
+ }
}
}
}
\ No newline at end of file
Index: Riskeer/Piping/test/Riskeer.Piping.Data.Test/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioTest.cs
===================================================================
diff -u -r4f10f77136d509ab74d4ffa22cd4d6bfc3bea60c -r87a1bea2bd70c4f66957ae4b961e23f2756014ce
--- Riskeer/Piping/test/Riskeer.Piping.Data.Test/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioTest.cs (.../SemiProbabilisticPipingCalculationScenarioTest.cs) (revision 4f10f77136d509ab74d4ffa22cd4d6bfc3bea60c)
+++ Riskeer/Piping/test/Riskeer.Piping.Data.Test/SemiProbabilistic/SemiProbabilisticPipingCalculationScenarioTest.cs (.../SemiProbabilisticPipingCalculationScenarioTest.cs) (revision 87a1bea2bd70c4f66957ae4b961e23f2756014ce)
@@ -49,20 +49,43 @@
}
[Test]
- public void Contribution_Always_ReturnsSetValue()
+ [SetCulture("nl-NL")]
+ [TestCase(double.NaN)]
+ [TestCase(double.PositiveInfinity)]
+ [TestCase(double.NegativeInfinity)]
+ [TestCase(-0.1)]
+ [TestCase(1.0001)]
+ [TestCase(1.1)]
+ public void WaterVolumetricWeight_SetInvalidValue_ThrowArgumentException(double newValue)
{
// Setup
- var random = new Random(21);
- RoundedDouble contribution = random.NextRoundedDouble();
+ var calculationScenario = new SemiProbabilisticPipingCalculationScenario();
- var scenario = new SemiProbabilisticPipingCalculationScenario();
+ // Call
+ void Call() => calculationScenario.Contribution = (RoundedDouble) newValue;
+ // Assert
+ TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, "De waarde moet binnen het bereik [0% en 100%] liggen.");
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCase(0.0)]
+ [TestCase(0.00001)]
+ [TestCase(0.0001)]
+ [TestCase(1.0)]
+ [TestCase(1.00001)]
+ public void WaterVolumetricWeight_SetValidValue_ValueSetAndSandParticlesVolumicWeightUpdated(double newValue)
+ {
+ // Setup
+ var calculationScenario = new SemiProbabilisticPipingCalculationScenario();
+
// Call
- scenario.Contribution = contribution;
+ calculationScenario.Contribution = (RoundedDouble) newValue;
// Assert
- Assert.AreEqual(4, scenario.Contribution.NumberOfDecimalPlaces);
- Assert.AreEqual(contribution, scenario.Contribution, scenario.Contribution.GetAccuracy());
+ Assert.AreEqual(4, calculationScenario.Contribution.NumberOfDecimalPlaces);
+ Assert.AreEqual(newValue, calculationScenario.Contribution, calculationScenario.Contribution.GetAccuracy());
}
[Test]