Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs =================================================================== diff -u -r1dc7aca66fba19cdc15c81d6b5d2d48f2625ebc0 -r787c7ef33e68750b3e1e7208f320e5b04fbf9024 --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 1dc7aca66fba19cdc15c81d6b5d2d48f2625ebc0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Service/GrassCoverErosionInwardsCalculationService.cs (.../GrassCoverErosionInwardsCalculationService.cs) (revision 787c7ef33e68750b3e1e7208f320e5b04fbf9024) @@ -468,21 +468,7 @@ private static IEnumerable ParseProfilePoints(RoughnessPoint[] roughnessProfilePoints) { - for (var i = 0; i < roughnessProfilePoints.Length; i++) - { - var roughnessProfilePoint = roughnessProfilePoints[i]; - - if (i == 0) - { - yield return new HydraRingRoughnessProfilePoint(roughnessProfilePoint.Point.X, roughnessProfilePoint.Point.Y, 1.0); - } - else - { - var precedingRoughnessProfilePoint = roughnessProfilePoints[i - 1]; - - yield return new HydraRingRoughnessProfilePoint(roughnessProfilePoint.Point.X, roughnessProfilePoint.Point.Y, precedingRoughnessProfilePoint.Roughness); - } - } + return roughnessProfilePoints.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)); } private static string[] ValidateInput(GrassCoverErosionInwardsInput inputParameters, IAssessmentSection assessmentSection) Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs =================================================================== diff -u -r950a87cfc7a4a8b266a34455dc4e79646686b964 -r787c7ef33e68750b3e1e7208f320e5b04fbf9024 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision 950a87cfc7a4a8b266a34455dc4e79646686b964) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs (.../GrassCoverErosionInwardsCalculationActivityIntegrationTest.cs) (revision 787c7ef33e68750b3e1e7208f320e5b04fbf9024) @@ -34,9 +34,14 @@ using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.IO.FileImporters; +using Ringtoets.Common.Service; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.HydraRing.Calculation.Calculator.Factory; +using Ringtoets.HydraRing.Calculation.Data; +using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics; +using Ringtoets.HydraRing.Calculation.Data.Input.Overtopping; +using Ringtoets.HydraRing.Calculation.TestUtil; using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.Integration.Data; @@ -890,6 +895,149 @@ } } + [Test] + public void Run_ValidOvertoppingCalculation_InputPropertiesCorrectlySendToService() + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile() + } + }; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + using (new HydraRingCalculatorFactoryConfig()) + { + // Call + activity.Run(); + + // Assert + var testOvertoppingCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).OvertoppingCalculator; + OvertoppingCalculationInput[] overtoppingCalculationInputs = testOvertoppingCalculator.ReceivedInputs.ToArray(); + Assert.AreEqual(1, overtoppingCalculationInputs.Length); + + OvertoppingCalculationInput actualInput = overtoppingCalculationInputs[0]; + GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; + + var input = calculation.InputParameters; + var expectedInput = new OvertoppingCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, + calculation.InputParameters.Orientation, + calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), + input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), + new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), + calculation.InputParameters.DikeHeight, + generalInput.CriticalOvertoppingModelFactor, + generalInput.FbFactor.Mean, + generalInput.FbFactor.StandardDeviation, + generalInput.FbFactor.LowerBoundary, + generalInput.FbFactor.UpperBoundary, + generalInput.FnFactor.Mean, + generalInput.FnFactor.StandardDeviation, + generalInput.FnFactor.LowerBoundary, + generalInput.FnFactor.UpperBoundary, + generalInput.OvertoppingModelFactor, + calculation.InputParameters.CriticalFlowRate.Mean, + calculation.InputParameters.CriticalFlowRate.StandardDeviation, + generalInput.FrunupModelFactor.Mean, + generalInput.FrunupModelFactor.StandardDeviation, + generalInput.FrunupModelFactor.LowerBoundary, + generalInput.FrunupModelFactor.UpperBoundary, + generalInput.FshallowModelFactor.Mean, + generalInput.FshallowModelFactor.StandardDeviation, + generalInput.FshallowModelFactor.LowerBoundary, + generalInput.FshallowModelFactor.UpperBoundary); + + HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.AreEqual(testDataPath, testOvertoppingCalculator.HydraulicBoundaryDatabaseDirectory); + Assert.AreEqual(assessmentSection.Id, testOvertoppingCalculator.RingId); + } + } + + [Test] + [TestCase(DikeHeightCalculationType.CalculateByAssessmentSectionNorm, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(AssessmentSectionNorm)")] + [TestCase(DikeHeightCalculationType.CalculateByProfileSpecificRequiredProbability, TestName = "Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(ProfileProbability)")] + public void Run_ValidDikeHeightCalculation_InputPropertiesCorrectlySendToService(DikeHeightCalculationType dikeHeightCalculationType) + { + // Setup + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + ImportHydraulicBoundaryDatabase(assessmentSection); + AddSectionToAssessmentSection(assessmentSection); + + var calculation = new GrassCoverErosionInwardsCalculation + { + InputParameters = + { + HydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(hl => hl.Id == 1300001), + DikeProfile = CreateDikeProfile(), + DikeHeightCalculationType = dikeHeightCalculationType + } + }; + + var activity = new GrassCoverErosionInwardsCalculationActivity(calculation, validFile, assessmentSection.GrassCoverErosionInwards, assessmentSection); + + using (new HydraRingCalculatorFactoryConfig()) + { + // Call + activity.Run(); + + // Assert + var dikeHeightCalculator = ((TestHydraRingCalculatorFactory) HydraRingCalculatorFactory.Instance).DikeHeightCalculator; + DikeHeightCalculationInput[] dikeHeightCalculationInputs = dikeHeightCalculator.ReceivedInputs.ToArray(); + Assert.AreEqual(1, dikeHeightCalculationInputs.Length); + + DikeHeightCalculationInput actualInput = dikeHeightCalculationInputs[0]; + GeneralGrassCoverErosionInwardsInput generalInput = assessmentSection.GrassCoverErosionInwards.GeneralInput; + + var input = calculation.InputParameters; + + var norm = dikeHeightCalculationType == DikeHeightCalculationType.CalculateByAssessmentSectionNorm + ? assessmentSection.FailureMechanismContribution.Norm + : RingtoetsCommonDataCalculationService.ProfileSpecificRequiredProbability( + assessmentSection.FailureMechanismContribution.Norm, + assessmentSection.GrassCoverErosionInwards.Contribution, + generalInput.N); + + var expectedInput = new DikeHeightCalculationInput(calculation.InputParameters.HydraulicBoundaryLocation.Id, + norm, + calculation.InputParameters.Orientation, + calculation.InputParameters.DikeGeometry.Select(roughnessPoint => new HydraRingRoughnessProfilePoint(roughnessPoint.Point.X, roughnessPoint.Point.Y, roughnessPoint.Roughness)), + input.ForeshoreGeometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), + new HydraRingBreakWater((int) input.BreakWater.Type, input.BreakWater.Height), + generalInput.CriticalOvertoppingModelFactor, + generalInput.FbFactor.Mean, + generalInput.FbFactor.StandardDeviation, + generalInput.FbFactor.LowerBoundary, + generalInput.FbFactor.UpperBoundary, + generalInput.FnFactor.Mean, + generalInput.FnFactor.StandardDeviation, + generalInput.FnFactor.LowerBoundary, + generalInput.FnFactor.UpperBoundary, + generalInput.OvertoppingModelFactor, + calculation.InputParameters.CriticalFlowRate.Mean, + calculation.InputParameters.CriticalFlowRate.StandardDeviation, + generalInput.FrunupModelFactor.Mean, + generalInput.FrunupModelFactor.StandardDeviation, + generalInput.FrunupModelFactor.LowerBoundary, + generalInput.FrunupModelFactor.UpperBoundary, + generalInput.FshallowModelFactor.Mean, + generalInput.FshallowModelFactor.StandardDeviation, + generalInput.FshallowModelFactor.LowerBoundary, + generalInput.FshallowModelFactor.UpperBoundary); + + HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); + Assert.AreEqual(testDataPath, dikeHeightCalculator.HydraulicBoundaryDatabaseDirectory); + Assert.AreEqual(assessmentSection.Id, dikeHeightCalculator.RingId); + } + } + private static void AddSectionToAssessmentSection(AssessmentSection assessmentSection) { assessmentSection.GrassCoverErosionInwards.AddSection(new FailureMechanismSection("test section", new[] Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj =================================================================== diff -u -r6a5d7b40b7ba4dcb73e393075338352d194e97c2 -r787c7ef33e68750b3e1e7208f320e5b04fbf9024 --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj) (revision 6a5d7b40b7ba4dcb73e393075338352d194e97c2) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Integration.Test/Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Integration.Test.csproj) (revision 787c7ef33e68750b3e1e7208f320e5b04fbf9024) @@ -104,6 +104,10 @@ {52BA7627-CBAB-4209-BE77-3B5F31378277} Ringtoets.Common.IO + + {D951D6DA-FE83-4920-9FDB-63BF96480B54} + Ringtoets.Common.Service + {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/HydraRingDataEqualityHelper.cs =================================================================== diff -u -r92ce01ec6a2ac8d64f77a2a618c6b6e410a78812 -r787c7ef33e68750b3e1e7208f320e5b04fbf9024 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/HydraRingDataEqualityHelper.cs (.../HydraRingDataEqualityHelper.cs) (revision 92ce01ec6a2ac8d64f77a2a618c6b6e410a78812) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.Calculation.TestUtil/HydraRingDataEqualityHelper.cs (.../HydraRingDataEqualityHelper.cs) (revision 787c7ef33e68750b3e1e7208f320e5b04fbf9024) @@ -23,6 +23,8 @@ using NUnit.Framework; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Input; +using Ringtoets.HydraRing.Calculation.Data.Input.Hydraulics; +using Ringtoets.HydraRing.Calculation.Data.Input.Overtopping; using Ringtoets.HydraRing.Calculation.Data.Input.Structures; using Ringtoets.HydraRing.Calculation.Data.Input.WaveConditions; using Ringtoets.HydraRing.Calculation.Data.Variables; @@ -41,6 +43,52 @@ /// /// The expected calculation input. /// The actual calculation input. + public static void AreEqual(OvertoppingCalculationInput expectedInput, OvertoppingCalculationInput actualInput) + { + Assert.AreEqual(expectedInput.FailureMechanismType, actualInput.FailureMechanismType); + Assert.AreEqual(expectedInput.CalculationTypeId, actualInput.CalculationTypeId); + Assert.AreEqual(expectedInput.VariableId, actualInput.VariableId); + Assert.AreEqual(expectedInput.HydraulicBoundaryLocationId, actualInput.HydraulicBoundaryLocationId); + Assert.AreEqual(expectedInput.Section.SectionId, actualInput.Section.SectionId); + + Assert.AreEqual(expectedInput.Beta, actualInput.Beta, accuracy); + Assert.AreEqual(expectedInput.Section.CrossSectionNormal, actualInput.Section.CrossSectionNormal, accuracy); + + AreEqual(expectedInput.BreakWater, actualInput.BreakWater); + AreEqual(expectedInput.Section, actualInput.Section); + AreEqual(expectedInput.ProfilePoints.ToArray(), actualInput.ProfilePoints.ToArray()); + AreEqual(expectedInput.ForelandsPoints.ToArray(), actualInput.ForelandsPoints.ToArray()); + AreEqual(expectedInput.Variables.ToArray(), actualInput.Variables.ToArray()); + } + + /// + /// Asserts whether or not and are equal to eachother. + /// + /// The expected calculation input. + /// The actual calculation input. + public static void AreEqual(DikeHeightCalculationInput expectedInput, DikeHeightCalculationInput actualInput) + { + Assert.AreEqual(expectedInput.FailureMechanismType, actualInput.FailureMechanismType); + Assert.AreEqual(expectedInput.CalculationTypeId, actualInput.CalculationTypeId); + Assert.AreEqual(expectedInput.VariableId, actualInput.VariableId); + Assert.AreEqual(expectedInput.HydraulicBoundaryLocationId, actualInput.HydraulicBoundaryLocationId); + Assert.AreEqual(expectedInput.Section.SectionId, actualInput.Section.SectionId); + + Assert.AreEqual(expectedInput.Beta, actualInput.Beta, accuracy); + Assert.AreEqual(expectedInput.Section.CrossSectionNormal, actualInput.Section.CrossSectionNormal, accuracy); + + AreEqual(expectedInput.BreakWater, actualInput.BreakWater); + AreEqual(expectedInput.Section, actualInput.Section); + AreEqual(expectedInput.ProfilePoints.ToArray(), actualInput.ProfilePoints.ToArray()); + AreEqual(expectedInput.ForelandsPoints.ToArray(), actualInput.ForelandsPoints.ToArray()); + AreEqual(expectedInput.Variables.ToArray(), actualInput.Variables.ToArray()); + } + + /// + /// Asserts whether or not and are equal to eachother. + /// + /// The expected calculation input. + /// The actual calculation input. public static void AreEqual(WaveConditionsCosineCalculationInput expectedInput, HydraRingCalculationInput actualInput) { Assert.AreEqual(expectedInput.FailureMechanismType, actualInput.FailureMechanismType); @@ -159,6 +207,18 @@ Assert.AreEqual(expectedSection.SectionId, actualSection.SectionId); } + private static void AreEqual(HydraRingProfilePoint[] expectedProfilePoints, HydraRingProfilePoint[] actualProfilePoints) + { + Assert.AreEqual(expectedProfilePoints.Length, actualProfilePoints.Length); + + for (int i = 0; i < expectedProfilePoints.Length; i++) + { + Assert.AreEqual(expectedProfilePoints[i].X, actualProfilePoints[i].X, accuracy); + Assert.AreEqual(expectedProfilePoints[i].Z, actualProfilePoints[i].Z, accuracy); + Assert.AreEqual(expectedProfilePoints[i].Roughness, actualProfilePoints[i].Roughness, accuracy); + } + } + private static void AreEqual(HydraRingForelandPoint[] expectedForelandPoints, HydraRingForelandPoint[] actualForelandPoints) { Assert.AreEqual(expectedForelandPoints.Length, actualForelandPoints.Length);