Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsPreconsolidationStress.cs =================================================================== diff -u -re4e0262d031b09d6ddb2812720cb69bb8f14b564 -red2f1cb6668ebc525c0d537db0e68db8f2bc65bc --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsPreconsolidationStress.cs (.../MacroStabilityInwardsPreconsolidationStress.cs) (revision e4e0262d031b09d6ddb2812720cb69bb8f14b564) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/MacroStabilityInwardsPreconsolidationStress.cs (.../MacroStabilityInwardsPreconsolidationStress.cs) (revision ed2f1cb6668ebc525c0d537db0e68db8f2bc65bc) @@ -19,6 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using Ringtoets.MacroStabilityInwards.Primitives.Properties; + namespace Ringtoets.MacroStabilityInwards.Primitives { /// @@ -38,12 +41,19 @@ /// variation of the stochastic distribution for the preconsolidation stress. /// The shift of the stochastic distribution /// for the preconsolidation stress + /// Thrown when any of the parameters has an invalid value. public MacroStabilityInwardsPreconsolidationStress(double xCoordinate, double zCoordinate, double preconsolidationStressMean, double preconsolidationStressCoefficientOfVariation, double preconsolidationStressShift) { + ValidateParameter(xCoordinate, Resources.MacroStabilityInwardsPreconsolidationStress_XCoordinate_ParameterName); + ValidateParameter(zCoordinate, Resources.MacroStabilityInwardsPreconsolidationStress_ZCoordinate_ParameterName); + ValidateParameter(preconsolidationStressMean, Resources.MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressMean_ParameterName); + ValidateParameter(preconsolidationStressCoefficientOfVariation, Resources.MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressCoefficientOfVariation_ParameterName); + ValidateParameter(preconsolidationStressShift, Resources.MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressShift_ParameterName); + XCoordinate = xCoordinate; ZCoordinate = zCoordinate; PreconsolidationStressMean = preconsolidationStressMean; @@ -81,6 +91,21 @@ /// public double PreconsolidationStressShift { get; } + /// + /// Validates if the is a valid value. + /// + /// The value to validate. + /// The name of the parameter to validate. + /// Thrown if the parameter value is invalid. + private static void ValidateParameter(double value, string parameterName) + { + if (double.IsNaN(value)) + { + string message = string.Format(Resources.MacroStabilityInwardsPreconsolidationStress_ValidateParameter_The_value_of_ParameterName_0_must_be_a_concrete_value, parameterName); + throw new ArgumentException(message); + } + } + public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.Designer.cs =================================================================== diff -u -rf9cb0b4f173deb3519922fb8f073d8815c516950 -red2f1cb6668ebc525c0d537db0e68db8f2bc65bc --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision f9cb0b4f173deb3519922fb8f073d8815c516950) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision ed2f1cb6668ebc525c0d537db0e68db8f2bc65bc) @@ -109,6 +109,64 @@ } /// + /// Looks up a localized string similar to variatiecoëfficient. + /// + public static string MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressCoefficientOfVariation_ParameterName { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressCoefficientOfVa" + + "riation_ParameterName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to gemiddelde. + /// + public static string MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressMean_ParameterName { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressMean_ParameterN" + + "ame", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to verschuiving. + /// + public static string MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressShift_ParameterName { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_PreconsolidationStressShift_Parameter" + + "Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to De waarde voor '{0}' moet een concreet getal zijn.. + /// + public static string MacroStabilityInwardsPreconsolidationStress_ValidateParameter_The_value_of_ParameterName_0_must_be_a_concrete_value { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_ValidateParameter_The_value_of_Parame" + + "terName_0_must_be_a_concrete_value", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to X-coördinaat. + /// + public static string MacroStabilityInwardsPreconsolidationStress_XCoordinate_ParameterName { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_XCoordinate_ParameterName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Z-coördinaat. + /// + public static string MacroStabilityInwardsPreconsolidationStress_ZCoordinate_ParameterName { + get { + return ResourceManager.GetString("MacroStabilityInwardsPreconsolidationStress_ZCoordinate_ParameterName", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Eén of meerdere lagen hebben een top onder de bodem van de ondergrondschematisatie.. /// public static string MacroStabilityInwardsSoilProfile_Layers_Layer_top_below_profile_bottom { Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.resx =================================================================== diff -u -rf9cb0b4f173deb3519922fb8f073d8815c516950 -red2f1cb6668ebc525c0d537db0e68db8f2bc65bc --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.resx (.../Resources.resx) (revision f9cb0b4f173deb3519922fb8f073d8815c516950) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Primitives/Properties/Resources.resx (.../Resources.resx) (revision ed2f1cb6668ebc525c0d537db0e68db8f2bc65bc) @@ -135,4 +135,22 @@ Zand dijk op zand (geval 2B) + + De waarde voor '{0}' moet een concreet getal zijn. + + + X-coördinaat + + + Z-coördinaat + + + gemiddelde + + + variatiecoëfficient + + + verschuiving + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPreconsolidationStressTest.cs =================================================================== diff -u -re4e0262d031b09d6ddb2812720cb69bb8f14b564 -red2f1cb6668ebc525c0d537db0e68db8f2bc65bc --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPreconsolidationStressTest.cs (.../MacroStabilityInwardsPreconsolidationStressTest.cs) (revision e4e0262d031b09d6ddb2812720cb69bb8f14b564) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPreconsolidationStressTest.cs (.../MacroStabilityInwardsPreconsolidationStressTest.cs) (revision ed2f1cb6668ebc525c0d537db0e68db8f2bc65bc) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using Core.Common.TestUtil; using NUnit.Framework; namespace Ringtoets.MacroStabilityInwards.Primitives.Test @@ -29,16 +30,16 @@ public class MacroStabilityInwardsPreconsolidationStressTest { [Test] - public void Constructor_ReturnsExpectedValues() + public void Constructor_ValidArguments_ReturnsExpectedValues() { // Setup var random = new Random(21); double xCoordinate = random.NextDouble(); double zCoordinate = random.NextDouble(); - double stressShift = random.NextDouble(); double stressMean = random.NextDouble(); double stressCoefficientOfVariation = random.NextDouble(); + double stressShift = random.NextDouble(); // Call var stress = new MacroStabilityInwardsPreconsolidationStress(xCoordinate, @@ -56,6 +57,27 @@ } [Test] + [TestCaseSource(nameof(GetInvalidConstructorArguments))] + public void Constructor_ArgumentsNaN_ThrowsArgumentException(double xCoordinate, + double zCoordinate, + double stressMean, + double stressCoefficientOfVariation, + double stressShift, + string parameterName) + { + // Call + TestDelegate call = () => new MacroStabilityInwardsPreconsolidationStress(xCoordinate, + zCoordinate, + stressMean, + stressCoefficientOfVariation, + stressShift); + + // Assert + string expectedMessage = $"De waarde voor '{parameterName}' moet een concreet getal zijn."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] public void Equals_ToNull_ReturnsFalse() { // Setup @@ -81,7 +103,7 @@ } [Test] - public void Equals_ToiTself_ReturnsTrue() + public void Equals_ToItself_ReturnsTrue() { // Setup var random = new Random(21); @@ -297,6 +319,23 @@ .SetName("Different Shift"); } + private static IEnumerable GetInvalidConstructorArguments() + { + var random = new Random(21); + + double xCoordinate = random.NextDouble(); + double zCoordinate = random.NextDouble(); + double stressMean = random.NextDouble(); + double stressCoefficientOfVariation = random.NextDouble(); + double stressShift = random.NextDouble(); + + yield return new TestCaseData(double.NaN, zCoordinate, stressMean, stressCoefficientOfVariation, stressShift, "X-coördinaat").SetName("Invalid XCoordinate"); + yield return new TestCaseData(xCoordinate, double.NaN, stressMean, stressCoefficientOfVariation, stressShift, "Z-coördinaat").SetName("Invalid ZCoordinate"); + yield return new TestCaseData(xCoordinate, zCoordinate, double.NaN, stressCoefficientOfVariation, stressShift, "gemiddelde").SetName("Invalid Mean"); + yield return new TestCaseData(xCoordinate, zCoordinate, stressMean, double.NaN, stressShift, "variatiecoëfficient").SetName("Invalid Coefficient of Variation"); + yield return new TestCaseData(xCoordinate, zCoordinate, stressMean, stressCoefficientOfVariation, double.NaN, "verschuiving").SetName("Invalid Shift"); + } + private class DerivedMacroStabilityInwardsPreconsolidationStress : MacroStabilityInwardsPreconsolidationStress { public DerivedMacroStabilityInwardsPreconsolidationStress(double xCoordinate,