Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs =================================================================== diff -u -r2a7be595bf1251849a3c5f3be000f0e40f8fa874 -r98a291d574281a04a9e0a243d8a4429a1ffb9379 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 2a7be595bf1251849a3c5f3be000f0e40f8fa874) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 98a291d574281a04a9e0a243d8a4429a1ffb9379) @@ -1,7 +1,10 @@ -using Core.Common.Base.Geometry; +using System; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.Extensions; +using Ringtoets.Piping.Forms.Properties; namespace Ringtoets.Piping.Forms.Test.Extensions { @@ -115,5 +118,153 @@ Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation); Assert.AreEqual(thirdPointX - firstPointX, inputParameters.ExitPointL); } + + [Test] + [TestCase(2, 0, 2)] + [TestCase(2, -2, 4)] + [TestCase(0.5, -3.5, 4)] + [TestCase(1e-6, -(4 - 1e-6), 4)] + [TestCase(3 + 1e-6, 3, 1e-6)] + [TestCase(0.5, 0.5 - 1e-6, 1e-6)] + public void SetEntryPointL_ExitPointAndSeepageLengthSet_UpdatesSeepageLength(double exitPoint, double entryPoint, double seepageLength) + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + ExitPointL = exitPoint + }; + + input.SetEntryPointL(entryPoint); + + // Call & Assert + Assert.AreEqual(exitPoint, input.ExitPointL); + Assert.AreEqual(seepageLength, input.SeepageLength.Mean, 1e-6); + } + + [Test] + [TestCase(2, 2, 4)] + [TestCase(4, 2, 6)] + [TestCase(4, 0.5, 4.5)] + [TestCase(1e-6, 4, 4 + 1e-6)] + [TestCase(3, -1e-6, 3 - 1e-6)] + [TestCase(0.5, 1e-6, 0.5 + 1e-6)] + public void SetExitPointL_ExitPointAndSeepageLengthSet_UpdatesSeepageLength(double seepageLength, double exitPoint, double newSeepageLength) + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + SeepageLength = + { + Mean = seepageLength + } + }; + + input.SetExitPointL(exitPoint); + + // Call & Assert + Assert.AreEqual(exitPoint, input.ExitPointL); + Assert.AreEqual(newSeepageLength, input.SeepageLength.Mean); + } + + [Test] + public void SetEntryPointL_SetResultInInvalidSeePage_ThrowsArgumentException() + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + + var l = 2.0; + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + ExitPointL = l + }; + + + // Call + TestDelegate test = () => input.SetEntryPointL(l); + + // Assert + var message = string.Format(Resources.PipingInputContextProperties_EntryPointL_Value_0_results_in_invalid_seepage_length, l); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + public void SetExitPointL_SetResultInInvalidSeePage_ThrowsArgumentException() + { + // Setup + var random = new Random(22); + + var surfaceLine = ValidSurfaceLine(0.0, 4.0); + var soilProfile = new PipingSoilProfile(String.Empty, random.NextDouble(), new[] + { + new PipingSoilLayer(random.NextDouble()) + { + IsAquifer = true + } + }); + var l = -2.0; + var input = new PipingInput + { + SurfaceLine = surfaceLine, + SoilProfile = soilProfile, + SeepageLength = + { + Mean = -l + } + }; + + + // Call + TestDelegate test = () => input.SetExitPointL(l); + + // Assert + var message = string.Format(Resources.PipingInputContextProperties_ExitPointL_Value_0_results_in_invalid_seepage_length, l); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + private static RingtoetsPipingSurfaceLine ValidSurfaceLine(double xMin, double xMax) + { + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(xMin, 0.0, 0.0), + new Point3D(xMax, 0.0, 1.0) + }); + return surfaceLine; + } } } \ No newline at end of file