Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -ra055d56e9d6e79c7285a51cce7de68188f252431 -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision a055d56e9d6e79c7285a51cce7de68188f252431) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -131,7 +131,6 @@ - Fisheye: Tag 4b7c486c202b231dda871f2fada8384e90572334 refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/ShearStrengthModel.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r564d08f23d1931635a55e1aa9240320dfdbfda6a -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 564d08f23d1931635a55e1aa9240320dfdbfda6a) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -180,6 +180,16 @@ } /// + /// Looks up a localized string similar to Ongeldige waarde voor parameter '{0}'.. + /// + public static string MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0 { + get { + return ResourceManager.GetString("MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_Parameter" + + "Name_0", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kritieke fout opgetreden bij het uitlezen van waardes uit kolommen in de database.. /// public static string MacroStabilityInwardsSoilProfileReader_Critical_Unexpected_value_on_column { @@ -367,6 +377,15 @@ } /// + /// Looks up a localized string similar to Schuifsterkte model. + /// + public static string SoilLayerProperties_ShearStrengthModel_Description { + get { + return ResourceManager.GetString("SoilLayerProperties_ShearStrengthModel_Description", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Schuifsterkte ratio S. /// public static string SoilLayerProperties_ShearStrengthRatioDistribution_Description { @@ -385,6 +404,15 @@ } /// + /// Looks up a localized string similar to Gebruik POP. + /// + public static string SoilLayerProperties_UsePop_Description { + get { + return ResourceManager.GetString("SoilLayerProperties_UsePop_Description", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Kon geen stochastische ondergrondmodellen verkrijgen uit de database.. /// public static string StochasticSoilModelDatabaseReader_Failed_to_read_database { Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx =================================================================== diff -u -r564d08f23d1931635a55e1aa9240320dfdbfda6a -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 564d08f23d1931635a55e1aa9240320dfdbfda6a) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/Properties/Resources.resx (.../Resources.resx) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -261,4 +261,13 @@ Verzadigd gewicht + + Ongeldige waarde voor parameter '{0}'. + + + Gebruik POP + + + Schuifsterkte model + \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs =================================================================== diff -u -ra055d56e9d6e79c7285a51cce7de68188f252431 -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision a055d56e9d6e79c7285a51cce7de68188f252431) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -37,6 +37,8 @@ /// internal static class MacroStabilityInwardsSoilLayerTransformer { + private const double tolerance = 1e-6; + /// /// Transforms the generic into a /// . @@ -95,22 +97,21 @@ return layer; } + /// + /// Sets the properties of the . + /// + /// The soil layer to get the properties from. + /// The properties to set the data upon. + /// Thrown when transformation would not result + /// in a valid transformed instance. private static void SetProperties(SoilLayerBase soilLayer, MacroStabilityInwardsSoilLayerProperties properties) { - try - { - // TODO: Write converter from double? to ShearStrengthModel -// properties.ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel); - } - catch (NotSupportedException e) - { - throw new ImportedDataTransformException("Er ging iets mis met transformeren.", e); - } + properties.ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel); + properties.UsePop = TransformUsePop(soilLayer.UsePop); properties.MaterialName = soilLayer.MaterialName; properties.IsAquifer = soilLayer.IsAquifer; properties.Color = soilLayer.Color; - properties.UsePop = false; // TODO: Write conversion from double? to bool properties.AbovePhreaticLevelMean = soilLayer.AbovePhreaticLevelMean; properties.AbovePhreaticLevelDeviation = soilLayer.AbovePhreaticLevelDeviation; properties.BelowPhreaticLevelMean = soilLayer.BelowPhreaticLevelMean; @@ -126,7 +127,46 @@ properties.PopMean = soilLayer.PopMean; properties.PopDeviation = soilLayer.PopDeviation; } + + private static bool TransformUsePop(double? usePop) + { + if (!usePop.HasValue) + { + return true; + } + if (Math.Abs(usePop.Value) < tolerance) + { + return false; + } + + throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0, + Resources.SoilLayerProperties_UsePop_Description)); + } + + private static MacroStabilityInwardsShearStrengthModel TransformShearStrengthModel(double? shearStrengthModel) + { + if (!shearStrengthModel.HasValue) + { + return MacroStabilityInwardsShearStrengthModel.CPhi; + } + if (Math.Abs(shearStrengthModel.Value - 6) < tolerance) + { + return MacroStabilityInwardsShearStrengthModel.SuCalculated; + } + if (Math.Abs(shearStrengthModel.Value - 9) < tolerance) + { + return MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated; + } + if (Math.Abs(shearStrengthModel.Value - 1) < tolerance) + { + return MacroStabilityInwardsShearStrengthModel.None; + } + + throw new ImportedDataTransformException(string.Format(Resources.MacroStabilityInwardsSoilLayerTransformer_TransformUsePop_Invalid_value_ParameterName_0, + Resources.SoilLayerProperties_ShearStrengthModel_Description)); + } + private static Ring TransformSegmentToRing(IEnumerable loop) { var points = new List(); @@ -182,7 +222,7 @@ private static void ValidateIsNonShiftedLogNormal(long? distribution, double shift, string incorrectDistibutionParameter) { if (distribution.HasValue && (distribution.Value != SoilLayerConstants.LogNormalDistributionValue - || Math.Abs(shift) > 1e-6)) + || Math.Abs(shift) > tolerance)) { throw new ImportedDataTransformException(string.Format( RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_lognormal_distribution, @@ -199,29 +239,5 @@ incorrectDistibutionParameter)); } } - - /// - /// Transforms the to . - /// - /// The model to transform. - /// A based on the given data. - /// Thrown when - /// has an invalid value. - private static MacroStabilityInwardsShearStrengthModel TransformShearStrengthModel(ShearStrengthModel shearStrengthModel) - { - switch (shearStrengthModel) - { - case ShearStrengthModel.None: - return MacroStabilityInwardsShearStrengthModel.None; - case ShearStrengthModel.SuCalculated: - return MacroStabilityInwardsShearStrengthModel.SuCalculated; - case ShearStrengthModel.CPhi: - return MacroStabilityInwardsShearStrengthModel.CPhi; - case ShearStrengthModel.CPhiOrSuCalculated: - return MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated; - default: - throw new NotSupportedException(); - } - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs =================================================================== diff -u -ra055d56e9d6e79c7285a51cce7de68188f252431 -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision a055d56e9d6e79c7285a51cce7de68188f252431) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -58,8 +58,6 @@ double top = random.NextDouble(); const string materialName = "materialX"; Color color = Color.AliceBlue; - double usePop = random.NextDouble(); - double shearStrengthModel = random.NextDouble(); double abovePhreaticLevelMean = random.NextDouble(); double abovePhreaticLevelDeviation = random.NextDouble(); @@ -81,8 +79,6 @@ IsAquifer = isAquifer, MaterialName = materialName, Color = color, - UsePop = usePop, - ShearStrengthModel = shearStrengthModel, AbovePhreaticLevelMean = abovePhreaticLevelMean, AbovePhreaticLevelDeviation = abovePhreaticLevelDeviation, BelowPhreaticLevelMean = belowPhreaticLevelMean, @@ -109,8 +105,6 @@ Assert.AreEqual(isAquifer, properties.IsAquifer); Assert.AreEqual(materialName, properties.MaterialName); Assert.AreEqual(color, properties.Color); -// Assert.AreEqual(usePop, properties.UsePop); // TODO Verify conversion from double? to bool -// Assert.AreEqual(GetMacroStabilityInwardsShearStrengthModel(shearStrengthModel), properties.ShearStrengthModel); // TODO: Verify conversion from double to enum Assert.AreEqual(abovePhreaticLevelMean, properties.AbovePhreaticLevelMean); Assert.AreEqual(abovePhreaticLevelDeviation, properties.AbovePhreaticLevelDeviation); Assert.AreEqual(belowPhreaticLevelMean, properties.BelowPhreaticLevelMean); @@ -127,25 +121,80 @@ Assert.AreEqual(popDeviation, properties.PopDeviation); } -// [Test] -// public void SoilLayer1DTransform_InvalidShearStrengthModel_ThrowImportedDataTransformException() -// { -// // Setup -// var layer = new SoilLayer1D(1) -// { -// ShearStrengthModel = 99 -// }; -// -// // Call -// TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); -// -// // Assert -// var exception = Assert.Throws(test); -// Assert.AreEqual("Er ging iets mis met transformeren.", exception.Message); -// Assert.IsInstanceOf(exception.InnerException); -// } + [Test] + [TestCase(null, true)] + [TestCase(0, false)] + public void SoilLayer1DTransform_ValidUsePopValue_ReturnMacroStabilityInwardSoilLayer1D(double? usePop, bool transformedUsePopValue) + { + // Setup + var layer = new SoilLayer1D(0) + { + UsePop = usePop + }; + // Call + MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + Assert.AreEqual(transformedUsePopValue, soilLayer1D.Properties.UsePop); + } + [Test] + public void SoilLayer1DTransform_InvalidUsePopValue_ReturnMacroStabilityInwardSoilLayer1D() + { + // Setup + var layer = new SoilLayer1D(0) + { + UsePop = 1 + }; + + // Call + TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message); + } + + [Test] + [TestCase(null, MacroStabilityInwardsShearStrengthModel.CPhi)] + [TestCase(9, MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)] + [TestCase(6, MacroStabilityInwardsShearStrengthModel.SuCalculated)] + [TestCase(1, MacroStabilityInwardsShearStrengthModel.None)] + public void SoilLayer1DTransform_ValidShearStrengthModelValue_ReturnMacroStabilityInwardSoilLayer1D(double? sheartStrengthModel, + MacroStabilityInwardsShearStrengthModel transformedShearStrengthModel) + { + // Setup + var layer = new SoilLayer1D(0) + { + ShearStrengthModel = sheartStrengthModel + }; + + // Call + MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + Assert.AreEqual(transformedShearStrengthModel, soilLayer1D.Properties.ShearStrengthModel); + } + + [Test] + public void SoilLayer1DTransform_InvalidShearStrengthModelValue_ThrowsImportedDataTransformException() + { + // Setup + var layer = new SoilLayer1D(0) + { + ShearStrengthModel = 2 + }; + + // Call + TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message); + } + + [Test] public void SoilLayer1DTransform_IncorrectShiftedLogNormalDistribution_ThrowsImportedDataTransformException() { // Setup @@ -194,8 +243,6 @@ bool isAquifer = random.NextBoolean(); const string materialName = "materialX"; Color color = Color.AliceBlue; - double usePop = random.NextDouble(); - double shearStrengthModel = random.NextDouble(); double abovePhreaticLevelMean = random.NextDouble(); double abovePhreaticLevelDeviation = random.NextDouble(); @@ -216,8 +263,6 @@ layer.IsAquifer = isAquifer; layer.MaterialName = materialName; layer.Color = color; - layer.UsePop = usePop; - layer.ShearStrengthModel = shearStrengthModel; layer.AbovePhreaticLevelMean = abovePhreaticLevelMean; layer.AbovePhreaticLevelDeviation = abovePhreaticLevelDeviation; layer.BelowPhreaticLevelMean = belowPhreaticLevelMean; @@ -241,8 +286,6 @@ Assert.AreEqual(isAquifer, properties.IsAquifer); Assert.AreEqual(materialName, properties.MaterialName); Assert.AreEqual(color, properties.Color); -// Assert.AreEqual(usePop, properties.UsePop); // TODO Verify conversion from double? to bool -// Assert.AreEqual(GetMacroStabilityInwardsShearStrengthModel(shearStrengthModel), properties.ShearStrengthModel); // TODO: Verify conversion from double to enum Assert.AreEqual(abovePhreaticLevelMean, properties.AbovePhreaticLevelMean); Assert.AreEqual(abovePhreaticLevelDeviation, properties.AbovePhreaticLevelDeviation); Assert.AreEqual(belowPhreaticLevelMean, properties.BelowPhreaticLevelMean); @@ -261,23 +304,72 @@ AssertRings(layer, soilLayer2D); } -// [Test] -// public void SoilLayer2DTransform_InvalidShearStrengthModel_ThrowImportedDataTransformException() -// { -// // Setup -// SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); -// layer.ShearStrengthModel = 99; -// -// // Call -// TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); -// -// // Assert -// var exception = Assert.Throws(test); -// Assert.AreEqual("Er ging iets mis met transformeren.", exception.Message); -// Assert.IsInstanceOf(exception.InnerException); -// } + [Test] + [TestCase(null, true)] + [TestCase(0, false)] + public void SoilLayer2DTransform_ValidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D(double? usePop, bool transformedUsePopValue) + { + // Setup + SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); + layer.UsePop = usePop; + // Call + MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + Assert.AreEqual(transformedUsePopValue, soilLayer2D.Properties.UsePop); + } + [Test] + public void SoilLayer2DTransform_InvalidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D() + { + // Setup + SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); + layer.UsePop = 1; + + // Call + TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message); + } + + [Test] + [TestCase(null, MacroStabilityInwardsShearStrengthModel.CPhi)] + [TestCase(9, MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)] + [TestCase(6, MacroStabilityInwardsShearStrengthModel.SuCalculated)] + [TestCase(1, MacroStabilityInwardsShearStrengthModel.None)] + public void SoilLayer2DTransform_ValidShearStrengthModelValue_ReturnMacroStabilityInwardSoilLayer2D(double? sheartStrengthModel, + MacroStabilityInwardsShearStrengthModel transformedShearStrengthModel) + { + // Setup + SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); + layer.ShearStrengthModel = sheartStrengthModel; + + // Call + MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + Assert.AreEqual(transformedShearStrengthModel, soilLayer2D.Properties.ShearStrengthModel); + } + + [Test] + public void SoilLayer2DTransform_InvalidShearStrengthModelValue_ThrowsImportedDataTransformException() + { + // Setup + SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); + layer.ShearStrengthModel = 2; + + // Call + TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message); + } + + [Test] public void SoilLayer2DTransform_IncorrectShiftedLogNormalDistribution_ThrowsImportedDataTransformException() { // Setup @@ -412,22 +504,5 @@ yield return new TestCaseData(invalidPopDistribution, "POP" ).SetName(string.Format(testNameFormat, typeName, "Distribution")); } - - private MacroStabilityInwardsShearStrengthModel GetMacroStabilityInwardsShearStrengthModel(ShearStrengthModel shearStrengthModel) - { - switch (shearStrengthModel) - { - case ShearStrengthModel.None: - return MacroStabilityInwardsShearStrengthModel.None; - case ShearStrengthModel.SuCalculated: - return MacroStabilityInwardsShearStrengthModel.SuCalculated; - case ShearStrengthModel.CPhi: - return MacroStabilityInwardsShearStrengthModel.CPhi; - case ShearStrengthModel.CPhiOrSuCalculated: - return MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated; - default: - throw new ArgumentOutOfRangeException(nameof(shearStrengthModel), shearStrengthModel, null); - } - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs =================================================================== diff -u -r140635b34616f25ca853982955976632b6000c52 -r4b7c486c202b231dda871f2fada8384e90572334 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilModelTransformerTest.cs) (revision 140635b34616f25ca853982955976632b6000c52) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilModelTransformerTest.cs) (revision 4b7c486c202b231dda871f2fada8384e90572334) @@ -105,6 +105,13 @@ var expectedStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(1, new MacroStabilityInwardsSoilProfile1D("test", 3, new[] { new MacroStabilityInwardsSoilLayer1D(4) + { + Properties = + { + UsePop = true, + ShearStrengthModel = MacroStabilityInwardsShearStrengthModel.CPhi + } + } })); AssertStochasticSoilProfile(expectedStochasticSoilProfile, transformedModel.StochasticSoilProfiles.First()); } @@ -151,6 +158,13 @@ new Point2D(1.0, 1.0) }), }) + { + Properties = + { + UsePop = true, + ShearStrengthModel = MacroStabilityInwardsShearStrengthModel.CPhi + } + } })); AssertStochasticSoilProfile(expectedStochasticSoilProfile, transformedModel.StochasticSoilProfiles.First()); }