Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probability/ProbabilityHelperTest.cs =================================================================== diff -u -ra67c46f098a4f3b87a41e991f14d2f71778c2b28 -r974fb1eadbd8a630c7a992648ad42ac85ec205b1 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probability/ProbabilityHelperTest.cs (.../ProbabilityHelperTest.cs) (revision a67c46f098a4f3b87a41e991f14d2f71778c2b28) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probability/ProbabilityHelperTest.cs (.../ProbabilityHelperTest.cs) (revision 974fb1eadbd8a630c7a992648ad42ac85ec205b1) @@ -19,6 +19,8 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data.Probability; @@ -29,8 +31,8 @@ { [Test] [TestCase(0)] + [TestCase(0.3)] [TestCase(1.0)] - [TestCase(double.NaN)] public void IsValidProbability_ValidProbability_ReturnTrue(double value) { // Call @@ -40,9 +42,23 @@ Assert.IsTrue(isValid); } + [Test] + public void IsValidProbability_NanIsValid_ReturnTrue() + { + // Call + bool isValid = ProbabilityHelper.IsValidProbability(double.NaN, true); + + // Assert + Assert.IsTrue(isValid); + } + + [Test] + [TestCase(-34.56)] [TestCase(-1e-6)] [TestCase(1.0 + 1e-6)] + [TestCase(13.76)] + [TestCase(double.NaN)] public void IsValidProbability_InvalidProbability_ReturnFalse(double value) { // Call @@ -51,5 +67,46 @@ // Assert Assert.IsFalse(isValid); } + + [Test] + [SetCulture("nl-NL")] + [TestCase(-123.456, "A")] + [TestCase(-1e-6, "b")] + [TestCase(1+1e-6, "C")] + [TestCase(456.789, "d")] + [TestCase(double.NaN, "e")] + public void ValidateProbability_InvalidProbability_ThrowsArgumentOutOfRangeException(double invalidProbabilityValue, string expectedParamName) + { + // Call + TestDelegate call = () => ProbabilityHelper.ValidateProbability(invalidProbabilityValue, expectedParamName); + + // Assert + const string message = "Kans moet in het bereik [0,0, 1,0] liggen."; + string paramName = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, message).ParamName; + Assert.AreEqual(expectedParamName, paramName); + } + + [Test] + [TestCase(0)] + [TestCase(0.7)] + [TestCase(1)] + public void ValidateProbability_ValidProbability_DoesNotThrow(double probability) + { + // Call + TestDelegate call = () => ProbabilityHelper.ValidateProbability(probability, "A"); + + // Assert + Assert.DoesNotThrow(call); + } + + [Test] + public void ValidateProbability_AllowNaN_DoesNotThrow() + { + // Call + TestDelegate call = () => ProbabilityHelper.ValidateProbability(double.NaN, "A", true); + + // Assert + Assert.DoesNotThrow(call); + } } } \ No newline at end of file