Index: Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityFormattingHelper.cs =================================================================== diff -u -r96ccefa48aa5c97c949f7a7858fcb4d3dc727a3a -ref7d25537327166e760b4077dffe51345f6b5616 --- Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityFormattingHelper.cs (.../ProbabilityFormattingHelper.cs) (revision 96ccefa48aa5c97c949f7a7858fcb4d3dc727a3a) +++ Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityFormattingHelper.cs (.../ProbabilityFormattingHelper.cs) (revision ef7d25537327166e760b4077dffe51345f6b5616) @@ -49,6 +49,33 @@ } /// + /// Formats the specified probability, including the discrete numbers , + /// and . + /// + /// The probability. + /// The formatted text. + /// Thrown when the probability cannot be formatted as a string. + public static string FormatWithDiscreteNumbers(double probability) + { + if (double.IsNaN(probability)) + { + return Resources.RoundedDouble_No_result_dash; + } + + if (double.IsNegativeInfinity(probability)) + { + return CommonBaseResources.RoundedDouble_ToString_NegativeInfinity; + } + + if (double.IsPositiveInfinity(probability)) + { + return CommonBaseResources.RoundedDouble_ToString_PositiveInfinity; + } + + return Format(probability); + } + + /// /// Formats the specified return period to a probability. /// /// The return period. Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs =================================================================== diff -u -r96ccefa48aa5c97c949f7a7858fcb4d3dc727a3a -ref7d25537327166e760b4077dffe51345f6b5616 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs (.../ProbabilityFormattingHelperTest.cs) (revision 96ccefa48aa5c97c949f7a7858fcb4d3dc727a3a) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityFormattingHelperTest.cs (.../ProbabilityFormattingHelperTest.cs) (revision ef7d25537327166e760b4077dffe51345f6b5616) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using NUnit.Framework; using Riskeer.Common.Forms.Helpers; @@ -39,13 +40,7 @@ [Test] [SetCulture("nl-NL")] - [TestCase(1.0, "1/1")] - [TestCase(0.5, "1/2")] - [TestCase(0.6, "1/2")] - [TestCase(0.0001, "1/10.000")] - [TestCase(0.000000123456789, "1/8.100.000")] - [TestCase(-0.0001, "1/-10.000")] - [TestCase(-0.5, "1/-2")] + [TestCaseSource(nameof(GetProbabilityNotZeroTestCases))] public void Format_ProbabilityNotZero_ReturnOneOverReturnPeriod(double probability, string expectedText) { // Call @@ -56,6 +51,41 @@ } [Test] + public void FormatWithDiscreteNumbers_ProbabilityIsZero_ReturnOneOverInfinity() + { + // Call + string text = ProbabilityFormattingHelper.FormatWithDiscreteNumbers(0); + + // Assert + Assert.AreEqual("1/Oneindig", text); + } + + [Test] + [TestCase(double.NaN, "-")] + [TestCase(double.NegativeInfinity, "-Oneindig")] + [TestCase(double.PositiveInfinity, "Oneindig")] + public void FormatWithDiscreteNumbers_ProbabilityDiscreteNumber_ReturnsExpectedTextRepresentation(double probability, string expectedText) + { + // Call + string text = ProbabilityFormattingHelper.FormatWithDiscreteNumbers(probability); + + // Assert + Assert.AreEqual(expectedText, text); + } + + [Test] + [SetCulture("nl-NL")] + [TestCaseSource(nameof(GetProbabilityNotZeroTestCases))] + public void FormatWithDiscreteNumbers_ProbabilityNotZero_ReturnOneOverReturnPeriod(double probability, string expectedText) + { + // Call + string text = ProbabilityFormattingHelper.FormatWithDiscreteNumbers(probability); + + // Assert + Assert.AreEqual(expectedText, text); + } + + [Test] public void FormatFromReturnPeriod_ReturnPeriodIsZero_ReturnOneOverInfinity() { // Call @@ -81,5 +111,16 @@ // Assert Assert.AreEqual(expectedText, text); } + + private static IEnumerable GetProbabilityNotZeroTestCases() + { + yield return new TestCaseData(1.0, "1/1"); + yield return new TestCaseData(0.5, "1/2"); + yield return new TestCaseData(0.6, "1/2"); + yield return new TestCaseData(0.0001, "1/10.000"); + yield return new TestCaseData(0.000000123456789, "1/8.100.000"); + yield return new TestCaseData(-0.0001, "1/-10.000"); + yield return new TestCaseData(-0.5, "1/-2"); + } } } \ No newline at end of file