Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsGridTest.cs =================================================================== diff -u -r11f07beedffdae5eee71141830eb73827dd3ae94 -rce5fb67782799e1a30202e917044803e62e7e078 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsGridTest.cs (.../MacroStabilityInwardsGridTest.cs) (revision 11f07beedffdae5eee71141830eb73827dd3ae94) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsGridTest.cs (.../MacroStabilityInwardsGridTest.cs) (revision ce5fb67782799e1a30202e917044803e62e7e078) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using Core.Common.Base.Data; using Core.Common.Data.TestUtil; using Core.Common.TestUtil; @@ -58,6 +59,54 @@ } [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void Constructor_InvalidX_ThrowsArgumentException(double xLeft, double xRight) + { + // Call + TestDelegate test = () => new MacroStabilityInwardsGrid(xLeft, xRight, double.NaN, double.NaN); + + // Assert + const string message = "X links moet kleiner zijn dan X rechts, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + [TestCaseSource(nameof(GetValidPointCombinations))] + public void Constructor_ValidX_ExpectedValues(double xLeft, double xRight) + { + // Call + var grid = new MacroStabilityInwardsGrid(xLeft, xRight, double.NaN, double.NaN); + + // Assert + Assert.AreEqual(xLeft, grid.XLeft); + Assert.AreEqual(xRight, grid.XRight); + } + + [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void Constructor_InvalidZ_ThrowsArgumentException(double zBottom, double zTop) + { + // Call + TestDelegate test = () => new MacroStabilityInwardsGrid(double.NaN, double.NaN, zTop, zBottom); + + // Assert + const string message = "Z boven moet groter zijn dan Z onder, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + [TestCaseSource(nameof(GetValidPointCombinations))] + public void Constructor_ValidZPoints_ExpectedValues(double zBottom, double zTop) + { + // Call + var grid = new MacroStabilityInwardsGrid(double.NaN, double.NaN, zTop, zBottom); + + // Assert + Assert.AreEqual(zTop, grid.ZTop); + Assert.AreEqual(zBottom, grid.ZBottom); + } + + [Test] public void Constructor_SetProperties_ExpectedValues() { // Setup @@ -69,7 +118,7 @@ int numberOfHorizontalPoints = random.Next(1, 100); int numberOfVerticalPoints = random.Next(1, 100); - // call + // Call var grid = new MacroStabilityInwardsGrid(double.NaN, double.NaN, double.NaN, double.NaN) { XLeft = (RoundedDouble) xLeft, @@ -102,6 +151,66 @@ } [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void XLeft_InvalidXLeft_ThrowsArgumentException(double xLeft, double xRight) + { + // Setup + var grid = new MacroStabilityInwardsGrid(double.NaN, xRight, double.NaN, double.NaN); + + // Call + TestDelegate test = () => grid.XLeft = (RoundedDouble) xLeft; + + // Assert + const string message = "X links moet kleiner zijn dan X rechts, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void XRight_InvalidXRight_ThrowsArgumentException(double xLeft, double xRight) + { + // Setup + var grid = new MacroStabilityInwardsGrid(xLeft, double.NaN, double.NaN, double.NaN); + + // Call + TestDelegate test = () => grid.XRight = (RoundedDouble) xRight; + + // Assert + const string message = "X rechts moet groter zijn dan X links, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void ZTop_InvalidZTop_ThrowsArgumentException(double zBottom, double zTop) + { + // Setup + var grid = new MacroStabilityInwardsGrid(double.NaN, double.NaN, double.NaN, zBottom); + + // Call + TestDelegate test = () => grid.ZTop = (RoundedDouble) zTop; + + // Assert + const string message = "Z boven moet groter zijn dan Z onder, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] + [TestCaseSource(nameof(GetInValidPointCombinations))] + public void ZBottom_InvalidZBottom_ThrowsArgumentException(double zBottom, double zTop) + { + // Setup + var grid = new MacroStabilityInwardsGrid(double.NaN, double.NaN, zTop, double.NaN); + + // Call + TestDelegate test = () => grid.ZBottom = (RoundedDouble) zBottom; + + // Assert + const string message = "Z onder moet kleiner zijn dan Z boven, of NaN."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, message); + } + + [Test] [TestCase(-10)] [TestCase(0)] [TestCase(101)] @@ -141,8 +250,8 @@ // Setup var random = new Random(21); var original = new MacroStabilityInwardsGrid(random.NextDouble(), - 1 + random.NextDouble(), - 1 + random.NextDouble(), + random.GetFromRange(2.0, 3.0), + random.GetFromRange(2.0, 3.0), random.NextDouble()) { NumberOfHorizontalPoints = random.Next(1, 100), @@ -155,5 +264,21 @@ // Assert CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); } + + private static IEnumerable GetInValidPointCombinations() + { + yield return new TestCaseData(0.0, 0.0); + yield return new TestCaseData(1.0, 0.0); + yield return new TestCaseData(0.0, -1.0); + } + + private static IEnumerable GetValidPointCombinations() + { + yield return new TestCaseData(double.NaN, 0.0); + yield return new TestCaseData(0.0, double.NaN); + yield return new TestCaseData(double.NaN, double.NaN); + yield return new TestCaseData(0.0, 1.0); + yield return new TestCaseData(-1.0, 1.0); + } } } \ No newline at end of file