Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationStochastAssignerTest.cs =================================================================== diff -u -r1a0da06a973d48c83dff8ccb8b92cdc4810b83a0 -r7487c5762780fee9a52bb2d6e0090d762054f799 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationStochastAssignerTest.cs (.../HeightStructuresCalculationStochastAssignerTest.cs) (revision 1a0da06a973d48c83dff8ccb8b92cdc4810b83a0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.IO.Test/Configurations/HeightStructuresCalculationStochastAssignerTest.cs (.../HeightStructuresCalculationStochastAssignerTest.cs) (revision 7487c5762780fee9a52bb2d6e0090d762054f799) @@ -19,8 +19,11 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Collections.Generic; using NUnit.Framework; using Ringtoets.Common.Data.Structures; +using Ringtoets.Common.IO.Configurations; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.IO.Configurations; @@ -29,12 +32,68 @@ [TestFixture] public class HeightStructuresCalculationStochastAssignerTest { + private static IEnumerable GetSetStochastParametersActions(string testNameFormat) + { + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.LevelCrestStructure = s, "LevelCrest", testNameFormat)) + { + yield return caseData; + } + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.AllowedLevelIncreaseStorage = s, "AllowedLevelIncreaseStorage", testNameFormat)) + { + yield return caseData; + } + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.FlowWidthAtBottomProtection = s, "FlowWidthAtBottomProtection", testNameFormat)) + { + yield return caseData; + } + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.WidthFlowApertures = s, "WidthFlowApertures", testNameFormat)) + { + yield return caseData; + } + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.CriticalOvertoppingDischarge = s, "CriticalOvertoppingDischarge", testNameFormat)) + { + yield return caseData; + } + foreach (TestCaseData caseData in ThreeParameterCase((c, s) => c.StorageStructureArea = s, "StorageStructureArea", testNameFormat)) + { + yield return caseData; + } + } + + private static IEnumerable ThreeParameterCase( + Action setStochastAction, + string stochastName, + string testNameFormat) + { + var random = new Random(21); + + yield return new TestCaseData( + new Action(c => setStochastAction(c, new StochastConfiguration + { + Mean = random.NextDouble() + }))) + .SetName(string.Format(testNameFormat, $"{stochastName}Mean")); + + yield return new TestCaseData( + new Action(c => setStochastAction(c, new StochastConfiguration + { + StandardDeviation = random.NextDouble() + }))) + .SetName(string.Format(testNameFormat, $"{stochastName}StandardDeviation")); + + yield return new TestCaseData( + new Action(c => setStochastAction(c, new StochastConfiguration + { + VariationCoefficient = random.NextDouble() + }))) + .SetName(string.Format(testNameFormat, $"{stochastName}VariationCoefficient")); + } + [Test] public void Constructor_WithParameters_ReturnsNewInstance() { // Setup var configuration = new HeightStructuresCalculationConfiguration("name"); - var calculation = new StructuresCalculation(); // Call @@ -48,14 +107,141 @@ Assert.NotNull(assigner); } - private static bool StandardDeviationStochastSetter( - HeightStructuresCalculationStochastAssigner.StandardDeviationDefinition definition) + [Test] + [TestCaseSource( + typeof(HeightStructuresCalculationStochastAssignerTest), + nameof(GetSetStochastParametersActions), + new object[] + { + "AreStochastsValid_WithoutStructureValueSetFor{0}_ReturnsFalse" + })] + public void AreStochastsValid_WithoutStructureParametersDefinedForStructureDependentStochats_ReturnsFalse( + Action modify) { + // Setup + var configuration = new HeightStructuresCalculationConfiguration("name"); + modify(configuration); + + var calculation = new StructuresCalculation(); + + var assigner = new HeightStructuresCalculationStochastAssigner( + configuration, + calculation, + StandardDeviationStochastSetter, + VariationCoefficientStochastSetter); + + // Call + var valid = assigner.AreStochastsValid(); + + // Assert + Assert.IsFalse(valid); + } + + [Test] + [TestCaseSource( + typeof(HeightStructuresCalculationStochastAssignerTest), + nameof(GetSetStochastParametersActions), + new object[] + { + "AreStochastsValid_WithStructureValueSetFor{0}_ReturnsTrue" + })] + public void AreStochastsValid_WithStructureParametersDefinedForStructureDependentStochats_ReturnsTrue( + Action modify) + { + // Setup + var configuration = new HeightStructuresCalculationConfiguration("name") + { + StructureName = "some structure" + }; + modify(configuration); + + var calculation = new StructuresCalculation(); + + var assigner = new HeightStructuresCalculationStochastAssigner( + configuration, + calculation, + StandardDeviationStochastSetter, + VariationCoefficientStochastSetter); + + // Call + var valid = assigner.AreStochastsValid(); + + // Assert + Assert.IsTrue(valid); + } + + [Test] + public void SetStochasts_WithAllStochastsSet_SetExpectedValuesOnInput() + { + // Setup + var levelCrestStructure = new StochastConfiguration + { + Mean = 1.1, + StandardDeviation = 1.5 + }; + + var configuration = new HeightStructuresCalculationConfiguration("name") + { + StructureName = "some structure", + LevelCrestStructure = levelCrestStructure, + AllowedLevelIncreaseStorage = new StochastConfiguration + { + Mean = 2.1, + StandardDeviation = 2.5 + }, + FlowWidthAtBottomProtection = new StochastConfiguration + { + Mean = 3.1, + StandardDeviation = 3.5 + }, + WidthFlowApertures = new StochastConfiguration + { + Mean = 4.1, + StandardDeviation = 4.5 + }, + ModelFactorSuperCriticalFlow = new StochastConfiguration + { + Mean = 5.1, + StandardDeviation = 5.5 + }, + CriticalOvertoppingDischarge = new StochastConfiguration + { + Mean = 6.1, + VariationCoefficient = 0.6 + }, + StorageStructureArea = new StochastConfiguration + { + Mean = 7.1, + VariationCoefficient = 0.7 + }, + StormDuration = new StochastConfiguration + { + Mean = 8.1, + VariationCoefficient = 0.8 + } + }; + + var calculation = new StructuresCalculation(); + + var assigner = new HeightStructuresCalculationStochastAssigner( + configuration, + calculation, + StandardDeviationStochastSetter, + VariationCoefficientStochastSetter); + + // Call + var valid = assigner.SetAllStochasts(); + + // Assert + Assert.IsTrue(valid); + } + + bool StandardDeviationStochastSetter(HeightStructuresCalculationStochastAssigner.StandardDeviationDefinition definition) + { return true; } - private static bool VariationCoefficientStochastSetter( - HeightStructuresCalculationStochastAssigner.VariationCoefficientDefinition definition) + bool VariationCoefficientStochastSetter(HeightStructuresCalculationStochastAssigner.VariationCoefficientDefinition definition) { return true; }