Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs =================================================================== diff -u -rcf2dc4330cecec3b8c8acae9e195280323fc2a50 -rd9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5 --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs (.../NormalDistributionDesignVariable.cs) (revision cf2dc4330cecec3b8c8acae9e195280323fc2a50) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/NormalDistributionDesignVariable.cs (.../NormalDistributionDesignVariable.cs) (revision d9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5) @@ -23,8 +23,15 @@ namespace Ringtoets.Common.Data.Probabilistics { + /// + /// This class defines a design variable for a normal distribution. + /// public class NormalDistributionDesignVariable : DesignVariable { + /// + /// Initializes a new instance of the class. + /// + /// A normal distribution. public NormalDistributionDesignVariable(NormalDistribution distribution) : base(distribution) {} public override RoundedDouble GetDesignValue() Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/TruncatedNormalDistribution.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/TruncatedNormalDistribution.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probabilistics/TruncatedNormalDistribution.cs (revision d9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5) @@ -0,0 +1,79 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; + +namespace Ringtoets.Common.Data.Probabilistics +{ + /// + /// Class representing a truncated normal distribution expressed in terms of standard + /// deviation. + /// + public class TruncatedNormalDistribution : NormalDistribution + { + private RoundedDouble lowerBoundary; + private RoundedDouble upperBoundary; + + /// + /// Initializes a new instance of the class. + /// + /// The number of decimal places of the distribution. + /// + /// Thrown when is not in range [0, ]. + /// + public TruncatedNormalDistribution(int numberOfDecimalPlaces) : base(numberOfDecimalPlaces) + { + lowerBoundary = new RoundedDouble(numberOfDecimalPlaces); + upperBoundary = new RoundedDouble(numberOfDecimalPlaces); + } + + /// X + /// Gets or sets the lower boundary of the distribution. + /// + public RoundedDouble LowerBoundary + { + get + { + return lowerBoundary; + } + set + { + lowerBoundary = value.ToPrecision(lowerBoundary.NumberOfDecimalPlaces); + } + } + + /// + /// Gets or sets the upper boundary of the distribution. + /// + public RoundedDouble UpperBoundary + { + get + { + return upperBoundary; + } + set + { + upperBoundary = value.ToPrecision(upperBoundary.NumberOfDecimalPlaces); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj =================================================================== diff -u -rb4e3629ea2130359117dd403af8db3c8ae0c680b -rd9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5 --- Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision b4e3629ea2130359117dd403af8db3c8ae0c680b) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Ringtoets.Common.Data.csproj (.../Ringtoets.Common.Data.csproj) (revision d9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5) @@ -52,6 +52,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/TruncatedNormalDistributionTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/TruncatedNormalDistributionTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/TruncatedNormalDistributionTest.cs (revision d9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5) @@ -0,0 +1,133 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.Common.Data.Probabilistics; + +namespace Ringtoets.Common.Data.Test.Probabilistics +{ + [TestFixture] + public class TruncatedNormalDistributionTest + { + [Test] + [TestCase(0)] + [TestCase(2)] + [TestCase(15)] + public void DefaultConstructor_ExpectedValues(int numberOfDecimalPlaces) + { + // Call + var distribution = new TruncatedNormalDistribution(numberOfDecimalPlaces); + + // Assert + Assert.IsInstanceOf(distribution); + Assert.AreEqual(0.0, distribution.Mean.Value); + Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); + Assert.AreEqual(1.0, distribution.StandardDeviation.Value); + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); + Assert.AreEqual(0.0, distribution.LowerBoundary.Value); + Assert.AreEqual(numberOfDecimalPlaces, distribution.LowerBoundary.NumberOfDecimalPlaces); + Assert.AreEqual(0.0, distribution.UpperBoundary.Value); + Assert.AreEqual(numberOfDecimalPlaces, distribution.UpperBoundary.NumberOfDecimalPlaces); + } + + [Test] + public void Mean_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces() + { + // Setup + var value = 1.23456789; + var numberOfDecimalPlaces = 4; + var distribution = new TruncatedNormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.Mean = (RoundedDouble)value; + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.Mean.NumberOfDecimalPlaces); + Assert.AreEqual(new RoundedDouble(numberOfDecimalPlaces, value), distribution.Mean); + } + + [Test] + [TestCase(1.23456789)] + [TestCase(0 - 1e-3, Description = "Valid standard deviation due to rounding to 0.0")] + public void StandardDeviation_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces(double standardDeviation) + { + // Setup + var numberOfDecimalPlaces = 2; + var distribution = new TruncatedNormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.StandardDeviation = (RoundedDouble)standardDeviation; + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.StandardDeviation.NumberOfDecimalPlaces); + Assert.AreEqual(new RoundedDouble(numberOfDecimalPlaces, standardDeviation), distribution.StandardDeviation); + } + + [Test] + [TestCase(-4)] + [TestCase(0 - 1e-2)] + public void StandardDeviation_SettingToLessThan0_ThrowArgumentOutOfRangeException(double standardDeviation) + { + // Setup + var distribution = new TruncatedNormalDistribution(2); + + // Call + TestDelegate call = () => distribution.StandardDeviation = (RoundedDouble)standardDeviation; + + // Assert + const string expectedMessage = "Standaardafwijking (\u03C3) moet groter zijn dan of gelijk zijn aan 0."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage); + } + + [Test] + public void LowerBoundary_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces() + { + var value = 1.23456789; + var numberOfDecimalPlaces = 4; + var distribution = new TruncatedNormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.LowerBoundary = (RoundedDouble)value; + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.LowerBoundary.NumberOfDecimalPlaces); + Assert.AreEqual(new RoundedDouble(numberOfDecimalPlaces, value), distribution.LowerBoundary); + } + + [Test] + public void UpperBoundary_SetNewValue_GetValueRoundedToGivenNumberOfDecimalPlaces() + { + var value = 1.23456789; + var numberOfDecimalPlaces = 4; + var distribution = new TruncatedNormalDistribution(numberOfDecimalPlaces); + + // Call + distribution.UpperBoundary = (RoundedDouble)value; + + // Assert + Assert.AreEqual(numberOfDecimalPlaces, distribution.UpperBoundary.NumberOfDecimalPlaces); + Assert.AreEqual(new RoundedDouble(numberOfDecimalPlaces, value), distribution.UpperBoundary); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj =================================================================== diff -u -rb4e3629ea2130359117dd403af8db3c8ae0c680b -rd9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision b4e3629ea2130359117dd403af8db3c8ae0c680b) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Ringtoets.Common.Data.Test.csproj (.../Ringtoets.Common.Data.Test.csproj) (revision d9ca53f8fa89c230d499c7ac28b3b0b8e9290fe5) @@ -61,6 +61,7 @@ +