Index: Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs (.../RoundedDouble.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Core/Common/src/Core.Common.Base/Data/RoundedDouble.cs (.../RoundedDouble.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -73,13 +73,30 @@ public static RoundedDouble operator -(RoundedDouble left, RoundedDouble right) { - return new RoundedDouble(Math.Min(left.numberOfDecimalPlaces, right.numberOfDecimalPlaces), + int smallestNumberOfDecimalPlaces = Math.Min(left.numberOfDecimalPlaces, right.numberOfDecimalPlaces); + return new RoundedDouble(smallestNumberOfDecimalPlaces, left.value - right.value); } + public static RoundedDouble operator *(RoundedDouble left, double right) + { + return new RoundedDouble(left.numberOfDecimalPlaces, left.value * right); + } + + public static RoundedDouble operator *(double left, RoundedDouble right) + { + return new RoundedDouble(right.numberOfDecimalPlaces, left * right.value); + } + + public static RoundedDouble operator *(RoundedDouble left, RoundedDouble right) + { + int smallestNumberOfDecimalPlaces = Math.Min(left.numberOfDecimalPlaces, right.numberOfDecimalPlaces); + return new RoundedDouble(smallestNumberOfDecimalPlaces, left.value * right.value); + } + public static implicit operator double(RoundedDouble d) { - return d.Value; + return d.value; } public static explicit operator RoundedDouble(Double d) Index: Core/Common/test/Core.Common.Base.Test/Data/RoundedDoubleTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Core/Common/test/Core.Common.Base.Test/Data/RoundedDoubleTest.cs (.../RoundedDoubleTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Core/Common/test/Core.Common.Base.Test/Data/RoundedDoubleTest.cs (.../RoundedDoubleTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -567,5 +567,70 @@ Assert.AreEqual(lowestNumberOfDecimalPlaces, diff.NumberOfDecimalPlaces); Assert.AreEqual(8.9, diff.Value); } + + [Test] + public void OperatorTimes_RoundedDoubleTimesDouble_ReturnResultAsRoundedDoublePreservingNumberOfDecimalPlaces() + { + // Setup + var roundedDouble = new RoundedDouble(3, 1.234); + double doubleValue = 5.67891234; + + // Call + RoundedDouble result1 = roundedDouble * doubleValue; + RoundedDouble result2 = doubleValue * roundedDouble; + + // Assert + Assert.AreEqual(roundedDouble.NumberOfDecimalPlaces, result1.NumberOfDecimalPlaces); + Assert.AreEqual(roundedDouble.NumberOfDecimalPlaces, result2.NumberOfDecimalPlaces); + const double expectedValue = 7.008; + Assert.AreEqual(expectedValue, result1.Value); + Assert.AreEqual(expectedValue, result2.Value); + } + + [Test] + public void OperatorTimes_LeftHasLeastPrecision_ResultIsRoundedDoubleWithLeastNumberOfDecimalPlaces() + { + // Setup + var roundedDouble1 = new RoundedDouble(2, 1.23); + var roundedDouble2 = new RoundedDouble(5, -3.45678); + + // Call + RoundedDouble result = roundedDouble1 * roundedDouble2; + + // Assert + Assert.AreEqual(2, result.NumberOfDecimalPlaces); + Assert.AreEqual(-4.25, result.Value); + } + + [Test] + public void OperatorTimes_RightHasLeastPrecision_ResultIsRoundedDoubleWithLeastNumberOfDecimalPlaces() + { + // Setup + var roundedDouble1 = new RoundedDouble(4, -4.5678); + var roundedDouble2 = new RoundedDouble(3, -9.123); + + // Call + RoundedDouble result = roundedDouble1 * roundedDouble2; + + // Assert + Assert.AreEqual(3, result.NumberOfDecimalPlaces); + Assert.AreEqual(41.672, result.Value); + } + + [Test] + public void OperatorTimes_TwoRoundedDoubles_MultiplicationIsCommutative() + { + // Setup + var roundedDouble1 = new RoundedDouble(1, 1.1); + var roundedDouble2 = new RoundedDouble(2, 2.22); + + // Call + RoundedDouble result1 = roundedDouble1 * roundedDouble2; + RoundedDouble result2 = roundedDouble2 * roundedDouble1; + + // Assert + Assert.AreEqual(result1.NumberOfDecimalPlaces, result2.NumberOfDecimalPlaces); + Assert.AreEqual(result1.Value, result2.Value); + } } } \ No newline at end of file Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs (.../AddNewDemoDikeAssessmentSectionCommandTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoDikeAssessmentSectionCommandTest.cs (.../AddNewDemoDikeAssessmentSectionCommandTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -135,11 +135,11 @@ PipingCalculationService.Calculate(calculation); Assert.IsTrue(calculation.HasOutput); Assert.AreEqual(99.0, calculation.Output.HeaveFactorOfSafety, 1e-3); - Assert.AreEqual(116.706, calculation.Output.HeaveZValue, 1e-3); + Assert.AreEqual(116.586, calculation.Output.HeaveZValue, 1e-3); Assert.AreEqual(99.0, calculation.Output.UpliftFactorOfSafety, 1e-3); Assert.AreEqual(3.655, calculation.Output.UpliftZValue, 1e-3); Assert.AreEqual(-1.391, calculation.Output.SellmeijerFactorOfSafety, 1e-3); - Assert.AreEqual(3.248, calculation.Output.SellmeijerZValue, 1e-3); + Assert.AreEqual(3.249, calculation.Output.SellmeijerZValue, 1e-3); } private static void AssertExpectedPipingInput(PipingInput inputParameters) Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingInput.cs (.../PipingInput.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -70,19 +70,19 @@ ThicknessCoverageLayer = new LognormalDistribution(2) { Mean = (RoundedDouble)double.NaN, - StandardDeviation = 0.5 + StandardDeviation = (RoundedDouble)0.5 }; SeepageLength = new LognormalDistribution(2) { Mean = (RoundedDouble)double.NaN, - StandardDeviation = double.NaN + StandardDeviation = (RoundedDouble)double.NaN }; Diameter70 = new LognormalDistribution(2); DarcyPermeability = new LognormalDistribution(3); ThicknessAquiferLayer = new LognormalDistribution(2) { Mean = (RoundedDouble)double.NaN, - StandardDeviation = 0.5 + StandardDeviation = (RoundedDouble)0.5 }; } Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/IDistribution.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/IDistribution.cs (.../IDistribution.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/IDistribution.cs (.../IDistribution.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -39,6 +39,6 @@ /// Gets or sets the standard deviation (square root of the Var(X)) of the distribution. /// /// Standard deviation is less than 0. - double StandardDeviation { get; set; } + RoundedDouble StandardDeviation { get; set; } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/LognormalDistribution.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/LognormalDistribution.cs (.../LognormalDistribution.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/LognormalDistribution.cs (.../LognormalDistribution.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -32,7 +32,7 @@ /// public class LognormalDistribution : IDistribution { - private double standardDeviation; + private RoundedDouble standardDeviation; private RoundedDouble mean; /// @@ -49,11 +49,11 @@ { // This causes the default initialization set mean to 0, which is invalid. throw new ArgumentOutOfRangeException("numberOfDecimalPlaces", - "Value must be in range [1, 15]"); + "Value must be in range [1, 15]."); } // Simplified calculation mean and standard deviation given mu=0 and sigma=1. mean = new RoundedDouble(numberOfDecimalPlaces, Math.Exp(-0.5)); - StandardDeviation = Math.Sqrt((Math.Exp(1) - 1) * Math.Exp(1)); + standardDeviation = new RoundedDouble(numberOfDecimalPlaces, Math.Sqrt((Math.Exp(1) - 1) * Math.Exp(1))); } /// @@ -76,7 +76,7 @@ } } - public double StandardDeviation + public RoundedDouble StandardDeviation { get { @@ -88,7 +88,7 @@ { throw new ArgumentOutOfRangeException("value", Resources.StandardDeviation_Should_be_greater_than_or_equal_to_zero); } - standardDeviation = value; + standardDeviation = value.ToPrecision(standardDeviation.NumberOfDecimalPlaces); } } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/NormalDistribution.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/NormalDistribution.cs (.../NormalDistribution.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Probabilistics/NormalDistribution.cs (.../NormalDistribution.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -32,21 +32,21 @@ /// public class NormalDistribution : IDistribution { - private double standardDeviation; + private RoundedDouble standardDeviation; private RoundedDouble mean; /// /// Initializes a new instance of the class, /// initialized as the standard normal distribution. /// - /// The number of decimal places. + /// The number of decimal places of the distribution. /// /// Thrown when is not in range [0, ]. /// public NormalDistribution(int numberOfDecimalPlaces) { mean = new RoundedDouble(numberOfDecimalPlaces, 0.0); - StandardDeviation = 1.0; + standardDeviation = new RoundedDouble(numberOfDecimalPlaces, 1.0); } public RoundedDouble Mean @@ -61,7 +61,7 @@ } } - public double StandardDeviation + public RoundedDouble StandardDeviation { get { @@ -73,7 +73,7 @@ { throw new ArgumentOutOfRangeException("value", Resources.StandardDeviation_Should_be_greater_than_or_equal_to_zero); } - standardDeviation = value; + standardDeviation = value.ToPrecision(standardDeviation.NumberOfDecimalPlaces); } } } Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingInputTest.cs (.../PipingInputTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -28,26 +28,33 @@ Assert.IsInstanceOf(inputParameters.PhreaticLevelExit); Assert.AreEqual(0, inputParameters.PhreaticLevelExit.Mean.Value); Assert.AreEqual(3, inputParameters.PhreaticLevelExit.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(1, inputParameters.PhreaticLevelExit.StandardDeviation); + Assert.AreEqual(1, inputParameters.PhreaticLevelExit.StandardDeviation.Value); + Assert.AreEqual(3, inputParameters.PhreaticLevelExit.StandardDeviation.NumberOfDecimalPlaces); double defaultLogNormalMean = Math.Exp(-0.5); double defaultLogNormalStandardDev = Math.Sqrt((Math.Exp(1) - 1) * Math.Exp(1)); Assert.IsInstanceOf(inputParameters.DampingFactorExit); Assert.AreEqual(1, inputParameters.DampingFactorExit.Mean.Value); Assert.AreEqual(3, inputParameters.DampingFactorExit.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.DampingFactorExit.StandardDeviation); + Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.DampingFactorExit.StandardDeviation, + GetErrorTolerance(inputParameters.DampingFactorExit.StandardDeviation)); + Assert.AreEqual(3, inputParameters.DampingFactorExit.StandardDeviation.NumberOfDecimalPlaces); Assert.IsInstanceOf(inputParameters.Diameter70); Assert.AreEqual(defaultLogNormalMean, inputParameters.Diameter70.Mean, - Math.Pow(10.0, -inputParameters.Diameter70.Mean.NumberOfDecimalPlaces)); + GetErrorTolerance(inputParameters.Diameter70.Mean)); Assert.AreEqual(2, inputParameters.Diameter70.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.Diameter70.StandardDeviation); + Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.Diameter70.StandardDeviation, + GetErrorTolerance(inputParameters.Diameter70.StandardDeviation)); + Assert.AreEqual(2, inputParameters.Diameter70.StandardDeviation.NumberOfDecimalPlaces); Assert.IsInstanceOf(inputParameters.DarcyPermeability); Assert.AreEqual(defaultLogNormalMean, inputParameters.DarcyPermeability.Mean, - Math.Pow(10.0, -inputParameters.DarcyPermeability.Mean.NumberOfDecimalPlaces)); + GetErrorTolerance(inputParameters.DarcyPermeability.Mean)); Assert.AreEqual(3, inputParameters.DarcyPermeability.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.DarcyPermeability.StandardDeviation); + Assert.AreEqual(defaultLogNormalStandardDev, inputParameters.DarcyPermeability.StandardDeviation, + GetErrorTolerance(inputParameters.DarcyPermeability.StandardDeviation)); + Assert.AreEqual(3, inputParameters.DarcyPermeability.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0, inputParameters.PiezometricHeadExit); Assert.AreEqual(0, inputParameters.PiezometricHeadPolder); @@ -70,17 +77,20 @@ Assert.IsInstanceOf(inputParameters.ThicknessCoverageLayer); Assert.IsNaN(inputParameters.ThicknessCoverageLayer.Mean); Assert.AreEqual(2, inputParameters.ThicknessCoverageLayer.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(0.5, inputParameters.ThicknessCoverageLayer.StandardDeviation); + Assert.AreEqual(0.5, inputParameters.ThicknessCoverageLayer.StandardDeviation.Value); + Assert.AreEqual(2, inputParameters.ThicknessCoverageLayer.StandardDeviation.NumberOfDecimalPlaces); Assert.IsInstanceOf(inputParameters.ThicknessAquiferLayer); Assert.IsNaN(inputParameters.ThicknessAquiferLayer.Mean); Assert.AreEqual(2, inputParameters.ThicknessAquiferLayer.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(0.5, inputParameters.ThicknessAquiferLayer.StandardDeviation); + Assert.AreEqual(0.5, inputParameters.ThicknessAquiferLayer.StandardDeviation.Value); + Assert.AreEqual(2, inputParameters.ThicknessAquiferLayer.StandardDeviation.NumberOfDecimalPlaces); Assert.IsInstanceOf(inputParameters.SeepageLength); Assert.IsNaN(inputParameters.SeepageLength.Mean); Assert.AreEqual(2, inputParameters.SeepageLength.Mean.NumberOfDecimalPlaces); Assert.IsNaN(inputParameters.SeepageLength.StandardDeviation); + Assert.AreEqual(2, inputParameters.SeepageLength.StandardDeviation.NumberOfDecimalPlaces); Assert.IsNaN(inputParameters.ExitPointL); Assert.AreEqual(2, inputParameters.ExitPointL.NumberOfDecimalPlaces); @@ -92,6 +102,11 @@ Assert.IsNaN(inputParameters.AssessmentLevel); } + private static double GetErrorTolerance(RoundedDouble roundedDouble) + { + return Math.Pow(10.0, -roundedDouble.NumberOfDecimalPlaces); + } + [Test] public void Constructor_GeneralPipingInputIsNull_ArgumentNullException() { @@ -185,7 +200,7 @@ // Assert Assert.AreEqual(expectedSeepageLength, pipingInput.SeepageLength.Mean.Value); - Assert.AreEqual(expectedSeepageLength * 0.1, pipingInput.SeepageLength.StandardDeviation); + Assert.AreEqual(expectedSeepageLength * 0.1, pipingInput.SeepageLength.StandardDeviation, GetErrorTolerance(pipingInput.SeepageLength.StandardDeviation)); } [Test] Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionDesignVariableTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionDesignVariableTest.cs (.../LognormalDistributionDesignVariableTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionDesignVariableTest.cs (.../LognormalDistributionDesignVariableTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -49,7 +49,7 @@ var lognormalDistribution = new LognormalDistribution(4) { Mean = (RoundedDouble)expectedValue, - StandardDeviation = Math.Sqrt(variance) + StandardDeviation = (RoundedDouble)Math.Sqrt(variance) }; var designVariable = new LognormalDistributionDesignVariable(lognormalDistribution) Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionTest.cs (.../LognormalDistributionTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/LognormalDistributionTest.cs (.../LognormalDistributionTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -1,6 +1,7 @@ using System; using Core.Common.Base.Data; +using Core.Common.TestUtil; using NUnit.Framework; @@ -22,13 +23,14 @@ // Assert Assert.IsInstanceOf(distribution); - Assert.AreEqual(Math.Exp(-0.5), distribution.Mean, Math.Pow(10.0, -numberOfDecimalPlaces)); + double expectedAccuracy = Math.Pow(10.0, -numberOfDecimalPlaces); + Assert.AreEqual(Math.Exp(-0.5), distribution.Mean, expectedAccuracy); Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(Math.Sqrt((Math.Exp(1)-1)*Math.Exp(1)), distribution.StandardDeviation); + Assert.AreEqual(Math.Sqrt((Math.Exp(1) - 1) * Math.Exp(1)), distribution.StandardDeviation, expectedAccuracy); + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); } [Test] - [TestCase(0)] public void Constructor_InvalidNumberOfDecimalPlaces_ThrowArgumentOutOfRangeException() { // Setup @@ -37,7 +39,7 @@ TestDelegate call = () => new LognormalDistribution(0); // Assert - Assert.Throws(call); + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, "Value must be in range [1, 15]."); } [Test] @@ -63,30 +65,68 @@ public void Mean_SettingValidValue_ValueIsSet(double newMean) { // Setup - var distribution = new LognormalDistribution(4); + const int numberOfDecimalPlaces = 4; + var distribution = new LognormalDistribution(numberOfDecimalPlaces); // Call distribution.Mean = (RoundedDouble)newMean; // Assert Assert.AreEqual(newMean, distribution.Mean, 1e-4); + Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); } [Test] - [TestCase(0 - 1e-6)] + [TestCase(1, 1.2)] + [TestCase(3, 1.235)] + [TestCase(4, 1.2345)] + [TestCase(15, 1.234500000000000)] + public void Mean_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(int numberOfDecimalPlaces, double expectedStandardDeviation) + { + // Setup + var distribution = new LognormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.Mean = new RoundedDouble(4, 1.2345); + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); + Assert.AreEqual(expectedStandardDeviation, distribution.Mean.Value); + } + + [Test] + [TestCase(0 - 1e-4)] [TestCase(-4)] - public void StandardDeviation_SettingNotGreaterThan0_ThrowArgumentOutOfRangeException(double newStd) + public void StandardDeviation_SettingToLessThan0_ThrowArgumentOutOfRangeException(double newStd) { // Setup var distribution = new LognormalDistribution(4); // Call - TestDelegate call = () => distribution.StandardDeviation = newStd; + TestDelegate call = () => distribution.StandardDeviation = (RoundedDouble)newStd; // Assert ArgumentException exception = Assert.Throws(call); string customMessagePart = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; Assert.AreEqual("Standaard afwijking (\u03C3) moet groter zijn dan of gelijk zijn aan 0.", customMessagePart); } + + [Test] + [TestCase(1, 5.7)] + [TestCase(2, 5.68)] + [TestCase(3, 5.678)] + [TestCase(15, 5.678000000000000)] + public void StandardDeviation_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(int numberOfDecimalPlaces, double expectedStandardDeviation) + { + // Setup + var distribution = new LognormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.StandardDeviation = new RoundedDouble(3, 5.678); + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); + Assert.AreEqual(expectedStandardDeviation, distribution.StandardDeviation.Value); + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionDesignVariableTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionDesignVariableTest.cs (.../NormalDistributionDesignVariableTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionDesignVariableTest.cs (.../NormalDistributionDesignVariableTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -49,7 +49,7 @@ var normalDistribution = new NormalDistribution(4) { Mean = (RoundedDouble)expectedValue, - StandardDeviation = Math.Sqrt(variance) + StandardDeviation = (RoundedDouble)Math.Sqrt(variance) }; var designVariable = new NormalDistributionDesignVariable(normalDistribution) Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionTest.cs (.../NormalDistributionTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/NormalDistributionTest.cs (.../NormalDistributionTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -1,5 +1,8 @@ using System; +using Core.Common.Base.Data; +using Core.Common.TestUtil; + using NUnit.Framework; using Ringtoets.Piping.Data.Probabilistics; @@ -20,26 +23,62 @@ // Assert Assert.IsInstanceOf(distribution); - Assert.AreEqual(0.0, distribution.Mean, Math.Pow(10.0, -numberOfDecimalPlaces)); + Assert.AreEqual(0.0, distribution.Mean.Value); Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); - Assert.AreEqual(1.0, distribution.StandardDeviation); + Assert.AreEqual(1.0, distribution.StandardDeviation.Value); + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); } [Test] - [TestCase(0 - 1e-6)] + [TestCase(0, 1.0)] + [TestCase(3, 1.235)] + [TestCase(4, 1.2345)] + [TestCase(15, 1.234500000000000)] + public void Mean_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(int numberOfDecimalPlaces, double expectedStandardDeviation) + { + // Setup + var distribution = new NormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.Mean = new RoundedDouble(4, 1.2345); + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); + Assert.AreEqual(expectedStandardDeviation, distribution.Mean.Value); + } + + [Test] + [TestCase(0 - 1e-2)] [TestCase(-4)] - public void StandardDeviation_SettingNotGreaterThan0_ThrowArgumentOutOfRangeException(double newStd) + public void StandardDeviation_SettingToLessThan0_ThrowArgumentOutOfRangeException(double newStd) { // Setup var distribution = new NormalDistribution(2); // Call - TestDelegate call = () => distribution.StandardDeviation = newStd; + TestDelegate call = () => distribution.StandardDeviation = (RoundedDouble)newStd; // Assert - ArgumentException exception = Assert.Throws(call); - string customMessagePart = exception.Message.Split(new []{Environment.NewLine}, StringSplitOptions.None)[0]; - Assert.AreEqual("Standaard afwijking (\u03C3) moet groter zijn dan of gelijk zijn aan 0.", customMessagePart); + const string expectedMessage = "Standaard afwijking (\u03C3) moet groter zijn dan of gelijk zijn aan 0."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); } + + [Test] + [TestCase(0, 6.0)] + [TestCase(2, 5.68)] + [TestCase(3, 5.678)] + [TestCase(15, 5.678000000000000)] + public void StandardDeviation_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(int numberOfDecimalPlaces, double expectedStandardDeviation) + { + // Setup + var distribution = new NormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.StandardDeviation = new RoundedDouble(3, 5.678); + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); + Assert.AreEqual(expectedStandardDeviation, distribution.StandardDeviation.Value); + } } } \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/ShiftedLognormalDistributionDesignVariableTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/ShiftedLognormalDistributionDesignVariableTest.cs (.../ShiftedLognormalDistributionDesignVariableTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Probabilistics/ShiftedLognormalDistributionDesignVariableTest.cs (.../ShiftedLognormalDistributionDesignVariableTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -52,7 +52,7 @@ var shiftedLognormalDistribution = new ShiftedLognormalDistribution(4) { Mean = (RoundedDouble)expectedValue, - StandardDeviation = Math.Sqrt(variance), + StandardDeviation = (RoundedDouble)Math.Sqrt(variance), Shift = shift }; @@ -83,7 +83,7 @@ var shiftedLognormalDistribution = new ShiftedLognormalDistribution(6) { Mean = (RoundedDouble)expectedValue, - StandardDeviation = Math.Sqrt(variance), + StandardDeviation = (RoundedDouble)Math.Sqrt(variance), Shift = 0 }; Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/Extensions/PipingInputExtensionsTest.cs (.../PipingInputExtensionsTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -117,7 +117,7 @@ // Assert Assert.AreEqual(2.0, inputParameters.SeepageLength.Mean.Value); - Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation); + Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation.Value); Assert.AreEqual(secondPointX - firstPointX, inputParameters.ExitPointL.Value); } @@ -146,7 +146,7 @@ // Assert Assert.AreEqual(2.0, inputParameters.SeepageLength.Mean.Value); - Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation); + Assert.AreEqual(0.2, inputParameters.SeepageLength.StandardDeviation.Value); Assert.AreEqual(thirdPointX - firstPointX, inputParameters.ExitPointL.Value); } Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/LognormalDistributionDesignVariableTypeConverterTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/LognormalDistributionDesignVariableTypeConverterTest.cs (.../LognormalDistributionDesignVariableTypeConverterTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/LognormalDistributionDesignVariableTypeConverterTest.cs (.../LognormalDistributionDesignVariableTypeConverterTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -50,7 +50,7 @@ var distribution = new LognormalDistribution(1) { Mean = (RoundedDouble)1.1, - StandardDeviation = 2.2 + StandardDeviation = (RoundedDouble)2.2 }; var designVariable = new LognormalDistributionDesignVariable(distribution); @@ -110,7 +110,7 @@ var stdPropertyDescriptor = properties[2]; Assert.AreEqual(distribution.GetType(), stdPropertyDescriptor.ComponentType); - Assert.AreEqual(typeof(double), stdPropertyDescriptor.PropertyType); + Assert.AreEqual(typeof(RoundedDouble), stdPropertyDescriptor.PropertyType); Assert.IsFalse(stdPropertyDescriptor.IsReadOnly); Assert.AreEqual("Standaardafwijking", stdPropertyDescriptor.DisplayName); Assert.AreEqual("De standaardafwijking van de lognormale verdeling.", stdPropertyDescriptor.Description); @@ -163,14 +163,7 @@ // Event const double newDoubleValue = 2.3; - if (propertyIndexToChange == 1) - { - properties[propertyIndexToChange].SetValue(dampingFactorExitHeave, (RoundedDouble)newDoubleValue); - } - else - { - properties[propertyIndexToChange].SetValue(dampingFactorExitHeave, newDoubleValue); - } + properties[propertyIndexToChange].SetValue(dampingFactorExitHeave, (RoundedDouble)newDoubleValue); // Result switch (propertyIndexToChange) @@ -179,7 +172,7 @@ Assert.AreEqual(newDoubleValue, inputParameters.DampingFactorExit.Mean.Value); break; case 2: - Assert.AreEqual(newDoubleValue, inputParameters.DampingFactorExit.StandardDeviation); + Assert.AreEqual(newDoubleValue, inputParameters.DampingFactorExit.StandardDeviation.Value); break; } mocks.VerifyAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/NormalDistributionDesignVariableTypeConverterTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/NormalDistributionDesignVariableTypeConverterTest.cs (.../NormalDistributionDesignVariableTypeConverterTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/NormalDistributionDesignVariableTypeConverterTest.cs (.../NormalDistributionDesignVariableTypeConverterTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -50,7 +50,7 @@ var distribution = new NormalDistribution(2) { Mean = (RoundedDouble)1.1, - StandardDeviation = 2.2 + StandardDeviation = (RoundedDouble)2.2 }; var designVariable = new NormalDistributionDesignVariable(distribution); var converter = new NormalDistributionDesignVariableTypeConverter(); @@ -109,7 +109,7 @@ var stdPropertyDescriptor = properties[2]; Assert.AreEqual(distribution.GetType(), stdPropertyDescriptor.ComponentType); - Assert.AreEqual(typeof(double), stdPropertyDescriptor.PropertyType); + Assert.AreEqual(typeof(RoundedDouble), stdPropertyDescriptor.PropertyType); Assert.IsFalse(stdPropertyDescriptor.IsReadOnly); Assert.AreEqual("Standaardafwijking", stdPropertyDescriptor.DisplayName); Assert.AreEqual("De standaardafwijking van de normale verdeling.", stdPropertyDescriptor.Description); @@ -161,14 +161,7 @@ // Event const double newValue = 2.3; - if (propertyIndexToChange == 1) - { - properties[propertyIndexToChange].SetValue(phreaticLevelExitHeave, (RoundedDouble)newValue); - } - else - { - properties[propertyIndexToChange].SetValue(phreaticLevelExitHeave, newValue); - } + properties[propertyIndexToChange].SetValue(phreaticLevelExitHeave, (RoundedDouble)newValue); // Result switch (propertyIndexToChange) @@ -177,7 +170,7 @@ Assert.AreEqual(newValue, inputParameters.PhreaticLevelExit.Mean.Value); break; case 2: - Assert.AreEqual(newValue, inputParameters.PhreaticLevelExit.StandardDeviation); + Assert.AreEqual(newValue, inputParameters.PhreaticLevelExit.StandardDeviation.Value); break; } mocks.VerifyAll(); Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/ShiftedLognormalDistributionDesignVariableTypeConverterTest.cs =================================================================== diff -u -r93b256575fba3e4068baadeeb62140533336371a -r28efef3cbb613e85c8ea893493e2618de2236f0b --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/ShiftedLognormalDistributionDesignVariableTypeConverterTest.cs (.../ShiftedLognormalDistributionDesignVariableTypeConverterTest.cs) (revision 93b256575fba3e4068baadeeb62140533336371a) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/TypeConverters/ShiftedLognormalDistributionDesignVariableTypeConverterTest.cs (.../ShiftedLognormalDistributionDesignVariableTypeConverterTest.cs) (revision 28efef3cbb613e85c8ea893493e2618de2236f0b) @@ -42,7 +42,7 @@ var distribution = new ShiftedLognormalDistribution(5) { Mean = (RoundedDouble)1.1, - StandardDeviation = 2.2, + StandardDeviation = (RoundedDouble)2.2, Shift = 3.3 }; var designVariable = new ShiftedLognormalDistributionDesignVariable(distribution); @@ -102,7 +102,7 @@ var stdPropertyDescriptor = properties[2]; Assert.AreEqual(distribution.GetType().BaseType, stdPropertyDescriptor.ComponentType); - Assert.AreEqual(typeof(double), stdPropertyDescriptor.PropertyType); + Assert.AreEqual(typeof(RoundedDouble), stdPropertyDescriptor.PropertyType); Assert.IsFalse(stdPropertyDescriptor.IsReadOnly); Assert.AreEqual("Standaardafwijking", stdPropertyDescriptor.DisplayName); Assert.AreEqual("De standaardafwijking van de verschoven lognormale verdeling.", stdPropertyDescriptor.Description);