Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs =================================================================== diff -u -rda004b349d777118e3fdf7dddca87c7e1fc5b596 -r70fcdcf73a30c29ab3a710b449d12a31022b3ab7 --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs (.../MacroStabilityInwardsChartDataPointsFactory.cs) (revision da004b349d777118e3fdf7dddca87c7e1fc5b596) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Factories/MacroStabilityInwardsChartDataPointsFactory.cs (.../MacroStabilityInwardsChartDataPointsFactory.cs) (revision 70fcdcf73a30c29ab3a710b449d12a31022b3ab7) @@ -286,26 +286,6 @@ : GetWaternetZoneWithSurfaceLineIntersection(surfaceLineLocalGeometry, waternetLineGeometry, phreaticLineGeometry); } - #region SoilLayers and Surface Line Helpers - - private static Point2D[] GetLocalPointsFromGeometry(MacroStabilityInwardsSurfaceLine surfaceLine, - Point3D worldCoordinate) - { - if (surfaceLine == null || worldCoordinate == null) - { - return new Point2D[0]; - } - - return new[] - { - surfaceLine.GetLocalPointFromGeometry(worldCoordinate) - }; - } - - #endregion - - #region Grid Helpers - /// /// Creates grid points in 2D space based on the provided . /// @@ -321,9 +301,25 @@ /// public static Point2D[] CreateGridPoints(MacroStabilityInwardsGrid grid, MacroStabilityInwardsGridDeterminationType gridDeterminationType) { - if (grid == null - || gridDeterminationType == MacroStabilityInwardsGridDeterminationType.Automatic - || !AreGridSettingsValid(grid)) + return gridDeterminationType == MacroStabilityInwardsGridDeterminationType.Automatic + ? new Point2D[0] + : CreateGridPoints(grid); + } + + /// + /// Creates grid points in 2D space based on the provided . + /// + /// The grid to create the grid points for. + /// An array of interpolated points in 2D space based on the provided + /// or an empty array when: + /// + /// is null; + /// The grid boundaries are . + /// + /// + public static Point2D[] CreateGridPoints(MacroStabilityInwardsGrid grid) + { + if (grid == null || !AreGridSettingsValid(grid)) { return new Point2D[0]; } @@ -343,6 +339,26 @@ return points.ToArray(); } + #region SoilLayers and Surface Line Helpers + + private static Point2D[] GetLocalPointsFromGeometry(MacroStabilityInwardsSurfaceLine surfaceLine, + Point3D worldCoordinate) + { + if (surfaceLine == null || worldCoordinate == null) + { + return new Point2D[0]; + } + + return new[] + { + surfaceLine.GetLocalPointFromGeometry(worldCoordinate) + }; + } + + #endregion + + #region Grid Helpers + private static bool AreGridSettingsValid(MacroStabilityInwardsGrid grid) { return !double.IsNaN(grid.XLeft) Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs =================================================================== diff -u -rda004b349d777118e3fdf7dddca87c7e1fc5b596 -r70fcdcf73a30c29ab3a710b449d12a31022b3ab7 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs (.../MacroStabilityInwardsChartDataPointsFactoryTest.cs) (revision da004b349d777118e3fdf7dddca87c7e1fc5b596) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Forms.Test/Factories/MacroStabilityInwardsChartDataPointsFactoryTest.cs (.../MacroStabilityInwardsChartDataPointsFactoryTest.cs) (revision 70fcdcf73a30c29ab3a710b449d12a31022b3ab7) @@ -529,7 +529,7 @@ } [Test] - public void CreateGridPoints_MacroStabilityInwardsGridNull_ReturnsEmptyPoints() + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsGridNull_ReturnsEmptyPoints() { // Call Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(null, MacroStabilityInwardsGridDeterminationType.Manual); @@ -539,7 +539,7 @@ } [Test] - public void CreateGridPoints_MacroStabilityInwardsGridDeterminationTypeAutomatic_ReturnsEmptyPoints() + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsGridDeterminationTypeAutomatic_ReturnsEmptyPoints() { // Setup var random = new Random(21); @@ -560,8 +560,8 @@ } [Test] - [TestCaseSource(nameof(GetGridSettingsNoGridPoints))] - public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsNoGrid_ReturnsEmptyPoints(MacroStabilityInwardsGrid grid) + [TestCaseSource(nameof(GetGridSettingsNoGridPoints), new object[] { "CreateGridPointsWithGridDeterminationType" })] + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsGridNumberOfPointsNoGrid_ReturnsEmptyPoints(MacroStabilityInwardsGrid grid) { // Call Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid, MacroStabilityInwardsGridDeterminationType.Manual); @@ -571,8 +571,8 @@ } [Test] - [TestCaseSource(nameof(GetGridSettingsOnePoint))] - public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsOnePoint_AlwaysReturnsBottomLeftPoint( + [TestCaseSource(nameof(GetGridSettingsOnePoint), new object[] { "CreateGridPointsWithGridDeterminationType" })] + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsGridNumberOfPointsOnePoint_AlwaysReturnsBottomLeftPoint( MacroStabilityInwardsGrid grid) { // Call @@ -586,8 +586,8 @@ } [Test] - [TestCaseSource(nameof(GetGridSettingsOnlyHorizontalPoints))] - public void CreateGridPoints_MacroStabilityInwardsGridSettingsOnlyHorizontalPoints_ReturnsGridPointsAtBottomSide( + [TestCaseSource(nameof(GetGridSettingsOnlyHorizontalPoints), new object[] { "CreateGridPointsWithGridDeterminationType" })] + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsGridSettingsOnlyHorizontalPoints_ReturnsGridPointsAtBottomSide( MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) { // Call @@ -598,8 +598,8 @@ } [Test] - [TestCaseSource(nameof(GetGridSettingsOnlyVerticalPoints))] - public void CreateGridPoints_CreateGridPoints_MacroStabilityInwardsGridSettingsOnlyVerticallPoints_ReturnsGridPointsAtLeftSide + [TestCaseSource(nameof(GetGridSettingsOnlyVerticalPoints), new object[] { "CreateGridPointsWithGridDeterminationType" })] + public void CreateGridPointsWithGridDeterminationType_CreateGridPoints_MacroStabilityInwardsGridSettingsOnlyVerticallPoints_ReturnsGridPointsAtLeftSide (MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) { // Call @@ -610,8 +610,8 @@ } [Test] - [TestCaseSource(nameof(GetWellDefinedGridSettings))] - public void CreateGridPoints_MacroStabilityInwardsWellDefinedGrid_ReturnsExpectedGridPoints( + [TestCaseSource(nameof(GetWellDefinedGridSettings), new object[] { "CreateGridPointsWithGridDeterminationType" })] + public void CreateGridPointsWithGridDeterminationType_MacroStabilityInwardsWellDefinedGrid_ReturnsExpectedGridPoints( MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) { // Call @@ -622,6 +622,78 @@ } [Test] + public void CreateGridPoints_MacroStabilityInwardsGridNull_ReturnsEmptyPoints() + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(null); + + // Assert + CollectionAssert.IsEmpty(gridPoints); + } + + [Test] + [TestCaseSource(nameof(GetGridSettingsNoGridPoints), new object[] { "CreateGridPoints" })] + public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsNoGrid_ReturnsEmptyPoints(MacroStabilityInwardsGrid grid) + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid); + + // Assert + CollectionAssert.IsEmpty(gridPoints); + } + + [Test] + [TestCaseSource(nameof(GetGridSettingsOnePoint), new object[] { "CreateGridPoints" })] + public void CreateGridPoints_MacroStabilityInwardsGridNumberOfPointsOnePoint_AlwaysReturnsBottomLeftPoint( + MacroStabilityInwardsGrid grid) + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid); + + // Assert + AssertEqualPointCollection(new[] + { + new Point2D(grid.XLeft, grid.ZBottom) + }, gridPoints); + } + + [Test] + [TestCaseSource(nameof(GetGridSettingsOnlyHorizontalPoints), new object[] { "CreateGridPoints" })] + public void CreateGridPoints_MacroStabilityInwardsGridSettingsOnlyHorizontalPoints_ReturnsGridPointsAtBottomSide( + MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid); + + // Assert + AssertEqualPointCollection(expectedPoints, gridPoints); + } + + [Test] + [TestCaseSource(nameof(GetGridSettingsOnlyVerticalPoints), new object[] { "CreateGridPoints" })] + public void CreateGridPoints_CreateGridPoints_MacroStabilityInwardsGridSettingsOnlyVerticallPoints_ReturnsGridPointsAtLeftSide + (MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid); + + // Assert + AssertEqualPointCollection(expectedPoints, gridPoints); + } + + [Test] + [TestCaseSource(nameof(GetWellDefinedGridSettings), new object[] { "CreateGridPoints" })] + public void CreateGridPoints_MacroStabilityInwardsWellDefinedGrid_ReturnsExpectedGridPoints( + MacroStabilityInwardsGrid grid, Point2D[] expectedPoints) + { + // Call + Point2D[] gridPoints = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(grid); + + // Assert + AssertEqualPointCollection(expectedPoints, gridPoints); + } + + [Test] public void CreateOuterRingArea_SoilLayerNull_ReturnsEmptyAreaCollection() { // Call @@ -1117,7 +1189,7 @@ #region Grid Settings - private static IEnumerable GetGridSettingsNoGridPoints() + private static IEnumerable GetGridSettingsNoGridPoints(string prefix) { var random = new Random(21); @@ -1130,25 +1202,25 @@ { NumberOfHorizontalPoints = 1, NumberOfVerticalPoints = 1 - }).SetName("XLeftNaN"); + }).SetName($"{prefix} - XLeftNaN"); yield return new TestCaseData(new MacroStabilityInwardsGrid(xLeft, double.NaN, zTop, zBottom) { NumberOfHorizontalPoints = 1, NumberOfVerticalPoints = 1 - }).SetName("XRightNaN"); + }).SetName($"{prefix} - XRightNaN"); yield return new TestCaseData(new MacroStabilityInwardsGrid(xLeft, xRight, double.NaN, zBottom) { NumberOfHorizontalPoints = 1, NumberOfVerticalPoints = 1 - }).SetName("ZTopNaN"); + }).SetName($"{prefix} - ZTopNaN"); yield return new TestCaseData(new MacroStabilityInwardsGrid(xLeft, xRight, zTop, double.NaN) { NumberOfHorizontalPoints = 1, NumberOfVerticalPoints = 1 - }).SetName("ZBottomNaN"); + }).SetName($"{prefix} - ZBottomNaN"); } - private static IEnumerable GetGridSettingsOnlyHorizontalPoints() + private static IEnumerable GetGridSettingsOnlyHorizontalPoints(string prefix) { var gridRightLargerThanLeft = new MacroStabilityInwardsGrid(1, 4, 3, 1) { @@ -1161,10 +1233,10 @@ new Point2D(2, gridRightLargerThanLeft.ZBottom), new Point2D(3, gridRightLargerThanLeft.ZBottom), new Point2D(gridRightLargerThanLeft.XRight, gridRightLargerThanLeft.ZBottom) - }).SetName("XRight > XLeft"); + }).SetName($"{prefix} - XRight > XLeft"); } - private static IEnumerable GetGridSettingsOnlyVerticalPoints() + private static IEnumerable GetGridSettingsOnlyVerticalPoints(string prefix) { var gridTopLargerThanBottom = new MacroStabilityInwardsGrid(1, 3, 4, 1) { @@ -1177,10 +1249,10 @@ new Point2D(gridTopLargerThanBottom.XLeft, 2), new Point2D(gridTopLargerThanBottom.XLeft, 3), new Point2D(gridTopLargerThanBottom.XLeft, gridTopLargerThanBottom.ZTop) - }).SetName("ZTop > ZBottom"); + }).SetName($"{prefix} - ZTop > ZBottom"); } - private static IEnumerable GetGridSettingsOnePoint() + private static IEnumerable GetGridSettingsOnePoint(string prefix) { const double zBottom = 1.0; @@ -1189,10 +1261,10 @@ NumberOfHorizontalPoints = 1, NumberOfVerticalPoints = 1 }; - yield return new TestCaseData(grid).SetName("XRight > XLeft, ZTop > ZBottom"); + yield return new TestCaseData(grid).SetName($"{prefix} - XRight > XLeft, ZTop > ZBottom"); } - private static IEnumerable GetWellDefinedGridSettings() + private static IEnumerable GetWellDefinedGridSettings(string prefix) { var grid = new MacroStabilityInwardsGrid(1, 3, 3, 1) { @@ -1210,7 +1282,7 @@ new Point2D(grid.XLeft, grid.ZTop), new Point2D(2, grid.ZTop), new Point2D(grid.XRight, grid.ZTop) - }).SetName("XRight > XLeft, ZTop > ZBottom"); + }).SetName($"{prefix} - XRight > XLeft, ZTop > ZBottom"); } #endregion