Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsWaveConditionsCalculationServiceTest.cs =================================================================== diff -u -re56b96f63d7f5098e36566ea556f45af5c142320 -r6a0cc80559d1f5dd0476dbe7eba4865cc158e93f --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsWaveConditionsCalculationServiceTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationServiceTest.cs) (revision e56b96f63d7f5098e36566ea556f45af5c142320) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/GrassCoverErosionOutwardsWaveConditionsCalculationServiceTest.cs (.../GrassCoverErosionOutwardsWaveConditionsCalculationServiceTest.cs) (revision 6a0cc80559d1f5dd0476dbe7eba4865cc158e93f) @@ -24,7 +24,6 @@ using System.Linq; using Core.Common.Base.Data; using Core.Common.TestUtil; -using Core.Common.Utils; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; @@ -42,6 +41,7 @@ using Ringtoets.HydraRing.Calculation.TestUtil.Calculator; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.Service; +using Ringtoets.Revetment.TestUtil; namespace Ringtoets.GrassCoverErosionOutwards.Service.Test { @@ -823,37 +823,21 @@ WaveConditionsOutput[] waveConditionsOutputs = calculation.Output.Items.ToArray(); Assert.AreEqual(3, waveConditionsOutputs.Length); - double targetNorm = TargetNorm(assessmentSectionStub, failureMechanism); - AssertFailedCalculationOutput(waterLevelUpperBoundaryRevetment, targetNorm, waveConditionsOutputs[0]); + double targetNorm = CalculateTargetNorm(assessmentSectionStub.FailureMechanismContribution.Norm, + failureMechanismContribution, + failureMechanism.GeneralInput.N); + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevelUpperBoundaryRevetment, + targetNorm, + waveConditionsOutputs[0]); } mockRepository.VerifyAll(); } - private static double TargetNorm(IAssessmentSection assessmentSectionStub, GrassCoverErosionOutwardsFailureMechanism failureMechanism) + private static double CalculateTargetNorm(double norm, double contribution, int N) { - return assessmentSectionStub.FailureMechanismContribution.Norm - * (failureMechanism.Contribution / 100) - / failureMechanism.GeneralInput.N; + return norm * (contribution / 100) / N; } - private static void AssertFailedCalculationOutput(double waterLevel, double targetNorm, WaveConditionsOutput actual) - { - double targetReliability = StatisticsConverter.ProbabilityToReliability(targetNorm); - double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); - - Assert.IsNotNull(actual); - Assert.AreEqual(waterLevel, actual.WaterLevel, actual.WaterLevel.GetAccuracy()); - Assert.IsNaN(actual.WaveHeight); - Assert.IsNaN(actual.WavePeakPeriod); - Assert.IsNaN(actual.WaveAngle); - Assert.IsNaN(actual.WaveDirection); - Assert.AreEqual(targetProbability, actual.TargetProbability); - Assert.AreEqual(targetReliability, actual.TargetReliability, actual.TargetReliability.GetAccuracy()); - Assert.IsNaN(actual.CalculatedProbability); - Assert.IsNaN(actual.CalculatedReliability); - Assert.AreEqual(CalculationConvergence.CalculatedNotConverged, actual.CalculationConvergence); - } - private static GrassCoverErosionOutwardsWaveConditionsCalculation GetValidCalculation() { var calculation = new GrassCoverErosionOutwardsWaveConditionsCalculation Index: Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/Ringtoets.GrassCoverErosionOutwards.Service.Test.csproj =================================================================== diff -u -re56b96f63d7f5098e36566ea556f45af5c142320 -r6a0cc80559d1f5dd0476dbe7eba4865cc158e93f --- Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/Ringtoets.GrassCoverErosionOutwards.Service.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Service.Test.csproj) (revision e56b96f63d7f5098e36566ea556f45af5c142320) +++ Ringtoets/GrassCoverErosionOutwards/test/Ringtoets.GrassCoverErosionOutwards.Service.Test/Ringtoets.GrassCoverErosionOutwards.Service.Test.csproj (.../Ringtoets.GrassCoverErosionOutwards.Service.Test.csproj) (revision 6a0cc80559d1f5dd0476dbe7eba4865cc158e93f) @@ -71,10 +71,6 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base - - {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} - Core.Common.Utils - {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil @@ -111,6 +107,10 @@ {2331235f-1e56-4344-acc2-191c22a39594} Ringtoets.Revetment.Service + + {3706200E-48C6-4B86-B48C-4E45C69ABE95} + Ringtoets.Revetment.Data.TestUtil + {E7225477-577F-4A17-B7EC-6721158E1543} Ringtoets.GrassCoverErosionOutwards.Data Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/Ringtoets.Revetment.Data.TestUtil.Test.csproj =================================================================== diff -u -rec15ff35b39f333c422b8ca6988c34bd8573f134 -r6a0cc80559d1f5dd0476dbe7eba4865cc158e93f --- Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/Ringtoets.Revetment.Data.TestUtil.Test.csproj (.../Ringtoets.Revetment.Data.TestUtil.Test.csproj) (revision ec15ff35b39f333c422b8ca6988c34bd8573f134) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/Ringtoets.Revetment.Data.TestUtil.Test.csproj (.../Ringtoets.Revetment.Data.TestUtil.Test.csproj) (revision 6a0cc80559d1f5dd0476dbe7eba4865cc158e93f) @@ -52,6 +52,7 @@ + @@ -64,6 +65,10 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/WaveConditionsOutputTestHelperTest.cs =================================================================== diff -u --- Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/WaveConditionsOutputTestHelperTest.cs (revision 0) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil.Test/WaveConditionsOutputTestHelperTest.cs (revision 6a0cc80559d1f5dd0476dbe7eba4865cc158e93f) @@ -0,0 +1,296 @@ +// 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 Core.Common.Utils; +using NUnit.Framework; +using Ringtoets.Common.Data.Hydraulics; +using Ringtoets.Revetment.Data; + +namespace Ringtoets.Revetment.TestUtil.Test +{ + [TestFixture] + public class WaveConditionsOutputTestHelperTest + { + [Test] + public void AssertFailedOutput_AllValuesMatch_DoesNotThrowException() + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); + + var output = new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + CalculationConvergence.CalculatedNotConverged); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void AssertFailedOutput_ActualOutputNull_ThrowsAssertionException() + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertFailedOutput_DifferentWaterLevel_ThrowsAssertionException() + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); + + var output = new WaveConditionsOutput(waterLevel + random.NextDouble(), + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + CalculationConvergence.CalculatedNotConverged); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertFailedOutput_DifferentTargetProbability_ThrowsAssertionException() + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + + var output = new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + random.NextDouble(), + targetReliability, + double.NaN, + double.NaN, + CalculationConvergence.CalculatedNotConverged); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.Throws(call); + } + + [Test] + public void AssertFailedOutput_DifferentTargetReliability_ThrowsAssertionException() + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); + + var output = new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability + random.NextDouble(), + double.NaN, + double.NaN, + CalculationConvergence.CalculatedNotConverged); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCase(CalculationConvergence.CalculatedConverged)] + [TestCase(CalculationConvergence.NotCalculated)] + public void AssertFailedOutput_DifferentCalculationConvergence_ThrowsAssertionException( + CalculationConvergence convergence) + { + // Setup + var random = new Random(21); + double norm = random.NextDouble(); + double waterLevel = random.NextDouble(); + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); + + var output = new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + convergence); + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.Throws(call); + } + + [Test] + [TestCaseSource(nameof(GetVariousWaveConditionsOutputs))] + public void AssertFailedOutput_PropertyHasDifferentValue_ThrowsAssertionException( + WaveConditionsOutput output) + { + // Setup + const double waterLevel = 0.7; + const double norm = 0.5; + + // Call + TestDelegate call = () => + WaveConditionsOutputTestHelper.AssertFailedOutput(waterLevel, norm, output); + + // Assert + Assert.Throws(call); + } + + private static IEnumerable GetVariousWaveConditionsOutputs() + { + const double waterLevel = 0.7; + const double norm = 0.5; + const CalculationConvergence convergence = CalculationConvergence.CalculatedNotConverged; + + double targetReliability = StatisticsConverter.ProbabilityToReliability(norm); + double targetProbability = StatisticsConverter.ReliabilityToProbability(targetReliability); + + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + 1, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + convergence)) + .SetName("WaveHeightDifferent"); + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + double.NaN, + 2, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + convergence)) + .SetName("WavePeakPeriodDifferent"); + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + 3, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + convergence)) + .SetName("WaveAngleDifferent"); + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + 4, + targetProbability, + targetReliability, + double.NaN, + double.NaN, + convergence)) + .SetName("DifferentWaveDirection"); + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + 0.5, + double.NaN, + convergence)) + .SetName("CalculatedProbabilityDifferent"); + yield return new TestCaseData(new WaveConditionsOutput(waterLevel, + double.NaN, + double.NaN, + double.NaN, + double.NaN, + targetProbability, + targetReliability, + double.NaN, + 6, + convergence)) + .SetName("CalculatedReliabilityDifferent"); + } + } +} \ No newline at end of file Index: Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/Ringtoets.Revetment.Data.TestUtil.csproj =================================================================== diff -u -r6c049c504e7f599a8cebb26ae37fcd82b03782f2 -r6a0cc80559d1f5dd0476dbe7eba4865cc158e93f --- Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/Ringtoets.Revetment.Data.TestUtil.csproj (.../Ringtoets.Revetment.Data.TestUtil.csproj) (revision 6c049c504e7f599a8cebb26ae37fcd82b03782f2) +++ Ringtoets/Revetment/test/Ringtoets.Revetment.Data.TestUtil/Ringtoets.Revetment.Data.TestUtil.csproj (.../Ringtoets.Revetment.Data.TestUtil.csproj) (revision 6a0cc80559d1f5dd0476dbe7eba4865cc158e93f) @@ -38,6 +38,10 @@ pdbonly + + ..\..\..\..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll + True + @@ -48,16 +52,25 @@ + {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + {87c2c553-c0bc-40bf-b1ea-b83bff357f27} Ringtoets.Revetment.Data @@ -67,6 +80,7 @@ Copying.licenseheader +