Index: Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs =================================================================== diff -u -r5ddc9c8c424e9a85e22bde50f7133111cbf16348 -r14708ad2bb047af38e5cdafb60946ed51c6462e5 --- Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs (.../AggregatedHydraulicBoundaryLocationFactoryTest.cs) (revision 5ddc9c8c424e9a85e22bde50f7133111cbf16348) +++ Ringtoets/Common/test/Ringtoets.Common.Util.Test/AggregatedHydraulicBoundaryLocationFactoryTest.cs (.../AggregatedHydraulicBoundaryLocationFactoryTest.cs) (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -118,10 +118,10 @@ } private static RoundedDouble GetExpectedResult(IEnumerable calculationList, - HydraulicBoundaryLocation hydraulicBoundaryLocation1) + HydraulicBoundaryLocation hydraulicBoundaryLocation) { return calculationList - .Where(calculation => calculation.HydraulicBoundaryLocation.Equals(hydraulicBoundaryLocation1)) + .Where(calculation => calculation.HydraulicBoundaryLocation.Equals(hydraulicBoundaryLocation)) .Select(calculation => calculation.Output.Result) .Single(); } Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.cs (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -0,0 +1,110 @@ +// 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 System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.GrassCoverErosionOutwards.Data; + +namespace Ringtoets.GrassCoverErosionOutwards.Util +{ + /// + /// Factory for creating instances. + /// + public static class GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory + { + /// + /// Creates the grass cover erosion outwards aggregated hydraulic boundary locations based on the locations and calculations + /// from an assessment section and failure mechanism. + /// + /// The assessment section to get the locations and calculations from. + /// The failure mechanism to get the calculations from. + /// An of . + /// Thrown when any parameter is null. + public static IEnumerable CreateAggregatedHydraulicBoundaryLocations( + IAssessmentSection assessmentSection, GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + Dictionary waterLevelLookupForMechanismSpecificFactorizedSignalingNorm = + failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waterLevelLookupForMechanismSpecificSignalingNorm = + failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waterLevelLookupForMechanismSpecificLowerLimitNorm = + failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waterLevelLookupForLowerLimitNorm = + assessmentSection.WaterLevelCalculationsForLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waterLevelLookupForFactorizedLowerLimitNorm = + assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + + Dictionary waveHeightLookupForMechanismSpecificFactorizedSignalingNorm = + failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waveHeightLookupForMechanismSpecificSignalingNorm = + failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waveHeightLookupForMechanismSpecificLowerLimitNorm = + failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waveHeightLookupForLowerLimitNorm = + assessmentSection.WaveHeightCalculationsForLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + Dictionary waveHeightLookupForFactorizedLowerLimitNorm = + assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm.ToDictionary(c => c.HydraulicBoundaryLocation, + c => c); + + return assessmentSection.HydraulicBoundaryDatabase.Locations + .Select(location => new GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation( + location.Id, location.Name, location.Location, + GetCalculationResult(waterLevelLookupForMechanismSpecificFactorizedSignalingNorm[location].Output), + GetCalculationResult(waterLevelLookupForMechanismSpecificSignalingNorm[location].Output), + GetCalculationResult(waterLevelLookupForMechanismSpecificLowerLimitNorm[location].Output), + GetCalculationResult(waterLevelLookupForLowerLimitNorm[location].Output), + GetCalculationResult(waterLevelLookupForFactorizedLowerLimitNorm[location].Output), + GetCalculationResult(waveHeightLookupForMechanismSpecificFactorizedSignalingNorm[location].Output), + GetCalculationResult(waveHeightLookupForMechanismSpecificSignalingNorm[location].Output), + GetCalculationResult(waveHeightLookupForMechanismSpecificLowerLimitNorm[location].Output), + GetCalculationResult(waveHeightLookupForLowerLimitNorm[location].Output), + GetCalculationResult(waveHeightLookupForFactorizedLowerLimitNorm[location].Output))).ToArray(); + } + + private static RoundedDouble GetCalculationResult(HydraulicBoundaryLocationOutput output) + { + return output?.Result ?? RoundedDouble.NaN; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/Ringtoets.GrassCoverErosionOutwards.Util.csproj =================================================================== diff -u -r752be44967f2f7c50520a6b6c18abe472ba62055 -r14708ad2bb047af38e5cdafb60946ed51c6462e5 --- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/Ringtoets.GrassCoverErosionOutwards.Util.csproj (.../Ringtoets.GrassCoverErosionOutwards.Util.csproj) (revision 752be44967f2f7c50520a6b6c18abe472ba62055) +++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Util/Ringtoets.GrassCoverErosionOutwards.Util.csproj (.../Ringtoets.GrassCoverErosionOutwards.Util.csproj) (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -12,6 +12,7 @@ + @@ -25,5 +26,15 @@ Core.Common.Base False + + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} + Ringtoets.Common.Data + False + + + {E7225477-577F-4A17-B7EC-6721158E1543} + Ringtoets.GrassCoverErosionOutwards.Data + False + \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactoryTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactoryTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactoryTest.cs (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -0,0 +1,189 @@ +// 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 System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionOutwards.Data; + +namespace Ringtoets.GrassCoverErosionOutwards.Util.Test +{ + [TestFixture] + public class GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactoryTest + { + [Test] + public void CreateAggregatedHydraulicBoundaryLocations_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations( + null, new GrassCoverErosionOutwardsFailureMechanism()); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void CreateAggregatedHydraulicBoundaryLocations_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations( + assessmentSection, null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void CreateAggregatedHydraulicBoundaryLocations_LocationsWithOutput_ReturnGrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocations() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "location1", 1, 1), true); + assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(2, "location2", 2, 2), true); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.SetHydraulicBoundaryLocationCalculations(assessmentSection.HydraulicBoundaryDatabase.Locations); + + SetOutputOnHydraulicBoundaryCalculations(failureMechanism); + + // Call + GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation[] aggregatedLocations = + GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations( + assessmentSection, failureMechanism).ToArray(); + + // Assert + HydraulicBoundaryLocation[] expectedLocations = assessmentSection.HydraulicBoundaryDatabase.Locations.ToArray(); + Assert.AreEqual(expectedLocations.Length, aggregatedLocations.Length); + + for (var i = 0; i < expectedLocations.Length; i++) + { + Assert.AreEqual(expectedLocations[i].Id, aggregatedLocations[i].Id); + Assert.AreEqual(expectedLocations[i].Name, aggregatedLocations[i].Name); + Assert.AreEqual(expectedLocations[i].Location, aggregatedLocations[i].Location); + + Assert.AreEqual(GetExpectedResult(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, expectedLocations[i]), + aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificFactorizedSignalingNorm); + Assert.AreEqual(GetExpectedResult(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, expectedLocations[i]), + aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificSignalingNorm); + Assert.AreEqual(GetExpectedResult(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaterLevelCalculationForLowerLimitNorm); + Assert.AreEqual(GetExpectedResult(assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaterLevelCalculationForFactorizedLowerLimitNorm); + + Assert.AreEqual(GetExpectedResult(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, expectedLocations[i]), + aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificFactorizedSignalingNorm); + Assert.AreEqual(GetExpectedResult(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, expectedLocations[i]), + aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificSignalingNorm); + Assert.AreEqual(GetExpectedResult(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificLowerLimitNorm); + Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaveHeightCalculationForLowerLimitNorm); + Assert.AreEqual(GetExpectedResult(assessmentSection.WaveHeightCalculationsForFactorizedLowerLimitNorm, expectedLocations[i]), + aggregatedLocations[i].WaveHeightCalculationForFactorizedLowerLimitNorm); + } + } + + [Test] + public void CreateAggregatedHydraulicBoundaryLocations_LocationsWithoutOutput_ReturnGrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocations() + { + // Setup + var assessmentSection = new ObservableTestAssessmentSectionStub(); + assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(1, "location1", 1, 1)); + assessmentSection.AddHydraulicBoundaryLocation(new HydraulicBoundaryLocation(2, "location2", 2, 2)); + + var failureMechanism = new GrassCoverErosionOutwardsFailureMechanism(); + failureMechanism.SetHydraulicBoundaryLocationCalculations(assessmentSection.HydraulicBoundaryDatabase.Locations); + + // Call + GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocation[] aggregatedLocations = + GrassCoverErosionOutwardsAggregatedHydraulicBoundaryLocationFactory.CreateAggregatedHydraulicBoundaryLocations( + assessmentSection, failureMechanism).ToArray(); + + // Assert + HydraulicBoundaryLocation[] expectedLocations = assessmentSection.HydraulicBoundaryDatabase.Locations.ToArray(); + Assert.AreEqual(expectedLocations.Length, aggregatedLocations.Length); + + for (var i = 0; i < expectedLocations.Length; i++) + { + Assert.AreEqual(expectedLocations[i].Id, aggregatedLocations[i].Id); + Assert.AreEqual(expectedLocations[i].Name, aggregatedLocations[i].Name); + Assert.AreEqual(expectedLocations[i].Location, aggregatedLocations[i].Location); + + Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificFactorizedSignalingNorm); + Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificSignalingNorm); + Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForMechanismSpecificLowerLimitNorm); + Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForLowerLimitNorm); + Assert.IsNaN(aggregatedLocations[i].WaterLevelCalculationForFactorizedLowerLimitNorm); + + Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificFactorizedSignalingNorm); + Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificSignalingNorm); + Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForMechanismSpecificLowerLimitNorm); + Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForLowerLimitNorm); + Assert.IsNaN(aggregatedLocations[i].WaveHeightCalculationForFactorizedLowerLimitNorm); + } + } + + private static void SetOutputOnHydraulicBoundaryCalculations(GrassCoverErosionOutwardsFailureMechanism failureMechanism) + { + var random = new Random(39); + + SetOutputOnCalculationsInlist(failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm, random); + SetOutputOnCalculationsInlist(failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm, random); + SetOutputOnCalculationsInlist(failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm, random); + SetOutputOnCalculationsInlist(failureMechanism.WaveHeightCalculationsForMechanismSpecificFactorizedSignalingNorm, random); + SetOutputOnCalculationsInlist(failureMechanism.WaveHeightCalculationsForMechanismSpecificSignalingNorm, random); + SetOutputOnCalculationsInlist(failureMechanism.WaveHeightCalculationsForMechanismSpecificLowerLimitNorm, random); + } + + private static void SetOutputOnCalculationsInlist(IEnumerable calculationsList, Random random) + { + foreach (HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation in calculationsList) + { + hydraulicBoundaryLocationCalculation.Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()); + } + } + + private static RoundedDouble GetExpectedResult(IEnumerable calculationList, + HydraulicBoundaryLocation hydraulicBoundaryLocation) + { + return calculationList + .Where(calculation => calculation.HydraulicBoundaryLocation.Equals(hydraulicBoundaryLocation)) + .Select(calculation => calculation.Output.Result) + .Single(); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/Ringtoets.GrassCoverErosionOutwards.Util.Test.csproj =================================================================== diff -u -r752be44967f2f7c50520a6b6c18abe472ba62055 -r14708ad2bb047af38e5cdafb60946ed51c6462e5 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/Ringtoets.GrassCoverErosionOutwards.Util.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Util.Test.csproj) (revision 752be44967f2f7c50520a6b6c18abe472ba62055) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/Ringtoets.GrassCoverErosionOutwards.Util.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Util.Test.csproj) (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -10,10 +10,14 @@ ..\..\..\..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll + + ..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll + + @@ -32,6 +36,18 @@ {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {d4200f43-3f72-4f42-af0a-8ced416a38ec} + Ringtoets.Common.Data + + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + + + {E7225477-577F-4A17-B7EC-6721158E1543} + Ringtoets.GrassCoverErosionOutwards.Data + {033ED27D-E806-42B4-9689-8150CFAE1906} Ringtoets.GrassCoverErosionOutwards.Util Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/packages.config =================================================================== diff -u -r0ca9570301ad44c327345f110b30b4ee9e539e56 -r14708ad2bb047af38e5cdafb60946ed51c6462e5 --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/packages.config (.../packages.config) (revision 0ca9570301ad44c327345f110b30b4ee9e539e56) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Util.Test/packages.config (.../packages.config) (revision 14708ad2bb047af38e5cdafb60946ed51c6462e5) @@ -1,4 +1,5 @@ - - + \ No newline at end of file