Index: Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs =================================================================== diff -u -rbeebce4bfdaeb8e8037bfb06c8673d770a6e0d64 -rd585b18f2f4d58d6e64f161a50318116de26fce6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs (.../FailureMechanismContribution.cs) (revision beebce4bfdaeb8e8037bfb06c8673d770a6e0d64) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Contribution/FailureMechanismContribution.cs (.../FailureMechanismContribution.cs) (revision d585b18f2f4d58d6e64f161a50318116de26fce6) @@ -26,7 +26,6 @@ using Core.Common.Base.Data; using Core.Common.Utils.Extensions; using Ringtoets.Common.Data.FailureMechanism; -using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.Contribution @@ -36,13 +35,14 @@ /// public class FailureMechanismContribution : Observable { + private const double defaultNorm = 1.0 / 30000; private static readonly Range normValidityRange = new Range(1.0 / 1000000, 1.0 / 10); - private const double defaultNorm = 1.0 / 30000; - private readonly ICollection distribution = new List(); private readonly OtherFailureMechanism otherFailureMechanism = new OtherFailureMechanism(); private double norm; + private double lowerLimitNorm; + private double signalingNorm; /// /// Creates a new instance of . Values are taken from the @@ -63,8 +63,8 @@ public FailureMechanismContribution(IEnumerable failureMechanisms, double otherContribution) { Norm = defaultNorm; - SignalingNorm = defaultNorm; - LowerLimitNorm = defaultNorm; + signalingNorm = defaultNorm; + lowerLimitNorm = defaultNorm; NormType = NormType.LowerLimit; UpdateContributions(failureMechanisms, otherContribution); @@ -73,13 +73,57 @@ /// /// Gets the signaling norm which has been defined on the assessment section. /// - public double SignalingNorm { get; } + /// Thrown when + /// + /// The new value is not in the interval [0.000001, 0.1] or is ; + /// The new value is larger than the . + /// + public double SignalingNorm + { + get + { + return signalingNorm; + } + set + { + ValidateNorm(value); + if (value > lowerLimitNorm) + { + throw new ArgumentOutOfRangeException(nameof(value), Resources.FailureMechanismContribution_SignalingNorm_should_be_same_or_smaller_than_LowerLimitNorm); + } + + signalingNorm = value; + } + } + /// /// Gets the lower limit norm which has been defined on the assessment section. /// - public double LowerLimitNorm { get; } + /// Thrown when + /// + /// The new value is not in the interval [0.000001, 0.1] or is ; + /// The new value is smaller than the . + /// + public double LowerLimitNorm + { + get + { + return lowerLimitNorm; + } + set + { + ValidateNorm(value); + if (value < signalingNorm) + { + throw new ArgumentOutOfRangeException(nameof(value), Resources.FailureMechanismContribution_SignalingNorm_should_be_same_or_smaller_than_LowerLimitNorm); + } + + lowerLimitNorm = value; + } + } + /// /// Gets or sets the norm which has been defined on the assessment section. /// @@ -93,12 +137,7 @@ } set { - if (!normValidityRange.InRange(value)) - { - string message = string.Format(Resources.Norm_should_be_in_Range_0_, - normValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)); - throw new ArgumentOutOfRangeException(nameof(value), message); - } + ValidateNorm(value); norm = value; distribution.ForEachElementDo(d => d.Norm = norm); @@ -149,6 +188,22 @@ } /// + /// Validates the norm value; + /// + /// The value to validate. + /// Thrown when the new value is not in + /// the interval [0.000001, 0.1] or is . + private static void ValidateNorm(double value) + { + if (!normValidityRange.InRange(value)) + { + string message = string.Format(Resources.Norm_should_be_in_Range_0_, + normValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)); + throw new ArgumentOutOfRangeException(nameof(value), message); + } + } + + /// /// Adds a based on . /// /// The to add a for. Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs =================================================================== diff -u -rbeebce4bfdaeb8e8037bfb06c8673d770a6e0d64 -rd585b18f2f4d58d6e64f161a50318116de26fce6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision beebce4bfdaeb8e8037bfb06c8673d770a6e0d64) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d585b18f2f4d58d6e64f161a50318116de26fce6) @@ -470,6 +470,16 @@ } /// + /// Looks up a localized string similar to De signaleringswaarde moet gelijk of kleiner zijn dan de ondergrens.. + /// + public static string FailureMechanismContribution_SignalingNorm_should_be_same_or_smaller_than_LowerLimitNorm { + get { + return ResourceManager.GetString("FailureMechanismContribution_SignalingNorm_should_be_same_or_smaller_than_LowerLi" + + "mitNorm", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kan geen bijdrageoverzicht maken zonder toetsspoor.. /// public static string FailureMechanismContribution_UpdateContributions_Can_not_create_FailureMechanismContribution_without_FailureMechanism_collection { Index: Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx =================================================================== diff -u -rbeebce4bfdaeb8e8037bfb06c8673d770a6e0d64 -rd585b18f2f4d58d6e64f161a50318116de26fce6 --- Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision beebce4bfdaeb8e8037bfb06c8673d770a6e0d64) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Properties/Resources.resx (.../Resources.resx) (revision d585b18f2f4d58d6e64f161a50318116de26fce6) @@ -375,4 +375,7 @@ De waarde van de norm moet in het bereik {0} liggen. + + De signaleringswaarde moet gelijk of kleiner zijn dan de ondergrens. + \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs =================================================================== diff -u -rbeebce4bfdaeb8e8037bfb06c8673d770a6e0d64 -rd585b18f2f4d58d6e64f161a50318116de26fce6 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs (.../FailureMechanismContributionTest.cs) (revision beebce4bfdaeb8e8037bfb06c8673d770a6e0d64) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Contribution/FailureMechanismContributionTest.cs (.../FailureMechanismContributionTest.cs) (revision d585b18f2f4d58d6e64f161a50318116de26fce6) @@ -314,11 +314,11 @@ } [Test] - [TestCase(double.MaxValue)] - [TestCase(double.MinValue)] - [TestCase(0.1 + 1e-6)] - [TestCase(0.000001 - 1e-6)] - [TestCase(double.NaN)] + [TestCaseSource(nameof(GetInvalidValues), + new object[] + { + "Norm_InvalidNewNorm_ThrowsArgumentOutOfRangeException" + })] [SetCulture("nl-NL")] public void Norm_InvalidNewNorm_ThrowsArgumentOutOfRangeException(double newNorm) { @@ -362,10 +362,100 @@ mocks.VerifyAll(); } + [Test] + [TestCaseSource(nameof(GetInvalidValues), + new object[] + { + "Norm_WhenUpdated_NormUpdatedForEachFailureMechanismContributionItem" + })] + [SetCulture("nl-NL")] + public void LowerLimitNorm_InvalidNewNorm_ThrowsArgumentOutOfRangeException(double newNorm) + { + // Setup + var random = new Random(21); + int contribution = random.Next(1, 100); + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), contribution); + + // Call + TestDelegate test = () => failureMechanismContribution.LowerLimitNorm = newNorm; + + // Assert + const string expectedMessage = "De waarde van de norm moet in het bereik [0,000001, 0,1] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + [TestCaseSource(nameof(GetInvalidValues), + new object[] + { + "SignalingNorm_InvalidNewNorm_ThrowsArgumentOutOfRangeException" + })] + [SetCulture("nl-NL")] + public void SignalingNorm_InvalidNewNorm_ThrowsArgumentOutOfRangeException(double newNorm) + { + // Setup + var random = new Random(21); + int contribution = random.Next(1, 100); + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), contribution); + + // Call + TestDelegate test = () => failureMechanismContribution.SignalingNorm = newNorm; + + // Assert + const string expectedMessage = "De waarde van de norm moet in het bereik [0,000001, 0,1] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void SignalingNorm_SignalingNormBiggerThanLowerLimitNorm_ThrowsArgumentOutOfRangeException() + { + // Setup + var random = new Random(21); + int contribution = random.Next(1, 100); + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), contribution); + + // Call + TestDelegate test = () => failureMechanismContribution.SignalingNorm = 0.1; + + // Assert + const string expectedMessage = "De signaleringswaarde moet gelijk of kleiner zijn dan de ondergrens."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void LowerLimitNorm_SignalingNormBiggerThanLowerLimitNorm_ThrowsArgumentOutOfRangeException() + { + // Setup + var random = new Random(21); + int contribution = random.Next(1, 100); + var failureMechanismContribution = new FailureMechanismContribution(Enumerable.Empty(), contribution); + + // Call + TestDelegate test = () => failureMechanismContribution.LowerLimitNorm = 0.000001; + + // Assert + const string expectedMessage = "De signaleringswaarde moet gelijk of kleiner zijn dan de ondergrens."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + private static void AssertFailureProbabilitySpace(double newOtherContribution, double norm, double probabilitySpace) { double expectedProbabilitySpace = 100.0 / (norm * newOtherContribution); Assert.AreEqual(expectedProbabilitySpace, probabilitySpace); } + + private static IEnumerable GetInvalidValues(string name) + { + yield return new TestCaseData(double.MaxValue) + .SetName($"{name} maxValue"); + yield return new TestCaseData(double.MinValue) + .SetName($"{name} minValue"); + yield return new TestCaseData(double.NaN) + .SetName($"{name} NaN"); + yield return new TestCaseData(0.1 + 1e-6) + .SetName($"{name} minimum boundary"); + yield return new TestCaseData(0.000001 - 1e-6) + .SetName($"{name} maximum boundary"); + } } } \ No newline at end of file