Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs =================================================================== diff -u -r7078f0ab14bab4985d611c668d73267e3a37c8d0 -r9368b3ac19481ec8b10dcea903ecdf0fab3048cf --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 7078f0ab14bab4985d611c668d73267e3a37c8d0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Service.Test/MacroStabilityInwardsCalculationServiceTest.cs (.../MacroStabilityInwardsCalculationServiceTest.cs) (revision 9368b3ac19481ec8b10dcea903ecdf0fab3048cf) @@ -22,24 +22,19 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base.Data; -using Core.Common.Base.Geometry; using Core.Common.TestUtil; using log4net.Core; using NUnit.Framework; -using Ringtoets.Common.Data.TestUtil; using Ringtoets.Common.Service.TestUtil; using Ringtoets.MacroStabilityInwards.CalculatedInput.TestUtil; using Ringtoets.MacroStabilityInwards.Data; -using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.Data.TestUtil; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Input; using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.UpliftVan.Output; using Ringtoets.MacroStabilityInwards.KernelWrapper.TestUtil.Calculators; -using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Service.Test { @@ -129,296 +124,6 @@ } [Test] - public void Validate_HydraulicBoundaryLocationNotCalculated_LogsErrorAndReturnsFalse() - { - // Setup - testCalculation.InputParameters.HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); - testCalculation.InputParameters.UseAssessmentLevelManualInput = false; - var isValid = true; - - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("Kan het toetspeil niet afleiden op basis van de invoer.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - - [Test] - [TestCase(double.NaN)] - [TestCase(double.NegativeInfinity)] - [TestCase(double.PositiveInfinity)] - public void Validate_InvalidManualAssessmentLevel_LogsErrorAndReturnsFalse(double assessmentLevel) - { - // Setup - testCalculation.InputParameters.UseAssessmentLevelManualInput = true; - testCalculation.InputParameters.AssessmentLevel = (RoundedDouble) assessmentLevel; - var isValid = true; - - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("De waarde voor 'toetspeil' moet een concreet getal zijn.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - - [Test] - public void Validate_WithoutSurfaceLine_LogsErrorAndReturnsFalse() - { - // Setup - testCalculation.InputParameters.SurfaceLine = null; - var isValid = true; - - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("Er is geen profielschematisatie geselecteerd.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - - [Test] - public void Validate_WithoutStochasticSoilProfile_LogsErrorAndReturnsFalse() - { - // Setup - testCalculation.InputParameters.StochasticSoilProfile = null; - var isValid = true; - - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("Er is geen ondergrondschematisatie geselecteerd.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - - [Test] - [TestCase(0.06)] - [TestCase(1)] - public void Validate_SoilProfile1DTopDoesNotExceedSurfaceLineTop_LogsErrorAndReturnsFalse(double differenceFromTop) - { - // Setup - const double surfaceLineTop = 5.0; - - testCalculation.Name = "Top of soil layer does not exceed top of surface line"; - - var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(1, new MacroStabilityInwardsSoilProfile1D("profile", 0.0, new[] - { - new MacroStabilityInwardsSoilLayer1D(surfaceLineTop - differenceFromTop) - })); - - var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test"); - var firstCharacteristicPointLocation = new Point3D(0.1, 0.0, 0.0); - var secondCharacteristicPointLocation = new Point3D(0.2, 0.0, 1.0); - var thirdCharacteristicPointLocation = new Point3D(0.3, 0.0, 2.0); - var fourthCharacteristicPointLocation = new Point3D(0.4, 0.0, 3.0); - var fifthCharacteristicPointLocation = new Point3D(0.5, 0.0, 4.0); - var sixthCharacteristicPointLocation = new Point3D(0.6, 0.0, surfaceLineTop); - - surfaceLine.SetGeometry(new[] - { - firstCharacteristicPointLocation, - secondCharacteristicPointLocation, - thirdCharacteristicPointLocation, - fourthCharacteristicPointLocation, - fifthCharacteristicPointLocation, - sixthCharacteristicPointLocation - }); - surfaceLine.SetSurfaceLevelOutsideAt(firstCharacteristicPointLocation); - surfaceLine.SetDikeToeAtRiverAt(secondCharacteristicPointLocation); - surfaceLine.SetDikeTopAtRiverAt(thirdCharacteristicPointLocation); - surfaceLine.SetDikeTopAtPolderAt(fourthCharacteristicPointLocation); - surfaceLine.SetDikeToeAtPolderAt(fifthCharacteristicPointLocation); - surfaceLine.SetSurfaceLevelInsideAt(sixthCharacteristicPointLocation); - - testCalculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile; - testCalculation.InputParameters.SurfaceLine = surfaceLine; - - var isValid = true; - using (new MacroStabilityInwardsCalculatorFactoryConfig()) - { - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("De ondergrondschematisatie moet boven de profielschematisatie liggen.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - } - - [Test] - [TestCase(0.05)] - [TestCase(0)] - [TestCase(-1)] - public void Validate_SoilProfile1DTopExceedsSurfaceLineTop_ReturnsTrue(double differenceFromTop) - { - // Setup - const double surfaceLineTop = 5.0; - - testCalculation.Name = "Top of soil layer < top of surface line"; - - var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(1, new MacroStabilityInwardsSoilProfile1D("profile", 0.0, new[] - { - new MacroStabilityInwardsSoilLayer1D(surfaceLineTop - differenceFromTop) - })); - - var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test"); - var firstCharacteristicPointLocation = new Point3D(0.1, 0.0, 0.0); - var secondCharacteristicPointLocation = new Point3D(0.2, 0.0, 1.0); - var thirdCharacteristicPointLocation = new Point3D(0.3, 0.0, 2.0); - var fourthCharacteristicPointLocation = new Point3D(0.4, 0.0, 3.0); - var fifthCharacteristicPointLocation = new Point3D(0.5, 0.0, 4.0); - var sixthCharacteristicPointLocation = new Point3D(0.6, 0.0, surfaceLineTop); - - surfaceLine.SetGeometry(new[] - { - firstCharacteristicPointLocation, - secondCharacteristicPointLocation, - thirdCharacteristicPointLocation, - fourthCharacteristicPointLocation, - fifthCharacteristicPointLocation, - sixthCharacteristicPointLocation - }); - surfaceLine.SetSurfaceLevelOutsideAt(firstCharacteristicPointLocation); - surfaceLine.SetDikeToeAtRiverAt(secondCharacteristicPointLocation); - surfaceLine.SetDikeTopAtRiverAt(thirdCharacteristicPointLocation); - surfaceLine.SetDikeTopAtPolderAt(fourthCharacteristicPointLocation); - surfaceLine.SetDikeToeAtPolderAt(fifthCharacteristicPointLocation); - surfaceLine.SetSurfaceLevelInsideAt(sixthCharacteristicPointLocation); - - testCalculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile; - testCalculation.InputParameters.SurfaceLine = surfaceLine; - - var isValid = false; - using (new MacroStabilityInwardsCalculatorFactoryConfig()) - { - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(2, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); - }); - Assert.IsTrue(isValid); - } - } - - [Test] - [TestCaseSource(nameof(SurfacelineNotOnMacroStabilityInwardsSoilProfile2D))] - public void Validate_SurfaceLineNotNear2DProfile_LogsErrorAndReturnsFalse(MacroStabilityInwardsSoilProfile2D soilProfile) - { - // Setup - testCalculation.Name = "calculation name"; - - var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test"); - surfaceLine.SetGeometry(new[] - { - new Point3D(0, 0.0, 10), - new Point3D(1, 0.0, 20), - new Point3D(2, 0.0, 10) - }); - - testCalculation.InputParameters.StochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.0, - soilProfile); - testCalculation.InputParameters.SurfaceLine = surfaceLine; - - var isValid = true; - using (new MacroStabilityInwardsCalculatorFactoryConfig()) - { - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(3, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - Assert.AreEqual("De profielschematisatie moet op de ondergrondschematisatie liggen.", msgs[1]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); - }); - Assert.IsFalse(isValid); - } - } - - [Test] - [TestCaseSource(nameof(SurfaceLineOnMacroStabilityInwardsSoilProfile2D))] - public void Validate_SurfaceLineNear2DProfile_ReturnsTrue(MacroStabilityInwardsSoilProfile2D soilProfile) - { - // Setup - testCalculation.Name = "calculation name"; - - var surfaceLine = new MacroStabilityInwardsSurfaceLine("Test"); - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 0.0, 10), - new Point3D(0.1, 0.0, 20), - new Point3D(0.2, 0.0, 10) - }); - - testCalculation.InputParameters.StochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.0, - soilProfile); - testCalculation.InputParameters.SurfaceLine = surfaceLine; - - var isValid = false; - using (new MacroStabilityInwardsCalculatorFactoryConfig()) - { - // Call - Action call = () => isValid = MacroStabilityInwardsCalculationService.Validate(testCalculation); - - // Assert - TestHelper.AssertLogMessages(call, messages => - { - string[] msgs = messages.ToArray(); - Assert.AreEqual(2, msgs.Length); - CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); - CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); - }); - Assert.IsTrue(isValid); - } - } - - [Test] public void Validate_KernelReturnsValidationError_LogsErrorAndReturnsFalse() { // Setup @@ -847,200 +552,6 @@ } } - private static IEnumerable SurfacelineNotOnMacroStabilityInwardsSoilProfile2D() - { - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(1, -20), - new Point2D(2, 10), - new Point2D(1, -20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, -10.0), - new Point2D(1, -20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point way too high"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(1, 20), - new Point2D(2, 10), - new Point2D(1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, 100.0), - new Point2D(1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point way too low"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(1, 200), - new Point2D(2, 100), - new Point2D(1, 200) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, 10.0 - 0.05), - new Point2D(1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point too high"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(1, 200), - new Point2D(2, 100), - new Point2D(1, 200) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, 10.0 + 0.05), - new Point2D(1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point too low"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(1, 20), - new Point2D(3, -1), - new Point2D(1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, 10.0), - new Point2D(1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("X further than x of surfaceLine, Y not within limit"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0, 10), - new Point2D(1, 21), - new Point2D(1, 19), - new Point2D(2, 10), - new Point2D(0, 10) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("Second segment is vertical and exceeds surfaceLine"); - } - - private static IEnumerable SurfaceLineOnMacroStabilityInwardsSoilProfile2D() - { - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.1, 20), - new Point2D(0.2, 10), - new Point2D(0.15, -10), - new Point2D(0.1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.0, 10), - new Point2D(0.1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("Irrelevant surface line point"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.1, 20), - new Point2D(0.2, 10), - new Point2D(0.1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.0, 10.0049), - new Point2D(0.1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point within upper limit"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.1, 20), - new Point2D(0.2, 10), - new Point2D(0.1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.0, 10.0 - 0.0049), - new Point2D(0.1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("First surface line point within lower limit"); - - yield return new TestCaseData( - new MacroStabilityInwardsSoilProfile2D( - "profile", - new[] - { - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.1, 20), - new Point2D(0.3, 0), - new Point2D(0.1, 20) - })), - new MacroStabilityInwardsSoilLayer2D(new Ring(new[] - { - new Point2D(0.0, 10.0), - new Point2D(0.1, 20) - })) - }, new MacroStabilityInwardsPreconsolidationStress[0])) - .SetName("X further than x of surfaceLine"); - } - private static void AssertInput(MacroStabilityInwardsInput originalInput, TestMacroStabilityInwardsCalculatorFactory factory) { UpliftVanCalculatorInput actualInput = factory.LastCreatedUpliftVanCalculator.Input;