Index: src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs =================================================================== diff -u -r300a33d9acf653458b834b296becbf9ae552de8e -r1d5aa9555ab25c06f0a322173953a79c6ead1404 --- src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision 300a33d9acf653458b834b296becbf9ae552de8e) +++ src/Plugins/Ringtoets/Piping/src/Ringtoets.Piping.IO/Calculation/Math2D.cs (.../Math2D.cs) (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404) @@ -20,11 +20,6 @@ /// public static double[] LineSegmentIntersectionWithLineSegment(double[] segmentsX, double[] segmentsY) { - var numberOfPoints = 4; - if (segmentsX.Length != numberOfPoints || segmentsY.Length != numberOfPoints) - { - throw new ArgumentException(String.Format("Collections of segments' x and y coordinates need to have length of {0}.", numberOfPoints)); - } var extraPolatedIntersectionPoint = LineSegmentIntersectionWithLine(segmentsX, segmentsY); if (extraPolatedIntersectionPoint.Length == 2) @@ -85,7 +80,7 @@ var numberOfPoints = 4; if (linesX.Length != numberOfPoints || linesY.Length != numberOfPoints) { - throw new ArgumentException(String.Format("Collections of lines' x and y coordinates need to have length of {0}", numberOfPoints)); + throw new ArgumentException(String.Format("Collections of lines' x and y coordinates need to have length of {0}.", numberOfPoints)); } var aLine = linesY[1] - linesY[0]; @@ -119,20 +114,28 @@ /// and [1],[1]. False otherwise. private static bool IsBetween(double[] x, double[] y) { - var crossProduct = (y[2] - y[0])*(x[1] - x[0]) - (x[2] - x[0])*(y[1] - y[0]); - if (Math.Abs(crossProduct) > EpsilonForComparisons) + if (Math.Abs(CrossProduct(x, y)) > EpsilonForComparisons) { return false; } - var dotProduct = (x[2] - x[0])*(x[1] - x[0]) + (y[2] - y[0])*(y[1] - y[0]); - if (dotProduct < 0) + if (DotProduct(x, y) < 0) { return false; } var squaredLengthSegment = (x[1] - x[0])*(x[1] - x[0]) + (y[1] - y[0])*(y[1] - y[0]); - return dotProduct <= squaredLengthSegment; + return DotProduct(x, y) <= squaredLengthSegment; } + + private static double DotProduct(double[] x, double[] y) + { + return (x[2] - x[0])*(x[1] - x[0]) + (y[2] - y[0])*(y[1] - y[0]); + } + + private static double CrossProduct(double[] x, double[] y) + { + return (y[2] - y[0])*(x[1] - x[0]) - (x[2] - x[0])*(y[1] - y[0]); + } } } \ No newline at end of file Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayer2DConversionExceptionTest.cs =================================================================== diff -u --- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayer2DConversionExceptionTest.cs (revision 0) +++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Builders/SoilLayer2DConversionExceptionTest.cs (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404) @@ -0,0 +1,52 @@ +using System; +using NUnit.Framework; +using Ringtoets.Piping.IO.Builders; + +namespace Ringtoets.Piping.IO.Test.Builders +{ + public class SoilLayer2DConversionExceptionTest + { + [Test] + public void DefaultConstructor_InnerExceptionNullAndMessageDefault() + { + // Setup + var expectedMessage = String.Format("Exception of type '{0}' was thrown.", typeof(SoilLayer2DConversionException).FullName); + + // Call + var exception = new SoilLayer2DConversionException(); + + // Assert + Assert.IsNull(exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Constructor_WithCustomMessage_InnerExceptionNullAndMessageSetToCustom() + { + // Setup + var expectedMessage = "Some exception message"; + + // Call + var exception = new SoilLayer2DConversionException(expectedMessage); + + // Assert + Assert.IsNull(exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Constructor_WithCustomMessageAndInnerException_InnerExceptionSetAndMessageSetToCustom() + { + // Setup + var expectedMessage = "Some exception message"; + var expectedInnerException = new Exception(); + + // Call + var exception = new SoilLayer2DConversionException(expectedMessage, expectedInnerException); + + // Assert + Assert.AreSame(expectedInnerException, exception.InnerException); + Assert.AreEqual(expectedMessage, exception.Message); + } + } +} \ No newline at end of file Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Calculation/Math2DTest.cs =================================================================== diff -u -r300a33d9acf653458b834b296becbf9ae552de8e -r1d5aa9555ab25c06f0a322173953a79c6ead1404 --- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Calculation/Math2DTest.cs (.../Math2DTest.cs) (revision 300a33d9acf653458b834b296becbf9ae552de8e) +++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Calculation/Math2DTest.cs (.../Math2DTest.cs) (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404) @@ -1,4 +1,7 @@ -using NUnit.Framework; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using NUnit.Framework; using Ringtoets.Piping.IO.Calculation; namespace Ringtoets.Piping.IO.Test.Calculation @@ -160,6 +163,66 @@ Assert.AreEqual(0, result.Length); } + [Test] + [TestCase(3,2)] + [TestCase(2,3)] + [TestCase(3,3)] + [TestCase(1,1)] + [TestCase(1,2)] + [TestCase(2,1)] + public void LineSegmentIntersectionWithLineSegment_IncorrectLengthOfParameters_ThrowsArgumentException(int xLength, int yLength) + { + // Setup + Collection xCollection = new Collection(); + Collection yCollection = new Collection(); + var random = new Random(22); + for (var i = 0; i < xLength; i++) + { + xCollection.Add(random.NextDouble()); + } + for (var i = 0; i < yLength; i++) + { + yCollection.Add(random.NextDouble()); + } + + // Call + TestDelegate test = () => Math2D.LineSegmentIntersectionWithLineSegment(xCollection.ToArray(), yCollection.ToArray()); + + // Assert + var message = Assert.Throws(test); + Assert.AreEqual(message.Message, "Collections of lines' x and y coordinates need to have length of 4."); + } + + [Test] + [TestCase(3, 2)] + [TestCase(2, 3)] + [TestCase(3, 3)] + [TestCase(1, 1)] + [TestCase(1, 2)] + [TestCase(2, 1)] + public void LineSegmentIntersectionWithLine_IncorrectLengthOfParameters_ThrowsArgumentException(int xLength, int yLength) + { + // Setup + Collection xCollection = new Collection(); + Collection yCollection = new Collection(); + var random = new Random(22); + for (var i = 0; i < xLength; i++) + { + xCollection.Add(random.NextDouble()); + } + for (var i = 0; i < yLength; i++) + { + yCollection.Add(random.NextDouble()); + } + + // Call + TestDelegate test = () => Math2D.LineSegmentIntersectionWithLine(xCollection.ToArray(), yCollection.ToArray()); + + // Assert + var message = Assert.Throws(test); + Assert.AreEqual(message.Message, "Collections of lines' x and y coordinates need to have length of 4."); + } + private double[][] ToSegmentCoordinatesCollections(double[] coordinates) { double[] segmentX = Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs =================================================================== diff -u -ra0ccfa1b27041c9d4fb8ab5a0e81913ed6ab26ba -r1d5aa9555ab25c06f0a322173953a79c6ead1404 --- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision a0ccfa1b27041c9d4fb8ab5a0e81913ed6ab26ba) +++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/PipingSoilProfileReaderTest.cs (.../PipingSoilProfileReaderTest.cs) (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404) @@ -174,6 +174,21 @@ CollectionAssert.AllItemsAreUnique(secondProfile.Layers.Select(l => l.Top)); Assert.AreEqual(3, secondProfile.Layers.Count(l => expectedSecondProfileLayersTops.Contains(l.Top, new DoubleComparer()))); } + + [Test] + public void ReadProfiles_DatabaseWith1DAnd2DProfilesWithSameName_ThrowsPipingSoilProfileReadException() + { + // Setup + var testFile = "Combined1dAnd2d.soil"; + var pipingSoilProfilesReader = new PipingSoilProfileReader(Path.Combine(testDataPath, testFile)); + + // Call + TestDelegate test = () => pipingSoilProfilesReader.Read(); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(Resources.Error_CannotCombine2DAnd1DLayersInProfile, exception.Message); + } } internal class DoubleComparer : IEqualityComparer { Index: src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj =================================================================== diff -u -r30c4782361bd6f897f02df74461a73b60bc4a085 -r1d5aa9555ab25c06f0a322173953a79c6ead1404 --- src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 30c4782361bd6f897f02df74461a73b60bc4a085) +++ src/Plugins/Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 1d5aa9555ab25c06f0a322173953a79c6ead1404) @@ -44,6 +44,7 @@ + Index: test-data/Plugins/Wti/IO/PipingSoilProfilesReader/Combined1dAnd2d.soil =================================================================== diff -u Binary files differ