Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/MechanismSurfaceLineBaseTest.cs =================================================================== diff -u -red125eab861825fb053bf64259d38f33599087a9 -r9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/MechanismSurfaceLineBaseTest.cs (.../MechanismSurfaceLineBaseTest.cs) (revision ed125eab861825fb053bf64259d38f33599087a9) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/MechanismSurfaceLineBaseTest.cs (.../MechanismSurfaceLineBaseTest.cs) (revision 9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612) @@ -23,9 +23,11 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; +using Ringtoets.Common.Data.Exceptions; namespace Ringtoets.Common.Data.Test { @@ -155,6 +157,219 @@ StringAssert.StartsWith("Een punt in de geometrie voor de profielschematisatie heeft geen waarde.", exception.Message); } + [Test] + public void GetZAtL_GeometryIsEmpty_ThrowsInvalidOperationException() + { + // Setup + var surfaceLine = new TestMechanismSurfaceLine(); + var l = (RoundedDouble) new Random(21).NextDouble(); + + // Call + TestDelegate test = () => surfaceLine.GetZAtL(l); + + // Assert + string exceptionMessage = Assert.Throws(test).Message; + Assert.AreEqual("De profielschematisatie heeft geen geometrie.", exceptionMessage); + } + + [Test] + public void GetZAtL_SurfaceLineContainsPointAtL_ReturnsZOfPoint() + { + // Setup + double testZ = new Random(22).NextDouble(); + + var surfaceLine = new TestMechanismSurfaceLine(); + var l = (RoundedDouble) 2.0; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 2.2), + new Point3D(l, 0.0, testZ), + new Point3D(3.0, 0.0, 7.7) + }); + + // Call + double result = surfaceLine.GetZAtL(l); + + // Assert + Assert.AreEqual(testZ, result, 1e-2); + } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-1)] + [TestCase(-5e-3)] + [TestCase(3.1 + 5e-3)] + [TestCase(4.0)] + public void GetZAtL_SurfaceLineDoesNotContainsPointAtL_ThrowsArgumentOutOfRangeException(double l) + { + // Setup + double testZ = new Random(22).NextDouble(); + + var surfaceLine = new TestMechanismSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(1.0, 0.0, 2.2), + new Point3D(2.0, 0.0, testZ), + new Point3D(4.1, 0.0, 7.7) + }); + + // Call + TestDelegate test = () => surfaceLine.GetZAtL((RoundedDouble) l); + + // Assert + const string expectedMessage = "Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0,0, 3,1] liggen."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); + } + + [Test] + public void GetZAtL_SurfaceLineVerticalAtL_ThrowsMechanismSurfaceLineException() + { + // Setup + double testZ = new Random(22).NextDouble(); + + var surfaceLine = new TestMechanismSurfaceLine(); + var l = (RoundedDouble) 2.0; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 0.0, 2.2), + new Point3D(l, 0.0, testZ), + new Point3D(l, 0.0, testZ + 1), + new Point3D(3.0, 0.0, 7.7) + }); + + // Call + TestDelegate test = () => surfaceLine.GetZAtL(l); + + // Assert + var exception = Assert.Throws(test); + string message = $"Kan geen hoogte bepalen op het punt met de lokale coördinaat {l}, omdat de profielschematisatie verticaal loopt op dat punt."; + Assert.AreEqual(message, exception.Message); + } + + [Test] + public void ToString_ReturnName() + { + // Setup + const string niceName = "Nice name"; + var surfaceLine = new TestMechanismSurfaceLine + { + Name = niceName + }; + + // Call + string text = surfaceLine.ToString(); + + // Assert + Assert.AreEqual(niceName, text); + } + + [Test] + [TestCase(5.0)] + [TestCase(1.375)] + [TestCase(-0.005)] + [TestCase(-5)] + public void ValidateInRange_PointNotInRange_ReturnsFalse(double invalidValue) + { + // Setup + const double testX = 1.0; + const double testY = 2.2; + const double testZ = 4.4; + var testPoint = new Point3D(testX, testY, testZ); + var surfaceLine = new TestMechanismSurfaceLine(); + CreateTestGeometry(testPoint, surfaceLine); + + // Call + bool valid = surfaceLine.ValidateInRange(invalidValue); + + // Assert + Assert.IsFalse(valid); + } + + [Test] + [TestCase(-0e-3)] + [TestCase(1.37)] + [TestCase(1.0)] + public void ValidateInRange_PointInRange_ReturnsTrue(double validValue) + { + // Setup + const double testX = 1.0; + const double testY = 2.2; + const double testZ = 4.4; + var testPoint = new Point3D(testX, testY, testZ); + var surfaceLine = new TestMechanismSurfaceLine(); + CreateTestGeometry(testPoint, surfaceLine); + + // Call + bool valid = surfaceLine.ValidateInRange(validValue); + + // Assert + Assert.IsTrue(valid); + } + + [Test] + public void GetLocalPointFromGeometry_ValidSurfaceLine_ReturnsLocalPoint() + { + // Setup + const double testX = 1.0; + const double testY = 2.2; + const double testZ = 4.4; + var testPoint = new Point3D(testX, testY, testZ); + var surfaceLine = new TestMechanismSurfaceLine(); + CreateTestGeometry(testPoint, surfaceLine); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); + + // Assert + Assert.AreEqual(new Point2D(0.04, 4.4), localPoint); + } + + [Test] + public void GetLocalPointFromGeometry_NoPointsOnSurfaceLine_ReturnsPointWithNanValues() + { + // Setup + var surfaceLine = new TestMechanismSurfaceLine(); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(new Point3D(1.0, 2.2, 4.4)); + + // Assert + Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); + } + + [Test] + public void GetLocalPointFromGeometry_OnePointOnSurfaceLine_ReturnsPointWithNanValues() + { + // Setup + const double testX = 1.0; + const double testY = 2.2; + const double testZ = 4.4; + var testPoint = new Point3D(testX, testY, testZ); + var surfaceLine = new TestMechanismSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + testPoint + }); + + // Call + Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); + + // Assert + Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); + } + private class TestMechanismSurfaceLine : MechanismSurfaceLineBase {} + + private static void CreateTestGeometry(Point3D testPoint, TestMechanismSurfaceLine surfaceLine) + { + var random = new Random(21); + + surfaceLine.SetGeometry(new[] + { + new Point3D(random.NextDouble(), random.NextDouble(), random.NextDouble()), + new Point3D(testPoint), + new Point3D(2 + random.NextDouble(), random.NextDouble(), random.NextDouble()) + }); + } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSurfaceLineTest.cs =================================================================== diff -u -red125eab861825fb053bf64259d38f33599087a9 -r9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSurfaceLineTest.cs (.../MacroStabilityInwardsSurfaceLineTest.cs) (revision ed125eab861825fb053bf64259d38f33599087a9) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSurfaceLineTest.cs (.../MacroStabilityInwardsSurfaceLineTest.cs) (revision 9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612) @@ -22,13 +22,11 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using Core.Common.Utils; using NUnit.Framework; using Ringtoets.Common.Data; -using Ringtoets.Common.Data.Exceptions; namespace Ringtoets.MacroStabilityInwards.Primitives.Test { @@ -46,207 +44,6 @@ } [Test] - public void GetZAtL_GeometryIsEmpty_ThrowsInvalidOperationException() - { - // Setup - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - var l = (RoundedDouble) new Random(21).NextDouble(); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL(l); - - // Assert - string exceptionMessage = Assert.Throws(test).Message; - Assert.AreEqual("De profielschematisatie heeft geen geometrie.", exceptionMessage); - } - - [Test] - public void GetZAtL_SurfaceLineContainsPointAtL_ReturnsZOfPoint() - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - var l = (RoundedDouble) 2.0; - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 0.0, 2.2), - new Point3D(l, 0.0, testZ), - new Point3D(3.0, 0.0, 7.7) - }); - - // Call - double result = surfaceLine.GetZAtL(l); - - // Assert - Assert.AreEqual(testZ, result, 1e-2); - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(-1)] - [TestCase(-5e-3)] - [TestCase(3.1 + 5e-3)] - [TestCase(4.0)] - public void GetZAtL_SurfaceLineDoesNotContainsPointAtL_ThrowsArgumentOutOfRangeException(double l) - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(1.0, 0.0, 2.2), - new Point3D(2.0, 0.0, testZ), - new Point3D(4.1, 0.0, 7.7) - }); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL((RoundedDouble) l); - - // Assert - const string expectedMessage = "Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0,0, 3,1] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - public void GetZAtL_SurfaceLineVerticalAtL_ThrowsMechanismSurfaceLineException() - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - var l = (RoundedDouble) 2.0; - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 0.0, 2.2), - new Point3D(l, 0.0, testZ), - new Point3D(l, 0.0, testZ + 1), - new Point3D(3.0, 0.0, 7.7) - }); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL(l); - - // Assert - var exception = Assert.Throws(test); - string message = $"Kan geen hoogte bepalen op het punt met de lokale coördinaat {l}, omdat de profielschematisatie verticaal loopt op dat punt."; - Assert.AreEqual(message, exception.Message); - } - - [Test] - public void ToString_ReturnName() - { - // Setup - const string niceName = "Nice name"; - var surfaceLine = new MacroStabilityInwardsSurfaceLine - { - Name = niceName - }; - - // Call - string text = surfaceLine.ToString(); - - // Assert - Assert.AreEqual(niceName, text); - } - - [Test] - [TestCase(5.0)] - [TestCase(1.375)] - [TestCase(-0.005)] - [TestCase(-5)] - public void ValidateInRange_PointNotInRange_ReturnsFalse(double invalidValue) - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - bool valid = surfaceLine.ValidateInRange(invalidValue); - - // Assert - Assert.IsFalse(valid); - } - - [Test] - [TestCase(-0e-3)] - [TestCase(1.37)] - [TestCase(1.0)] - public void ValidateInRange_PointInRange_ReturnsTrue(double validValue) - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - bool valid = surfaceLine.ValidateInRange(validValue); - - // Assert - Assert.IsTrue(valid); - } - - [Test] - public void GetLocalPointFromGeometry_ValidSurfaceLine_ReturnsLocalPoint() - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); - - // Assert - Assert.AreEqual(new Point2D(0.04, 4.4), localPoint); - } - - [Test] - public void GetLocalPointFromGeometry_NoPointsOnSurfaceLine_ReturnsPointWithNanValues() - { - // Setup - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(new Point3D(1.0, 2.2, 4.4)); - - // Assert - Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); - } - - [Test] - public void GetLocalPointFromGeometry_OnePointOnSurfaceLine_ReturnsPointWithNanValues() - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new MacroStabilityInwardsSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - testPoint - }); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); - - // Assert - Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); - } - - [Test] public void CopyProperties_WithSurfaceLineNull_ThrowsArgumentNullException() { // Setup Index: Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSurfaceLineTest.cs =================================================================== diff -u -red125eab861825fb053bf64259d38f33599087a9 -r9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612 --- Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSurfaceLineTest.cs (.../PipingSurfaceLineTest.cs) (revision ed125eab861825fb053bf64259d38f33599087a9) +++ Ringtoets/Piping/test/Ringtoets.Piping.Primitives.Test/PipingSurfaceLineTest.cs (.../PipingSurfaceLineTest.cs) (revision 9b791eb0a5c7d9bf4842ac9c79d4acb31bf69612) @@ -22,13 +22,11 @@ using System; using System.Collections.Generic; using System.Linq; -using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using Core.Common.Utils; using NUnit.Framework; using Ringtoets.Common.Data; -using Ringtoets.Common.Data.Exceptions; namespace Ringtoets.Piping.Primitives.Test { @@ -46,207 +44,6 @@ } [Test] - public void GetZAtL_GeometryIsEmpty_ThrowsInvalidOperationException() - { - // Setup - var surfaceLine = new PipingSurfaceLine(); - var l = (RoundedDouble) new Random(21).NextDouble(); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL(l); - - // Assert - string exceptionMessage = Assert.Throws(test).Message; - Assert.AreEqual("De profielschematisatie heeft geen geometrie.", exceptionMessage); - } - - [Test] - public void GetZAtL_SurfaceLineContainsPointAtL_ReturnsZOfPoint() - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new PipingSurfaceLine(); - var l = (RoundedDouble) 2.0; - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 0.0, 2.2), - new Point3D(l, 0.0, testZ), - new Point3D(3.0, 0.0, 7.7) - }); - - // Call - double result = surfaceLine.GetZAtL(l); - - // Assert - Assert.AreEqual(testZ, result, 1e-2); - } - - [Test] - [SetCulture("nl-NL")] - [TestCase(-1)] - [TestCase(-5e-3)] - [TestCase(3.1 + 5e-3)] - [TestCase(4.0)] - public void GetZAtL_SurfaceLineDoesNotContainsPointAtL_ThrowsArgumentOutOfRangeException(double l) - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new PipingSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(1.0, 0.0, 2.2), - new Point3D(2.0, 0.0, testZ), - new Point3D(4.1, 0.0, 7.7) - }); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL((RoundedDouble) l); - - // Assert - const string expectedMessage = "Kan geen hoogte bepalen. De lokale coördinaat moet in het bereik [0,0, 3,1] liggen."; - TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage); - } - - [Test] - public void GetZAtL_SurfaceLineVerticalAtL_ThrowsMechanismSurfaceLineException() - { - // Setup - double testZ = new Random(22).NextDouble(); - - var surfaceLine = new PipingSurfaceLine(); - var l = (RoundedDouble) 2.0; - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 0.0, 2.2), - new Point3D(l, 0.0, testZ), - new Point3D(l, 0.0, testZ + 1), - new Point3D(3.0, 0.0, 7.7) - }); - - // Call - TestDelegate test = () => surfaceLine.GetZAtL(l); - - // Assert - var exception = Assert.Throws(test); - string message = $"Kan geen hoogte bepalen op het punt met de lokale coördinaat {l}, omdat de profielschematisatie verticaal loopt op dat punt."; - Assert.AreEqual(message, exception.Message); - } - - [Test] - public void ToString_ReturnName() - { - // Setup - const string niceName = "Nice name"; - var surfaceLine = new PipingSurfaceLine - { - Name = niceName - }; - - // Call - string text = surfaceLine.ToString(); - - // Assert - Assert.AreEqual(niceName, text); - } - - [Test] - [TestCase(5.0)] - [TestCase(1.375)] - [TestCase(-0.005)] - [TestCase(-5)] - public void ValidateInRange_PointNotInRange_ReturnsFalse(double invalidValue) - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new PipingSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - bool valid = surfaceLine.ValidateInRange(invalidValue); - - // Assert - Assert.IsFalse(valid); - } - - [Test] - [TestCase(-0e-3)] - [TestCase(1.37)] - [TestCase(1.0)] - public void ValidateInRange_PointInRange_ReturnsTrue(double validValue) - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new PipingSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - bool valid = surfaceLine.ValidateInRange(validValue); - - // Assert - Assert.IsTrue(valid); - } - - [Test] - public void GetLocalPointFromGeometry_ValidSurfaceLine_ReturnsLocalPoint() - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new PipingSurfaceLine(); - CreateTestGeometry(testPoint, surfaceLine); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); - - // Assert - Assert.AreEqual(new Point2D(0.04, 4.4), localPoint); - } - - [Test] - public void GetLocalPointFromGeometry_NoPointsOnSurfaceLine_ReturnsPointWithNanValues() - { - // Setup - var surfaceLine = new PipingSurfaceLine(); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(new Point3D(1.0, 2.2, 4.4)); - - // Assert - Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); - } - - [Test] - public void GetLocalPointFromGeometry_OnePointOnSurfaceLine_ReturnsPointWithNanValues() - { - // Setup - const double testX = 1.0; - const double testY = 2.2; - const double testZ = 4.4; - var testPoint = new Point3D(testX, testY, testZ); - var surfaceLine = new PipingSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - testPoint - }); - - // Call - Point2D localPoint = surfaceLine.GetLocalPointFromGeometry(testPoint); - - // Assert - Assert.AreEqual(new Point2D(double.NaN, double.NaN), localPoint); - } - - [Test] public void CopyProperties_WithSurfaceLineNull_ThrowsArgumentNullException() { // Setup