Index: Ringtoets/Common/src/Ringtoets.Common.Util/FailureMechanismNormHelper.cs =================================================================== diff -u -r4b64623cd95f3917397dbb4add6c34da61c25cf4 -r18fa622cceab5b9575dbf4b6bffd0825100d7416 --- Ringtoets/Common/src/Ringtoets.Common.Util/FailureMechanismNormHelper.cs (.../FailureMechanismNormHelper.cs) (revision 4b64623cd95f3917397dbb4add6c34da61c25cf4) +++ Ringtoets/Common/src/Ringtoets.Common.Util/FailureMechanismNormHelper.cs (.../FailureMechanismNormHelper.cs) (revision 18fa622cceab5b9575dbf4b6bffd0825100d7416) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using Core.Common.Base.Data; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssemblyTool; using Ringtoets.Common.Data.AssessmentSection; @@ -35,6 +36,8 @@ /// public static class FailureMechanismNormHelper { + private static readonly Range contributionValidityRange = new Range(0, 100); + /// /// Gets the norm based on . /// @@ -48,6 +51,13 @@ /// is an invalid . /// Thrown when /// is a valid but unsupported . + /// + /// Thrown when: + /// + /// is not in the interval [0.0, 100.0] or is ; + /// is not larger than 1 or is . + /// + /// public static double GetNorm(IAssessmentSection assessmentSection, FailureMechanismCategoryType categoryType, double failureMechanismContribution, @@ -58,12 +68,7 @@ throw new ArgumentNullException(nameof(assessmentSection)); } - if (!Enum.IsDefined(typeof(FailureMechanismCategoryType), categoryType)) - { - throw new InvalidEnumArgumentException(nameof(categoryType), - (int) categoryType, - typeof(FailureMechanismCategoryType)); - } + ValidateInput(categoryType, failureMechanismContribution, n); IEnumerable categories = AssemblyToolCategoriesFactory.CreateFailureMechanismSectionAssemblyCategories( assessmentSection.FailureMechanismContribution.SignalingNorm, @@ -92,5 +97,31 @@ throw new NotSupportedException(); } } + + private static void ValidateInput(FailureMechanismCategoryType categoryType, double failureMechanismContribution, double n) + { + if (!Enum.IsDefined(typeof(FailureMechanismCategoryType), categoryType)) + { + throw new InvalidEnumArgumentException(nameof(categoryType), + (int)categoryType, + typeof(FailureMechanismCategoryType)); + } + + ValidateNumericInput(failureMechanismContribution, n); + } + + private static void ValidateNumericInput(double failureMechanismContribution, double n) + { + if (!contributionValidityRange.InRange(failureMechanismContribution)) + { + throw new ArgumentOutOfRangeException(nameof(failureMechanismContribution), + $@"The value for '{nameof(failureMechanismContribution)}' must be in the range of [0.0, 100.0]."); + } + + if (double.IsNaN(n) || n < 1.0) + { + throw new ArgumentOutOfRangeException(nameof(n), $@"The value for '{nameof(n)}' must be larger than 1.0."); + } + } } } \ No newline at end of file