Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r10de4c88d71a59af9a2d7e46a94410445ce257f5 -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 10de4c88d71a59af9a2d7e46a94410445ce257f5) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -141,6 +141,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilLayerDistributionHelper.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilLayerDistributionHelper.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/SoilLayerDistributionHelper.cs (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Ringtoets.Common.IO.Exceptions; +using Ringtoets.Common.IO.Properties; + +namespace Ringtoets.Common.IO.SoilProfile +{ + /// + /// Class which provides helper methods for validating distributions of + /// . + /// + public static class SoilLayerDistributionHelper + { + private const double tolerance = 1e-6; + + /// + /// Validates if the distribution is a non-shifted log normal distribution. + /// + /// The distribution type. + /// The value of the shift. + /// The name of the parameter to be validated. + /// Thrown when + /// is null. + /// Thrown when the parameter is not a + /// non-shifted log normal distribution. + public static void ValidateIsNonShiftedLogNormal(long? distribution, double shift, string parameterName) + { + if (parameterName == null) + { + throw new ArgumentNullException(nameof(parameterName)); + } + + if (distribution.HasValue && (distribution.Value != SoilLayerConstants.LogNormalDistributionValue + || Math.Abs(shift) > tolerance)) + { + throw new ImportedDataTransformException(string.Format( + Resources.SoilLayer_Stochastic_parameter_0_has_no_lognormal_distribution, + parameterName)); + } + } + + /// + /// Validates if the distribution is a log normal distribution. + /// + /// The distribution type. + /// The name of the parameter to be validated. + /// Thrown when + /// is null. + /// Thrown when the parameter is not a + /// log-normal distribution. + public static void ValidateIsLogNormal(long? distribution, string parameterName) + { + if (parameterName == null) + { + throw new ArgumentNullException(nameof(parameterName)); + } + + if (distribution.HasValue && distribution != SoilLayerConstants.LogNormalDistributionValue) + { + throw new ImportedDataTransformException(string.Format( + Resources.SoilLayer_Stochastic_parameter_0_has_no_shifted_lognormal_distribution, + parameterName)); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj =================================================================== diff -u -r10de4c88d71a59af9a2d7e46a94410445ce257f5 -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 10de4c88d71a59af9a2d7e46a94410445ce257f5) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -122,6 +122,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilLayerDistributionHelperTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilLayerDistributionHelperTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/SoilLayerDistributionHelperTest.cs (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -0,0 +1,163 @@ +// Copyright (C) Stichting Deltares 2017. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using NUnit.Framework; +using Ringtoets.Common.IO.Exceptions; +using Ringtoets.Common.IO.SoilProfile; + +namespace Ringtoets.Common.IO.Test.SoilProfile +{ + [TestFixture] + public class SoilLayerDistributionHelperTest + { + [Test] + public void ValidateIsNonShiftedLogNormal_ParameterNameNull_ThrowsArgumentNullException() + { + // Setup + var random = new Random(21); + long distributionType = random.Next(); + double shift = random.NextDouble(); + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal(distributionType, + shift, + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("parameterName", exception.ParamName); + } + + [Test] + [TestCase(-1, 0)] + [TestCase(3, 10)] + public void ValidateIsNonShiftedLogNormal_InvalidDistributionProperties_ThrowsImportedDataException( + long distributionType, + double shift) + { + // Setup + const string parameterName = "Just a name"; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal(distributionType, + shift, + parameterName); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Parameter '{parameterName}' is niet lognormaal verdeeld.", exception.Message); + } + + [Test] + public void ValidateIsNonShiftedLogNormal_ValidDistribution_DoesNotThrowException() + { + // Setup + const long distributionType = 3; + const double shift = 0; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal(distributionType, + shift, + string.Empty); + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void ValidateIsNonShiftedLogNormal_DistributionTypeNull_DoesNotThrowException() + { + // Setup + var random = new Random(21); + double shift = random.NextDouble(); + const string parameterName = "Just a name"; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal(null, + shift, + parameterName); + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void ValidateIsLogNormal_ParameterNameNull_ThrowsArgumentNullException() + { + // Setup + var random = new Random(21); + long distributionType = random.Next(); + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsLogNormal(distributionType, + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("parameterName", exception.ParamName); + } + + [Test] + public void ValidateIsLogNormal_InvalidDistributionProperties_ThrowsImportedDataException() + { + // Setup + const long invalidDistributionType = -1; + const string parameterName = "Just a name"; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsLogNormal(invalidDistributionType, + parameterName); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual($"Parameter '{parameterName}' is niet verschoven lognormaal verdeeld.", exception.Message); + } + + [Test] + public void ValidateIsLogNormal_ValidDistribution_DoesNotThrowException() + { + // Setup + const long distributionType = 3; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsLogNormal(distributionType, + string.Empty); + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void ValidateIsLogNormal_DistributionTypeNull_DoesNotThrowException() + { + // Setup + const string parameterName = "Just a name"; + + // Call + TestDelegate call = () => SoilLayerDistributionHelper.ValidateIsLogNormal(null, + parameterName); + + // Assert + Assert.DoesNotThrow(call); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r4b7c486c202b231dda871f2fada8384e90572334 -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4b7c486c202b231dda871f2fada8384e90572334) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -182,10 +182,9 @@ /// /// Looks up a localized string similar to Ongeldige waarde voor parameter '{0}'.. /// - public static string MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0 { + public static string MacroStabilityInwardsSoilLayerTransformer_Invalid_value_ParameterName_0 { get { - return ResourceManager.GetString("MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_Parameter" + - "Name_0", resourceCulture); + return ResourceManager.GetString("MacroStabilityInwardsSoilLayerTransformer_Invalid_value_ParameterName_0", resourceCulture); } } Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx =================================================================== diff -u -r4b7c486c202b231dda871f2fada8384e90572334 -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 4b7c486c202b231dda871f2fada8384e90572334) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -261,7 +261,7 @@ Verzadigd gewicht - + Ongeldige waarde voor parameter '{0}'. Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs =================================================================== diff -u -r9e44ac01609d60fb143e8c3df05439ae919f8e5a -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 9e44ac01609d60fb143e8c3df05439ae919f8e5a) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -27,7 +27,6 @@ using Ringtoets.Common.IO.SoilProfile; using Ringtoets.MacroStabilityInwards.IO.Properties; using Ringtoets.MacroStabilityInwards.Primitives; -using RingtoetsCommonResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.IO.SoilProfiles { @@ -129,7 +128,7 @@ properties.PopMean = soilLayer.PopMean; properties.PopDeviation = soilLayer.PopCoefficientOfVariation; } - + private static bool TransformUsePop(double? usePop) { if (!usePop.HasValue) @@ -142,7 +141,7 @@ return false; } - throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0, + throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_Invalid_value_ParameterName_0, Resources.SoilLayerProperties_UsePop_Description)); } @@ -165,7 +164,7 @@ return MacroStabilityInwardsShearStrengthModel.None; } - throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0, + throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_Invalid_value_ParameterName_0, Resources.SoilLayerProperties_ShearStrengthModel_Description)); } @@ -192,73 +191,37 @@ /// stochastic parameters is not defined as lognormal or is shifted when it should not be. private static void ValidateStochasticParameters(SoilLayerBase soilLayer) { - ValidateIsLogNormal(soilLayer.AbovePhreaticLevelDistribution, - Resources.SoilLayerProperties_AbovePhreaticLevelDistribution_Description); + SoilLayerDistributionHelper.ValidateIsLogNormal(soilLayer.AbovePhreaticLevelDistribution, + Resources.SoilLayerProperties_AbovePhreaticLevelDistribution_Description); - ValidateIsLogNormal( + SoilLayerDistributionHelper.ValidateIsLogNormal( soilLayer.BelowPhreaticLevelDistribution, Resources.SoilLayerProperties_BelowPhreaticLevelDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.CohesionDistribution, soilLayer.CohesionShift, Resources.SoilLayerProperties_CohesionDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.FrictionAngleDistribution, soilLayer.FrictionAngleShift, Resources.SoilLayerProperties_FrictionAngleDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.ShearStrengthRatioDistribution, soilLayer.ShearStrengthRatioShift, Resources.SoilLayerProperties_ShearStrengthRatioDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.StrengthIncreaseExponentDistribution, soilLayer.StrengthIncreaseExponentShift, Resources.SoilLayerProperties_StrengthIncreaseExponentDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.PopDistribution, soilLayer.PopShift, Resources.SoilLayerProperties_PopDistribution_Description); } - - /// - /// Validates if the distribution is a non-shifted log normal distribution. - /// - /// The distribution type. - /// The value of the shift. - /// The name of the parameter to be validated. - /// Thrown when the parameter is not a - /// non-shifted log normal distribution. - private static void ValidateIsNonShiftedLogNormal(long? distribution, double shift, string incorrectDistibutionParameter) - { - if (distribution.HasValue && (distribution.Value != SoilLayerConstants.LogNormalDistributionValue - || Math.Abs(shift) > tolerance)) - { - throw new ImportedDataTransformException(string.Format( - RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_lognormal_distribution, - incorrectDistibutionParameter)); - } - } - - /// - /// Validates if the distribution is a log normal distribution. - /// - /// The distribution type. - /// The name of the parameter to be validated. - /// Thrown when the parameter is not a - /// log-normal distribution. - private static void ValidateIsLogNormal(long? distribution, string incorrectDistibutionParameter) - { - if (distribution.HasValue && distribution != SoilLayerConstants.LogNormalDistributionValue) - { - throw new ImportedDataTransformException(string.Format( - RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_shifted_lognormal_distribution, - incorrectDistibutionParameter)); - } - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilProfileTransformerTest.cs =================================================================== diff -u -r140635b34616f25ca853982955976632b6000c52 -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilProfileTransformerTest.cs (.../MacroStabilityInwardsSoilProfileTransformerTest.cs) (revision 140635b34616f25ca853982955976632b6000c52) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilProfileTransformerTest.cs (.../MacroStabilityInwardsSoilProfileTransformerTest.cs) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -68,9 +68,9 @@ public void Transform_ValidSoilProfile1D_ReturnMacroStabilityInwardsSoilProfile1D() { // Setup - var profile = new SoilProfile1D(1, "test", 3, new [] + var profile = new SoilProfile1D(1, "test", 3, new[] { - new SoilLayer1D(4), + new SoilLayer1D(4) }); // Call @@ -80,14 +80,14 @@ Assert.AreEqual(profile.Name, transformedProfile.Name); Assert.AreEqual(profile.Bottom, transformedProfile.Bottom); Assert.AreEqual(profile.Layers.Count(), transformedProfile.Layers.Count()); - Assert.IsInstanceOf(transformedProfile.Layers.First()); + CollectionAssert.AllItemsAreInstancesOfType(transformedProfile.Layers, typeof(MacroStabilityInwardsSoilLayer1D)); } [Test] public void Transform_ValidSoilProfile2D_ReturnMacroStabilityInwardsSoilProfile1D() { // Setup - var profile = new SoilProfile2D(1, "test", new [] + var profile = new SoilProfile2D(1, "test", new[] { SoilLayer2DTestFactory.CreateSoilLayer2D() }); @@ -98,7 +98,7 @@ // Assert Assert.AreEqual(profile.Name, transformedProfile.Name); Assert.AreEqual(profile.Layers.Count(), transformedProfile.Layers.Count()); - Assert.IsInstanceOf(transformedProfile.Layers.First()); + CollectionAssert.AllItemsAreInstancesOfType(transformedProfile.Layers, typeof(MacroStabilityInwardsSoilLayer2D)); } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingSoilLayerTransformer.cs =================================================================== diff -u -r564d08f23d1931635a55e1aa9240320dfdbfda6a -r613d5197233c721a6cf95c4f722f1c1941f3081d --- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingSoilLayerTransformer.cs (.../PipingSoilLayerTransformer.cs) (revision 564d08f23d1931635a55e1aa9240320dfdbfda6a) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingSoilLayerTransformer.cs (.../PipingSoilLayerTransformer.cs) (revision 613d5197233c721a6cf95c4f722f1c1941f3081d) @@ -28,7 +28,6 @@ using Ringtoets.Common.IO.SoilProfile; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.Primitives; -using RingtoetsCommonResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.Piping.IO.SoilProfiles { @@ -124,14 +123,14 @@ /// stochastic parameters is not defined as lognormal or is shifted when it should not be. private static void ValidateStochasticParameters(SoilLayerBase soilLayer) { - ValidateIsLogNormal( + SoilLayerDistributionHelper.ValidateIsLogNormal( soilLayer.BelowPhreaticLevelDistribution, Resources.SoilLayer_BelowPhreaticLevelDistribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.DiameterD70Distribution, soilLayer.DiameterD70Shift, Resources.SoilLayer_DiameterD70Distribution_Description); - ValidateIsNonShiftedLogNormal( + SoilLayerDistributionHelper.ValidateIsNonShiftedLogNormal( soilLayer.PermeabilityDistribution, soilLayer.PermeabilityShift, Resources.SoilLayer_PermeabilityDistribution_Description); @@ -155,27 +154,6 @@ pipingSoilLayer.PermeabilityCoefficientOfVariation = soilLayer1D.PermeabilityCoefficientOfVariation; } - private static void ValidateIsNonShiftedLogNormal(long? distribution, double shift, string incorrectDistibutionParameter) - { - if (distribution.HasValue && (distribution.Value != SoilLayerConstants.LogNormalDistributionValue - || Math.Abs(shift) > 1e-6)) - { - throw new ImportedDataTransformException(string.Format( - RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_lognormal_distribution, - incorrectDistibutionParameter)); - } - } - - private static void ValidateIsLogNormal(long? distribution, string incorrectDistibutionParameter) - { - if (distribution.HasValue && distribution != SoilLayerConstants.LogNormalDistributionValue) - { - throw new ImportedDataTransformException(string.Format( - RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_shifted_lognormal_distribution, - incorrectDistibutionParameter)); - } - } - private static bool HeightInInnerLoop(Tuple tuple, double height) { return height <= tuple.Item2 && height > tuple.Item1;