Index: Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityParsingHelper.cs =================================================================== diff -u -rbaf3c6613fea1a4f12451bad110647573050dd75 -r5f48daec42d433dee498af00bde38ccb1cecb5a3 --- Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityParsingHelper.cs (.../ProbabilityParsingHelper.cs) (revision baf3c6613fea1a4f12451bad110647573050dd75) +++ Riskeer/Common/src/Riskeer.Common.Forms/Helpers/ProbabilityParsingHelper.cs (.../ProbabilityParsingHelper.cs) (revision 5f48daec42d433dee498af00bde38ccb1cecb5a3) @@ -48,12 +48,13 @@ try { - if (!value.StartsWith(returnPeriodNotation)) + string trimmedString = value.Trim(); + if (!trimmedString.StartsWith(returnPeriodNotation)) { return Convert.ToDouble(value); } - - string returnPeriodValue = value.Substring(2).ToLower(); + + string returnPeriodValue = trimmedString.Substring(2).ToLower(); return returnPeriodValue != CommonBaseResources.RoundedDouble_ToString_PositiveInfinity.ToLower() ? 1 / Convert.ToDouble(returnPeriodValue) : 0.0; Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityParsingHelperTest.cs =================================================================== diff -u -r9111b22be47e41193ab7bd5d3e1c06aa8dffee1a -r5f48daec42d433dee498af00bde38ccb1cecb5a3 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityParsingHelperTest.cs (.../ProbabilityParsingHelperTest.cs) (revision 9111b22be47e41193ab7bd5d3e1c06aa8dffee1a) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/ProbabilityParsingHelperTest.cs (.../ProbabilityParsingHelperTest.cs) (revision 5f48daec42d433dee498af00bde38ccb1cecb5a3) @@ -46,7 +46,7 @@ [Test] [SetCulture("nl-NL")] - [TestCase("1/25", 0.04)] + [TestCase("1/25 ", 0.04)] [TestCase("1/2,500", 0.4)] [TestCase("1/2.500", 0.0004)] [TestCase("1e-3", 0.001)] @@ -56,9 +56,9 @@ [TestCase("1/oneINdig", 0.0)] [TestCase("1/-1.000", -0.001)] [TestCase("1/-10", -0.1)] - [TestCase("1/-2,5", -0.4)] - [TestCase("-0,5", -0.5)] - [TestCase("-1", -1.0)] + [TestCase(" 1/-2,5", -0.4)] + [TestCase(" -0,5", -0.5)] + [TestCase("-1 ", -1.0)] [TestCase("-1e-2", -0.01)] public void Parse_ValidStringInDutchCulture_ReturnsExpectedOutput(string value, double expectedProbability) { @@ -71,6 +71,7 @@ [Test] [SetCulture("en-US")] + [TestCase("1/25 ", 0.04)] [TestCase("1/25", 0.04)] [TestCase("1/2.5", 0.4)] [TestCase("1e-3", 0.001)] @@ -80,9 +81,9 @@ [TestCase("1/oneINdig", 0.0)] [TestCase("1/-1,000", -0.001)] [TestCase("1/-10", -0.1)] - [TestCase("1/-2.5", -0.4)] - [TestCase("-0.5", -0.5)] - [TestCase("-1", -1.0)] + [TestCase(" 1/-2.5", -0.4)] + [TestCase(" -0.5", -0.5)] + [TestCase("-1 ", -1.0)] [TestCase("-1e-2", -0.01)] public void Parse_ValidStringInEnglishCulture_ReturnsExpectedOutput(string value, double expectedProbability) { @@ -109,10 +110,12 @@ } [Test] - public void Parse_ValueTooLargeToStoreInDouble_ThrowsProbabilityParsingException() + [TestCase("1")] + [TestCase("-1")] + public void Parse_ValueTooLargeToStoreInDouble_ThrowsProbabilityParsingException(string prefix) { // Setup - string invalidValue = "1" + double.MaxValue.ToString(CultureInfo.CurrentCulture); + string invalidValue = prefix + double.MaxValue.ToString(CultureInfo.CurrentCulture); // Call void Call() => ProbabilityParsingHelper.Parse(invalidValue);