Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationImporter.cs
===================================================================
diff -u -r5f489223b4d730eec42acd55533dd012d10dd1ca -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationImporter.cs (.../ClosingStructuresCalculationConfigurationImporter.cs) (revision 5f489223b4d730eec42acd55533dd012d10dd1ca)
+++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.IO/Configurations/ClosingStructuresCalculationConfigurationImporter.cs (.../ClosingStructuresCalculationConfigurationImporter.cs) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -22,7 +22,6 @@
using System;
using System.Collections.Generic;
using Core.Common.Base.Data;
-using log4net;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.IO.Configurations.Helpers;
using Ringtoets.ClosingStructures.IO.Properties;
@@ -130,79 +129,76 @@
}
return TryReadStandardDeviationStochast(
- calculation.Name,
ClosingStructuresConfigurationSchemaIdentifiers.LevelCrestStructureNotClosingStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.LevelCrestStructureNotClosing,
- i => i.LevelCrestStructureNotClosing,
- (i, d) => i.LevelCrestStructureNotClosing = d)
+ i => i.LevelCrestStructureNotClosing, (i, d) => i.LevelCrestStructureNotClosing = d)
&& TryReadStandardDeviationStochast(
- calculation.Name,
ClosingStructuresConfigurationSchemaIdentifiers.AreaFlowAperturesStochastName,
- calculation.InputParameters, readCalculation.AreaFlowApertures,
- i => i.AreaFlowApertures,
- (i, d) => i.AreaFlowApertures = d)
- && TryReadStandardDeviationStochast(
calculation.Name,
- ClosingStructuresConfigurationSchemaIdentifiers.DrainCoefficientStochastName,
- calculation.InputParameters, readCalculation.DrainCoefficient,
- i => i.DrainCoefficient,
- (i, d) => i.DrainCoefficient = d)
+ calculation.InputParameters,
+ readCalculation.AreaFlowApertures,
+ i => i.AreaFlowApertures, (i, d) => i.AreaFlowApertures = d)
&& TryReadStandardDeviationStochast(
+ ClosingStructuresConfigurationSchemaIdentifiers.DrainCoefficientStochastName,
calculation.Name,
- ClosingStructuresConfigurationSchemaIdentifiers.InsideWaterLevelStochastName,
- calculation.InputParameters, readCalculation.InsideWaterLevel,
- i => i.InsideWaterLevel,
- (i, d) => i.InsideWaterLevel = d)
+ calculation.InputParameters,
+ readCalculation.DrainCoefficient,
+ i => i.DrainCoefficient, (i, d) => i.DrainCoefficient = d)
&& TryReadStandardDeviationStochast(
+ ClosingStructuresConfigurationSchemaIdentifiers.InsideWaterLevelStochastName,
calculation.Name,
- ClosingStructuresConfigurationSchemaIdentifiers.ThresholdHeightOpenWeirStochastName,
- calculation.InputParameters, readCalculation.ThresholdHeightOpenWeir,
- i => i.ThresholdHeightOpenWeir,
- (i, d) => i.ThresholdHeightOpenWeir = d)
+ calculation.InputParameters,
+ readCalculation.InsideWaterLevel,
+ i => i.InsideWaterLevel, (i, d) => i.InsideWaterLevel = d)
&& TryReadStandardDeviationStochast(
+ ClosingStructuresConfigurationSchemaIdentifiers.ThresholdHeightOpenWeirStochastName,
calculation.Name,
- ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName,
- calculation.InputParameters, readCalculation.AllowedLevelIncreaseStorage,
- i => i.AllowedLevelIncreaseStorage,
- (i, d) => i.AllowedLevelIncreaseStorage = d)
+ calculation.InputParameters,
+ readCalculation.ThresholdHeightOpenWeir,
+ i => i.ThresholdHeightOpenWeir, (i, d) => i.ThresholdHeightOpenWeir = d)
&& TryReadStandardDeviationStochast(
+ ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName,
calculation.Name,
- ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName,
- calculation.InputParameters, readCalculation.FlowWidthAtBottomProtection,
- i => i.FlowWidthAtBottomProtection,
- (i, d) => i.FlowWidthAtBottomProtection = d)
+ calculation.InputParameters,
+ readCalculation.AllowedLevelIncreaseStorage,
+ i => i.AllowedLevelIncreaseStorage, (i, d) => i.AllowedLevelIncreaseStorage = d)
&& TryReadStandardDeviationStochast(
+ ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName,
calculation.Name,
- ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName,
- calculation.InputParameters, readCalculation.ModelFactorSuperCriticalFlow,
- i => i.ModelFactorSuperCriticalFlow,
- (i, d) => i.ModelFactorSuperCriticalFlow = d)
+ calculation.InputParameters,
+ readCalculation.FlowWidthAtBottomProtection,
+ i => i.FlowWidthAtBottomProtection, (i, d) => i.FlowWidthAtBottomProtection = d)
&& TryReadStandardDeviationStochast(
+ ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName,
calculation.Name,
+ calculation.InputParameters,
+ readCalculation.ModelFactorSuperCriticalFlow,
+ i => i.ModelFactorSuperCriticalFlow, (i, d) => i.ModelFactorSuperCriticalFlow = d)
+ && TryReadStandardDeviationStochast(
ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName,
- calculation.InputParameters, readCalculation.WidthFlowApertures,
- i => i.WidthFlowApertures, (i, d) => i.WidthFlowApertures = d)
- && TryReadVariationCoefficientStochast(
calculation.Name,
- ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName,
- calculation.InputParameters, readCalculation.CriticalOvertoppingDischarge,
- i => i.CriticalOvertoppingDischarge,
- (i, d) => i.CriticalOvertoppingDischarge = d)
+ calculation.InputParameters,
+ readCalculation.WidthFlowApertures, i => i.WidthFlowApertures, (i, d) => i.WidthFlowApertures = d)
&& TryReadVariationCoefficientStochast(
+ ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName,
calculation.Name,
+ calculation.InputParameters,
+ readCalculation.CriticalOvertoppingDischarge,
+ i => i.CriticalOvertoppingDischarge, (i, d) => i.CriticalOvertoppingDischarge = d)
+ && TryReadVariationCoefficientStochast(
ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.StorageStructureArea,
- i => i.StorageStructureArea,
- (i, d) => i.StorageStructureArea = d)
+ i => i.StorageStructureArea, (i, d) => i.StorageStructureArea = d)
&& TryReadVariationCoefficientStochast(
- calculation.Name,
ConfigurationSchemaIdentifiers.StormDurationStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.StormDuration,
- i => i.StormDuration,
- (i, d) => i.StormDuration = d);
+ i => i.StormDuration, (i, d) => i.StormDuration = d);
}
private bool ValidateStochasts(ClosingStructuresCalculationConfiguration configuration)
Index: Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs
===================================================================
diff -u -reeac9fe0e250075e6e95683e4781b7b96ddc178c -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision eeac9fe0e250075e6e95683e4781b7b96ddc178c)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/FileImporters/CalculationConfigurationImporter.cs (.../CalculationConfigurationImporter.cs) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -33,6 +33,7 @@
using Ringtoets.Common.Data.Probabilistics;
using Ringtoets.Common.IO.Configurations;
using Ringtoets.Common.IO.Configurations.Helpers;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.Properties;
using Ringtoets.Common.IO.Readers;
@@ -160,9 +161,9 @@
if (location == null)
{
Log.LogCalculationConversionError(string.Format(
- Resources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_HydraulicBoundaryLocation_0_does_not_exist,
- locationName),
- calculationName);
+ Resources.CalculationConfigurationImporter_ReadHydraulicBoundaryLocation_HydraulicBoundaryLocation_0_does_not_exist,
+ locationName),
+ calculationName);
return false;
}
@@ -209,9 +210,9 @@
if (structure == null)
{
Log.LogCalculationConversionError(string.Format(
- Resources.CalculationConfigurationImporter_ReadStructure_Structure_0_does_not_exist,
- structureName),
- calculationName);
+ Resources.CalculationConfigurationImporter_ReadStructure_Structure_0_does_not_exist,
+ structureName),
+ calculationName);
return false;
}
@@ -237,7 +238,7 @@
/// or is null.
protected bool TryReadForeshoreProfile(
string foreshoreProfileName,
- string calculationName,
+ string calculationName,
IEnumerable foreshoreProfiles,
out ForeshoreProfile foundForeshoreProfile)
{
@@ -259,9 +260,9 @@
if (foreshoreProfile == null)
{
Log.LogCalculationConversionError(string.Format(
- Resources.CalculationConfigurationImporter_ReadForeshoreProfile_ForeshoreProfile_0_does_not_exist,
- foreshoreProfileName),
- calculationName);
+ Resources.CalculationConfigurationImporter_ReadForeshoreProfile_ForeshoreProfile_0_does_not_exist,
+ foreshoreProfileName),
+ calculationName);
return false;
}
@@ -310,20 +311,20 @@
///
/// The type of the distribution to read.
/// The type of the calculation input.
- /// The name of the calculation to configure.
/// The stochast's name.
+ /// The name of the calculation to configure.
/// The input for which to assign the read stochast.
/// The configuration of the stochast.
/// The function for obtaining the stochast to read.
/// The function to set the stochast with the read parameters.
/// true if reading all required stochast parameters was successful,
/// false otherwise.
protected bool TryReadStandardDeviationStochast(
- string calculationName,
string stochastName,
- TCalculationInput input,
- StochastConfiguration stochastConfiguration,
- Func getStochast,
+ string calculationName,
+ TCalculationInput input,
+ StochastConfiguration stochastConfiguration,
+ Func getStochast,
Action setStochast)
where TDistribution : IDistribution
where TCalculationInput : ICalculationInput
@@ -332,8 +333,18 @@
{
return true;
}
- var distribution = (TDistribution) getStochast(input).Clone();
+ if (stochastConfiguration.VariationCoefficient.HasValue)
+ {
+ Log.LogCalculationConversionError(string.Format(
+ Resources.CalculationConfigurationImporter_TryReadStandardDeviationStochast_Stochast_0_requires_standard_deviation_but_variation_coefficient_found_for_Calculation_1_,
+ stochastName,
+ calculationName),
+ calculationName);
+ return false;
+ }
+
+ var distribution = (TDistribution) getStochast(input).Clone();
if (!distribution.TrySetDistributionProperties(stochastConfiguration,
stochastName,
calculationName))
@@ -349,19 +360,19 @@
///
/// The type of the distribution to read.
/// The type of the calculation input.
- /// The name of the calculation to configure.
/// The stochast's name.
+ /// The name of the calculation to configure.
/// The input for which to assign the read stochast.
/// The configuration of the stochast.
/// The function for obtaining the stochast to read.
/// The function to set the stochast with the read parameters.
/// true if reading all required stochast parameters was successful,
/// false otherwise.
protected bool TryReadVariationCoefficientStochast(
- string calculationName,
string stochastName,
- TCalculationInput input,
- StochastConfiguration stochastConfiguration,
+ string calculationName,
+ TCalculationInput input,
+ StochastConfiguration stochastConfiguration,
Func getStochast,
Action setStochast)
where TDistribution : IVariationCoefficientDistribution
@@ -371,8 +382,18 @@
{
return true;
}
- var distribution = (TDistribution) getStochast(input).Clone();
+ if (stochastConfiguration.StandardDeviation.HasValue)
+ {
+ Log.LogCalculationConversionError(string.Format(
+ Resources.CalculationConfigurationImporter_TryReadVariationCoefficientStochast_Stochast_0_requires_variation_coefficient_but_standard_deviation_found_for_Calculation_1_,
+ stochastName,
+ calculationName),
+ calculationName);
+ return false;
+ }
+
+ var distribution = (TDistribution) getStochast(input).Clone();
if (!distribution.TrySetDistributionProperties(stochastConfiguration,
stochastName,
calculationName))
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -r1fea24f00be5ae78cf5ceba066bae1056c0e5a2e -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1fea24f00be5ae78cf5ceba066bae1056c0e5a2e)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -235,6 +235,26 @@
}
///
+ /// Looks up a localized string similar to Indien voor parameter '{0}' de spreiding wordt opgegeven, moet dit door middel van een standaardafwijking. Voor berekening '{1}' is een variatiecoëfficiënt gevonden..
+ ///
+ public static string CalculationConfigurationImporter_TryReadStandardDeviationStochast_Stochast_0_requires_standard_deviation_but_variation_coefficient_found_for_Calculation_1_ {
+ get {
+ return ResourceManager.GetString("CalculationConfigurationImporter_TryReadStandardDeviationStochast_Stochast_0_requ" +
+ "ires_standard_deviation_but_variation_coefficient_found_for_Calculation_1_", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Indien voor parameter '{0}' de spreiding wordt opgegeven, moet dit door middel van een variatiecoëfficiënt. Voor berekening '{1}' is een standaardafwijking gevonden..
+ ///
+ public static string CalculationConfigurationImporter_TryReadVariationCoefficientStochast_Stochast_0_requires_variation_coefficient_but_standard_deviation_found_for_Calculation_1_ {
+ get {
+ return ResourceManager.GetString("CalculationConfigurationImporter_TryReadVariationCoefficientStochast_Stochast_0_r" +
+ "equires_variation_coefficient_but_standard_deviation_found_for_Calculation_1_", resourceCulture);
+ }
+ }
+
+ ///
/// Looks up a localized string similar to {0} Berekening '{1}' is overgeslagen..
///
public static string CalculationConfigurationImporter_ValidateCalculation_ErrorMessage_0_Calculation_1_skipped {
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u -r1fea24f00be5ae78cf5ceba066bae1056c0e5a2e -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 1fea24f00be5ae78cf5ceba066bae1056c0e5a2e)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -640,4 +640,10 @@
Indien voor parameter '{0}' de spreiding wordt opgegeven, moet dit door middel van een standaardafwijking. Voor berekening '{1}' is een variatiecoëfficiënt gevonden.
+
+ Indien voor parameter '{0}' de spreiding wordt opgegeven, moet dit door middel van een standaardafwijking. Voor berekening '{1}' is een variatiecoëfficiënt gevonden.
+
+
+ Indien voor parameter '{0}' de spreiding wordt opgegeven, moet dit door middel van een variatiecoëfficiënt. Voor berekening '{1}' is een standaardafwijking gevonden.
+
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/CalculationConfigurationImporterTest.cs
===================================================================
diff -u -r335523a40d190e19b1061804de21c28f74140f52 -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/CalculationConfigurationImporterTest.cs (.../CalculationConfigurationImporterTest.cs) (revision 335523a40d190e19b1061804de21c28f74140f52)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/CalculationConfigurationImporterTest.cs (.../CalculationConfigurationImporterTest.cs) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -34,9 +34,9 @@
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.Hydraulics;
+using Ringtoets.Common.Data.Probabilistics;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.IO.Configurations;
-using Ringtoets.Common.IO.Configurations.Helpers;
using Ringtoets.Common.IO.FileImporters;
using Ringtoets.Common.IO.Readers;
using Ringtoets.Common.IO.Schema;
@@ -46,7 +46,8 @@
[TestFixture]
public class CalculationConfigurationImporterTest
{
- private readonly string readerPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "CalculationConfigurationReader");
+ private readonly string readerPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(CalculationConfigurationReader));
+ private readonly string importerPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, nameof(CalculationConfigurationImporter));
[Test]
public void Constructor_ExpectedValues()
@@ -210,7 +211,7 @@
Assert.IsTrue(successful);
AssertCalculationGroup(GetExpectedNestedData(), calculationGroup);
}
-
+
[Test]
[TestCase(true, true, 1.2, ConfigurationBreakWaterType.Wall, BreakWaterType.Wall)]
[TestCase(false, false, 2.2, ConfigurationBreakWaterType.Caisson, BreakWaterType.Caisson)]
@@ -704,6 +705,172 @@
Assert.AreSame(expectedProfile, structure);
}
+ [Test]
+ [TestCase(true, false)]
+ [TestCase(false, true)]
+ [TestCase(true, true)]
+ [TestCase(false, false)]
+ public void TryReadStandardDeviationStochast_ValidStochastConfiguration_ReturnsTrueParametersSet(bool setMean, bool setStandardDeviation)
+ {
+ // Setup
+ string filePath = Path.Combine(readerPath, "validConfiguration.xml");
+ var calculationGroup = new CalculationGroup();
+ var importer = new CalculationConfigurationImporter(filePath,
+ calculationGroup);
+
+ var configuration = new StochastConfiguration();
+
+ var random = new Random(21);
+ double mean = random.NextDouble();
+ double standardDeviation = random.NextDouble();
+ if (setMean)
+ {
+ configuration.Mean = mean;
+ }
+ if (setStandardDeviation)
+ {
+ configuration.StandardDeviation = standardDeviation;
+ }
+ var input = new TestInputWithStochasts();
+
+ // Call
+ var valid = importer.PublicTryReadStandardDeviationStochast(
+ "some stochast name",
+ "some calculation name",
+ input,
+ configuration, i => i.Distribution,
+ (i, s) => i.Distribution = s);
+
+ // Assert
+ Assert.IsTrue(valid);
+ var defaultLogNormal = new LogNormalDistribution();
+ Assert.AreEqual(
+ setMean ? mean : defaultLogNormal.Mean,
+ input.Distribution.Mean,
+ input.Distribution.Mean.GetAccuracy());
+ Assert.AreEqual(
+ setStandardDeviation ? standardDeviation : defaultLogNormal.StandardDeviation,
+ input.Distribution.StandardDeviation,
+ input.Distribution.StandardDeviation.GetAccuracy());
+ }
+
+ [Test]
+ public void TryReadStandardDeviationStochast_StochastConfigurationWithStandardDeviation_LogsErrorReturnsFalse()
+ {
+ // Setup
+ string filePath = Path.Combine(readerPath, "validConfiguration.xml");
+ var calculationGroup = new CalculationGroup();
+ var importer = new CalculationConfigurationImporter(filePath,
+ calculationGroup);
+
+ var configuration = new StochastConfiguration
+ {
+ VariationCoefficient = new Random(21).NextDouble()
+ };
+
+ var input = new TestInputWithStochasts();
+ var valid = true;
+ const string stochastName = "some stochast name";
+ const string calculationName = "some calculation name";
+
+ // Call
+ Action validate = () => valid = importer.PublicTryReadStandardDeviationStochast(
+ stochastName,
+ calculationName,
+ input, configuration,
+ i => i.Distribution,
+ (i, s) => i.Distribution = s);
+
+ // Assert
+ var expectedError = $"Indien voor parameter '{stochastName}' de spreiding wordt opgegeven, moet dit door middel van een standaardafwijking. " +
+ $"Voor berekening '{calculationName}' is een variatiecoëfficiënt gevonden. Berekening '{calculationName}' is overgeslagen.";
+ TestHelper.AssertLogMessageWithLevelIsGenerated(validate, Tuple.Create(expectedError, LogLevelConstant.Error));
+ Assert.IsFalse(valid);
+ }
+
+ [Test]
+ [TestCase(true, false)]
+ [TestCase(false, true)]
+ [TestCase(true, true)]
+ [TestCase(false, false)]
+ public void TryReadVariationCoefficientStochast_ValidStochastConfiguration_ReturnsTrueParametersSet(bool setMean, bool setVariationCoefficient)
+ {
+ // Setup
+ string filePath = Path.Combine(readerPath, "validConfiguration.xml");
+ var calculationGroup = new CalculationGroup();
+ var importer = new CalculationConfigurationImporter(filePath,
+ calculationGroup);
+
+ var configuration = new StochastConfiguration();
+
+ var random = new Random(21);
+ double mean = random.NextDouble();
+ double variationCoefficient = random.NextDouble();
+ if (setMean)
+ {
+ configuration.Mean = mean;
+ }
+ if (setVariationCoefficient)
+ {
+ configuration.VariationCoefficient = variationCoefficient;
+ }
+ var input = new TestInputWithStochasts();
+
+ // Call
+ var valid = importer.PublicTryReadVariationCoefficientStochast(
+ "some stochast name",
+ "some calculation name",
+ input, configuration,
+ i => i.VariationCoefficientDistribution,
+ (i, s) => i.VariationCoefficientDistribution = s);
+
+ // Assert
+ Assert.IsTrue(valid);
+ var defaultLogNormal = new VariationCoefficientLogNormalDistribution();
+ Assert.AreEqual(
+ setMean ? mean : defaultLogNormal.Mean,
+ input.VariationCoefficientDistribution.Mean,
+ input.VariationCoefficientDistribution.Mean.GetAccuracy());
+ Assert.AreEqual(
+ setVariationCoefficient ? variationCoefficient : defaultLogNormal.CoefficientOfVariation,
+ input.VariationCoefficientDistribution.CoefficientOfVariation,
+ input.VariationCoefficientDistribution.CoefficientOfVariation.GetAccuracy());
+ }
+
+ [Test]
+ public void TryReadVariationCoefficientStochast_StochastConfigurationWithStandardDeviation_LogsErrorReturnsFalse()
+ {
+ // Setup
+ string filePath = Path.Combine(readerPath, "validConfiguration.xml");
+ var calculationGroup = new CalculationGroup();
+ var importer = new CalculationConfigurationImporter(filePath,
+ calculationGroup);
+
+ var configuration = new StochastConfiguration
+ {
+ StandardDeviation = new Random(21).NextDouble()
+ };
+
+ var input = new TestInputWithStochasts();
+ var valid = true;
+ const string stochastName = "some stochast name";
+ const string calculationName = "some calculation name";
+
+ // Call
+ Action validate = () => valid = importer.PublicTryReadVariationCoefficientStochast(
+ stochastName,
+ calculationName,
+ input, configuration,
+ i => i.VariationCoefficientDistribution,
+ (i, s) => i.VariationCoefficientDistribution = s);
+
+ // Assert
+ var expectedError = $"Indien voor parameter '{stochastName}' de spreiding wordt opgegeven, moet dit door middel van een variatiecoëfficiënt. " +
+ $"Voor berekening '{calculationName}' is een standaardafwijking gevonden. Berekening '{calculationName}' is overgeslagen.";
+ TestHelper.AssertLogMessageWithLevelIsGenerated(validate, Tuple.Create(expectedError, LogLevelConstant.Error));
+ Assert.IsFalse(valid);
+ }
+
private class CalculationConfigurationImporter : CalculationConfigurationImporter
{
public CalculationConfigurationImporter(string filePath, CalculationGroup importTarget)
@@ -730,6 +897,30 @@
return TryReadStructure(locationName, calculationName, structures, out location);
}
+ public bool PublicTryReadStandardDeviationStochast(
+ string stochastName,
+ string calculationName,
+ TestInputWithStochasts input,
+ StochastConfiguration stochastConfiguration,
+ Func getStochast,
+ Action setStochast)
+ where TDistribution : IDistribution
+ {
+ return TryReadStandardDeviationStochast(stochastName, calculationName, input, stochastConfiguration, getStochast, setStochast);
+ }
+
+ public bool PublicTryReadVariationCoefficientStochast(
+ string stochastName,
+ string calculationName,
+ TestInputWithStochasts input,
+ StochastConfiguration stochastConfiguration,
+ Func getStochast,
+ Action setStochast)
+ where TDistribution : IVariationCoefficientDistribution
+ {
+ return TryReadVariationCoefficientStochast(stochastName, calculationName, input, stochastConfiguration, getStochast, setStochast);
+ }
+
protected override CalculationConfigurationReader CreateCalculationConfigurationReader(string xmlFilePath)
{
return new CalculationConfigurationReader(xmlFilePath);
@@ -886,5 +1077,17 @@
}
}
}
+
+ private class TestInputWithStochasts : Observable, ICalculationInput
+ {
+ public TestInputWithStochasts()
+ {
+ Distribution = new LogNormalDistribution();
+ VariationCoefficientDistribution = new VariationCoefficientLogNormalDistribution();
+ }
+
+ public IDistribution Distribution { get; set; }
+ public IVariationCoefficientDistribution VariationCoefficientDistribution { get; set; }
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj
===================================================================
diff -u -reeac9fe0e250075e6e95683e4781b7b96ddc178c -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision eeac9fe0e250075e6e95683e4781b7b96ddc178c)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/Ringtoets.Common.IO.Test.csproj (.../Ringtoets.Common.IO.Test.csproj) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -159,6 +159,10 @@
{4843d6e5-066f-4795-94f5-1d53932dd03c}
Ringtoets.Common.Data.TestUtil
+
+ {D24FA2F7-28A7-413B-AFD3-EE10E985630B}
+ Ringtoets.Common.Forms.TestUtil
+
{33508D7C-1602-4C0D-8503-73AAE98C19E5}
Ringtoets.Common.IO.TestUtil
Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs
===================================================================
diff -u -r5f489223b4d730eec42acd55533dd012d10dd1ca -rb574376e8d2b485ff320504841723923c1e41331
--- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision 5f489223b4d730eec42acd55533dd012d10dd1ca)
+++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.IO/Configurations/HeightStructuresCalculationConfigurationImporter.cs (.../HeightStructuresCalculationConfigurationImporter.cs) (revision b574376e8d2b485ff320504841723923c1e41331)
@@ -22,16 +22,13 @@
using System;
using System.Collections.Generic;
using Core.Common.Base.Data;
-using log4net;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.Hydraulics;
-using Ringtoets.Common.Data.Probabilistics;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.IO.Configurations;
using Ringtoets.Common.IO.Configurations.Helpers;
using Ringtoets.Common.IO.FileImporters;
-using Ringtoets.Common.IO.Properties;
using Ringtoets.Common.IO.Schema;
using Ringtoets.HeightStructures.Data;
using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
@@ -120,55 +117,52 @@
}
return TryReadStandardDeviationStochast(
- calculation.Name,
HeightStructuresConfigurationSchemaIdentifiers.LevelCrestStructureStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.LevelCrestStructure,
- i => i.LevelCrestStructure,
- (i, d) => i.LevelCrestStructure = d)
+ i => i.LevelCrestStructure, (i, d) => i.LevelCrestStructure = d)
&& TryReadStandardDeviationStochast(
- calculation.Name,
ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName,
- calculation.InputParameters, readCalculation.AllowedLevelIncreaseStorage,
- i => i.AllowedLevelIncreaseStorage,
- (i, d) => i.AllowedLevelIncreaseStorage = d)
- && TryReadStandardDeviationStochast(
calculation.Name,
- ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName,
- calculation.InputParameters, readCalculation.FlowWidthAtBottomProtection,
- i => i.FlowWidthAtBottomProtection,
- (i, d) => i.FlowWidthAtBottomProtection = d)
+ calculation.InputParameters,
+ readCalculation.AllowedLevelIncreaseStorage,
+ i => i.AllowedLevelIncreaseStorage, (i, d) => i.AllowedLevelIncreaseStorage = d)
&& TryReadStandardDeviationStochast(
+ ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName,
calculation.Name,
- ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName,
- calculation.InputParameters, readCalculation.ModelFactorSuperCriticalFlow,
- i => i.ModelFactorSuperCriticalFlow,
- (i, d) => i.ModelFactorSuperCriticalFlow = d)
+ calculation.InputParameters,
+ readCalculation.FlowWidthAtBottomProtection,
+ i => i.FlowWidthAtBottomProtection, (i, d) => i.FlowWidthAtBottomProtection = d)
&& TryReadStandardDeviationStochast(
+ ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName,
calculation.Name,
+ calculation.InputParameters,
+ readCalculation.ModelFactorSuperCriticalFlow,
+ i => i.ModelFactorSuperCriticalFlow, (i, d) => i.ModelFactorSuperCriticalFlow = d)
+ && TryReadStandardDeviationStochast(
ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName,
- calculation.InputParameters, readCalculation.WidthFlowApertures,
- i => i.WidthFlowApertures, (i, d) => i.WidthFlowApertures = d)
- && TryReadVariationCoefficientStochast(
calculation.Name,
- ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName,
- calculation.InputParameters, readCalculation.CriticalOvertoppingDischarge,
- i => i.CriticalOvertoppingDischarge,
- (i, d) => i.CriticalOvertoppingDischarge = d)
+ calculation.InputParameters,
+ readCalculation.WidthFlowApertures, i => i.WidthFlowApertures, (i, d) => i.WidthFlowApertures = d)
&& TryReadVariationCoefficientStochast(
+ ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName,
calculation.Name,
+ calculation.InputParameters,
+ readCalculation.CriticalOvertoppingDischarge,
+ i => i.CriticalOvertoppingDischarge, (i, d) => i.CriticalOvertoppingDischarge = d)
+ && TryReadVariationCoefficientStochast(
ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.StorageStructureArea,
- i => i.StorageStructureArea,
- (i, d) => i.StorageStructureArea = d)
+ i => i.StorageStructureArea, (i, d) => i.StorageStructureArea = d)
&& TryReadVariationCoefficientStochast(
- calculation.Name,
ConfigurationSchemaIdentifiers.StormDurationStochastName,
+ calculation.Name,
calculation.InputParameters,
readCalculation.StormDuration,
- i => i.StormDuration,
- (i, d) => i.StormDuration = d);
+ i => i.StormDuration, (i, d) => i.StormDuration = d);
}
///