Index: Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs =================================================================== diff -u -rab0d105b9a42cd88f3d112314e2d079755bfd91b -r7e53c08e25e9a9a730326f624be98008ddafbb7b --- Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ab0d105b9a42cd88f3d112314e2d079755bfd91b) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 7e53c08e25e9a9a730326f624be98008ddafbb7b) @@ -244,16 +244,36 @@ } /// - /// Looks up a localized string similar to De N-waarde van dit toetsspoor is nul. Daardoor is de doorsnede-eis onbepaald en kan de berekening niet worden uitgevoerd.. + /// Looks up a localized string similar to De bijdrage van dit toetsspoor moet in het bereik [0, 1] liggen.. /// - public static string RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_is_zero { + public static string RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Contribution_must_be_in_interval_0_100 { get { - return ResourceManager.GetString("RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_is_zer" + - "o", resourceCulture); + return ResourceManager.GetString("RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Contribu" + + "tion_must_be_in_interval_0_100", resourceCulture); } } /// + /// Looks up a localized string similar to De N-waarde van dit toetsspoor moet groter zijn dan 0.. + /// + public static string RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_must_be_larger_than_0 { + get { + return ResourceManager.GetString("RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_must_b" + + "e_larger_than_0", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De norm moet in het bereik [0, 1] liggen.. + /// + public static string RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Norm_must_be_in_interval_0_1 { + get { + return ResourceManager.GetString("RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Norm_mus" + + "t_be_in_interval_0_1", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Er is geen kunstwerk geselecteerd.. /// public static string StructuresCalculationService_ValidateInput_No_Structure_selected { Index: Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx =================================================================== diff -u -rab0d105b9a42cd88f3d112314e2d079755bfd91b -r7e53c08e25e9a9a730326f624be98008ddafbb7b --- Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx (.../Resources.resx) (revision ab0d105b9a42cd88f3d112314e2d079755bfd91b) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Properties/Resources.resx (.../Resources.resx) (revision 7e53c08e25e9a9a730326f624be98008ddafbb7b) @@ -197,7 +197,13 @@ Er is geen hydraulische randvoorwaardendatabase geïmporteerd. - - De N-waarde van dit toetsspoor is nul. Daardoor is de doorsnede-eis onbepaald en kan de berekening niet worden uitgevoerd. + + De norm moet in het bereik [0, 1] liggen. + + De bijdrage van dit toetsspoor moet in het bereik [0, 100] liggen. + + + De N-waarde van dit toetsspoor moet groter zijn dan 0. + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataCalculationService.cs =================================================================== diff -u -rab0d105b9a42cd88f3d112314e2d079755bfd91b -r7e53c08e25e9a9a730326f624be98008ddafbb7b --- Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataCalculationService.cs (.../RingtoetsCommonDataCalculationService.cs) (revision ab0d105b9a42cd88f3d112314e2d079755bfd91b) +++ Ringtoets/Common/src/Ringtoets.Common.Service/RingtoetsCommonDataCalculationService.cs (.../RingtoetsCommonDataCalculationService.cs) (revision 7e53c08e25e9a9a730326f624be98008ddafbb7b) @@ -52,14 +52,31 @@ /// The failure mechanism contribution. /// The 'N' parameter used to factor in the 'length effect'. /// The profile specific required probability. - /// Thrown when is 0. + /// + /// Thrown when: + /// + /// is not in the interval [0.0, 1.0] or is ; + /// is not in the interval [0.0, 100.0] or is ; + /// is not larger than 0. + /// + /// public static double ProfileSpecificRequiredProbability(double norm, double failureMechanismContribution, int n) { - if (n == 0) + if (double.IsNaN(norm) || norm < 0.0 || norm > 1.0) { - throw new ArgumentOutOfRangeException(nameof(n), n, Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_is_zero); + throw new ArgumentOutOfRangeException(nameof(norm), norm, Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Norm_must_be_in_interval_0_1); } + if (double.IsNaN(failureMechanismContribution) || failureMechanismContribution < 0 || failureMechanismContribution > 100) + { + throw new ArgumentOutOfRangeException(nameof(failureMechanismContribution), failureMechanismContribution, Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Contribution_must_be_in_interval_0_100); + } + + if (n <= 0) + { + throw new ArgumentOutOfRangeException(nameof(n), n, Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_must_be_larger_than_0); + } + return norm*(failureMechanismContribution/100)/n; } } Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataCalculationServiceTest.cs =================================================================== diff -u -rab0d105b9a42cd88f3d112314e2d079755bfd91b -r7e53c08e25e9a9a730326f624be98008ddafbb7b --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataCalculationServiceTest.cs (.../RingtoetsCommonDataCalculationServiceTest.cs) (revision ab0d105b9a42cd88f3d112314e2d079755bfd91b) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/RingtoetsCommonDataCalculationServiceTest.cs (.../RingtoetsCommonDataCalculationServiceTest.cs) (revision 7e53c08e25e9a9a730326f624be98008ddafbb7b) @@ -59,37 +59,70 @@ } [Test] - [TestCase(0, 0)] - [TestCase(10, 0.00025)] - public void ProfileSpecificRequiredProbability_WithValidParameters_ReturnSpecificProbability(double contribution, double expectedProfileSpecificRequiredProbability) + public void ProfileSpecificRequiredProbability_WithValidParameters_ReturnSpecificProbability( + [Values(1, 0.5, 0)] double norm, + [Values(100, 50, 0)] double failureMechanismContribution, + [Values(10, 1)] int n) { + // Call + double probability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); + + // Assert + double expectedProfileSpecificRequiredProbability = norm * (failureMechanismContribution / 100) / n; + Assert.AreEqual(expectedProfileSpecificRequiredProbability, probability); + } + + [Test] + public void ProfileSpecificRequiredProbability_WithInvalidNorm_ThrowsArgumentException([Values(150, 1 + 1e-6, -1e-6, -150, double.NaN)] double norm) + { // Setup - const double norm = 1.0/200; - const int n = 2; + const double failureMechanismContribution = 50; + int n = 10; // Call - double probability = RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, contribution, n); + TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); + // Asserty + ArgumentOutOfRangeException exception = Assert.Throws(action); + Assert.AreEqual(norm, exception.ActualValue); + Assert.AreEqual("norm", exception.ParamName); + StringAssert.StartsWith("De norm moet in het bereik [0, 1] liggen." + + Environment.NewLine, exception.Message); + } + + [Test] + public void ProfileSpecificRequiredProbability_WithInvalidFailureMechanismContribution_ThrowsArgumentException([Values(150, 100 + 1e-6, -1e-6, -150, double.NaN)] double failureMechanismContribution) + { + // Setup + const double norm = 0.5; + int n = 10; + + // Call + TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); + // Assert - Assert.AreEqual(expectedProfileSpecificRequiredProbability, probability); + ArgumentOutOfRangeException exception = Assert.Throws(action); + Assert.AreEqual(failureMechanismContribution, exception.ActualValue); + Assert.AreEqual("failureMechanismContribution", exception.ParamName); + StringAssert.StartsWith("De bijdrage van dit toetsspoor moet in het bereik [0, 100] liggen." + + Environment.NewLine, exception.Message); } [Test] - public void ProfileSpecificRequiredProbability_WithZeroN_ThrowsArgumentException() + public void ProfileSpecificRequiredProbability_WithInvalidN_ThrowsArgumentException([Values(0, -1)] int n) { // Setup - const double norm = 1.0/200; - const double contribution = 10; - const int n = 0; + const double norm = 0.5; + const double failureMechanismContribution = 50; // Call - TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, contribution, n); + TestDelegate action = () => RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability(norm, failureMechanismContribution, n); // Assert ArgumentOutOfRangeException exception = Assert.Throws(action); Assert.AreEqual(n, exception.ActualValue); Assert.AreEqual("n", exception.ParamName); - StringAssert.StartsWith("De N-waarde van dit toetsspoor is nul. Daardoor is de doorsnede-eis onbepaald en kan de berekening niet worden uitgevoerd." + + StringAssert.StartsWith("De N-waarde van dit toetsspoor moet groter zijn dan 0." + Environment.NewLine, exception.Message); } }