Index: Riskeer/Common/src/Riskeer.Common.Data/FailureMechanism/ScenarioConfigurationPerFailureMechanismSection.cs =================================================================== diff -u -r284cb27417263141ef138969297da216150b08a4 -rf46dff86a77c90d968fc00fc6e6306711ebf1b83 --- Riskeer/Common/src/Riskeer.Common.Data/FailureMechanism/ScenarioConfigurationPerFailureMechanismSection.cs (.../ScenarioConfigurationPerFailureMechanismSection.cs) (revision 284cb27417263141ef138969297da216150b08a4) +++ Riskeer/Common/src/Riskeer.Common.Data/FailureMechanism/ScenarioConfigurationPerFailureMechanismSection.cs (.../ScenarioConfigurationPerFailureMechanismSection.cs) (revision f46dff86a77c90d968fc00fc6e6306711ebf1b83) @@ -27,48 +27,56 @@ namespace Riskeer.Common.Data.FailureMechanism { - /// - /// This class holds the information of the scenario configuration of the . + /// This base class holds the information of the scenario configuration of the . /// - public class ScenarioConfigurationPerFailureMechanismSection : Observable + public abstract class ScenarioConfigurationPerFailureMechanismSection : Observable { - private static readonly Range validityRangeA = new Range(0, 1); - private double a; + private const int aNrOfDecimals = 3; + private static readonly Range validityRangeA = new Range( + new RoundedDouble(aNrOfDecimals), new RoundedDouble(aNrOfDecimals, 1)); + + private RoundedDouble a; + /// - /// Creates a new instance of . + /// Creates a new instance of . /// /// The to get the scenario configuration from. + /// The 'a' parameter used to factor in the 'length effect' when determining the + /// maximum tolerated probability of failure. /// Thrown when is null. - public ScenarioConfigurationPerFailureMechanismSection(FailureMechanismSection section) + /// Thrown when value is not in the range [0, 1]. + protected ScenarioConfigurationPerFailureMechanismSection(FailureMechanismSection section, RoundedDouble a) { if (section == null) { throw new ArgumentNullException(nameof(section)); } + A = a; Section = section; } - + /// /// Gets or sets 'a' parameter used to factor in the 'length effect' when determining the /// maximum tolerated probability of failure. /// /// Thrown when value is not in the range [0, 1]. - public double A + public RoundedDouble A { get => a; set { - if (!validityRangeA.InRange(value)) + RoundedDouble newA = value.ToPrecision(aNrOfDecimals); + if (!validityRangeA.InRange(newA)) { throw new ArgumentOutOfRangeException(nameof(value), string.Format(Resources.ProbabilityAssessmentInput_A_Value_must_be_in_Range_0_, validityRangeA.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture))); } - a = value; + a = newA; } } Index: Riskeer/Common/test/Riskeer.Common.Data.Test/FailureMechanism/ScenarioConfigurationPerFailureMechanismSectionTest.cs =================================================================== diff -u -r284cb27417263141ef138969297da216150b08a4 -rf46dff86a77c90d968fc00fc6e6306711ebf1b83 --- Riskeer/Common/test/Riskeer.Common.Data.Test/FailureMechanism/ScenarioConfigurationPerFailureMechanismSectionTest.cs (.../ScenarioConfigurationPerFailureMechanismSectionTest.cs) (revision 284cb27417263141ef138969297da216150b08a4) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/FailureMechanism/ScenarioConfigurationPerFailureMechanismSectionTest.cs (.../ScenarioConfigurationPerFailureMechanismSectionTest.cs) (revision f46dff86a77c90d968fc00fc6e6306711ebf1b83) @@ -19,8 +19,8 @@ // 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 Riskeer.Common.Data.FailureMechanism; @@ -34,66 +34,90 @@ [Test] public void Constructor_SectionNull_ThrowsArgumentNullException() { + // Setup + var random = new Random(21); + // Call - void Call() => new ScenarioConfigurationPerFailureMechanismSection(null); + void Call() => new TestScenarioConfigurationPerFailureMechanismSection(null, random.NextRoundedDouble()); // Assert var exception = Assert.Throws(Call); Assert.AreEqual("section", exception.ParamName); } - + [Test] public void Constructor_ExpectedValues() { - // Call + // Setup + var random = new Random(21); + RoundedDouble a = random.NextRoundedDouble(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - + // Call - var scenarioConfigurationPerFailureMechanismSection = new ScenarioConfigurationPerFailureMechanismSection(section); + var scenarioConfigurationPerFailureMechanismSection = new TestScenarioConfigurationPerFailureMechanismSection(section, a); // Assert - Assert.AreEqual(0, scenarioConfigurationPerFailureMechanismSection.A); + Assert.AreEqual(3, scenarioConfigurationPerFailureMechanismSection.A.NumberOfDecimalPlaces); + Assert.AreEqual(a, scenarioConfigurationPerFailureMechanismSection.A, scenarioConfigurationPerFailureMechanismSection.A.GetAccuracy()); + Assert.AreSame(section, scenarioConfigurationPerFailureMechanismSection.Section); } - + [Test] [SetCulture("nl-NL")] [TestCase(-1)] + [TestCase(-0.0005)] [TestCase(-0.1)] [TestCase(1.1)] + [TestCase(1.0005)] [TestCase(8)] [TestCase(double.NaN)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.PositiveInfinity)] public void A_InvalidValue_ThrowsArgumentOutOfRangeException(double a) { // Setup + var random = new Random(21); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var scenarioConfigurationPerFailureMechanismSection = new ScenarioConfigurationPerFailureMechanismSection(section); + var scenarioConfigurationPerFailureMechanismSection = new TestScenarioConfigurationPerFailureMechanismSection(section, random.NextRoundedDouble()); // Call - void Call() => scenarioConfigurationPerFailureMechanismSection.A = a; + void Call() => scenarioConfigurationPerFailureMechanismSection.A = (RoundedDouble) a; // Assert const string expectedMessage = "De waarde voor 'a' moet in het bereik [0,0, 1,0] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage(Call, expectedMessage); } - + [Test] + [TestCase(-0.0004)] [TestCase(0)] [TestCase(0.1)] [TestCase(1)] + [TestCase(1.0004)] [TestCase(0.0000001)] [TestCase(0.9999999)] public void A_ValidValue_SetsValue(double a) { // Setup + var random = new Random(21); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - var scenarioConfigurationPerFailureMechanismSection = new ScenarioConfigurationPerFailureMechanismSection(section); + var scenarioConfigurationPerFailureMechanismSection = new TestScenarioConfigurationPerFailureMechanismSection(section, random.NextRoundedDouble()); // Call - scenarioConfigurationPerFailureMechanismSection.A = a; + scenarioConfigurationPerFailureMechanismSection.A = (RoundedDouble) a; // Assert - Assert.AreEqual(a, scenarioConfigurationPerFailureMechanismSection.A); + Assert.AreEqual(3, scenarioConfigurationPerFailureMechanismSection.A.NumberOfDecimalPlaces); + Assert.AreEqual(a, scenarioConfigurationPerFailureMechanismSection.A, scenarioConfigurationPerFailureMechanismSection.A.GetAccuracy()); } + + private class TestScenarioConfigurationPerFailureMechanismSection : ScenarioConfigurationPerFailureMechanismSection + { + public TestScenarioConfigurationPerFailureMechanismSection(FailureMechanismSection section, RoundedDouble a) : base(section, a) {} + } } } \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.Test/Probability/ScenarioConfigurationPerFailureMechanismSectionExtensionsTest.cs =================================================================== diff -u -r4001685fc423945628f49eb3064c4d23ec99df54 -rf46dff86a77c90d968fc00fc6e6306711ebf1b83 --- Riskeer/Common/test/Riskeer.Common.Data.Test/Probability/ScenarioConfigurationPerFailureMechanismSectionExtensionsTest.cs (.../ScenarioConfigurationPerFailureMechanismSectionExtensionsTest.cs) (revision 4001685fc423945628f49eb3064c4d23ec99df54) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/Probability/ScenarioConfigurationPerFailureMechanismSectionExtensionsTest.cs (.../ScenarioConfigurationPerFailureMechanismSectionExtensionsTest.cs) (revision f46dff86a77c90d968fc00fc6e6306711ebf1b83) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using Core.Common.Base.Data; using Core.Common.Base.Geometry; using NUnit.Framework; using Riskeer.Common.Data.FailureMechanism; @@ -56,16 +57,18 @@ new Point2D(length, 0) }); - var configuration = new ScenarioConfigurationPerFailureMechanismSection(section) - { - A = a - }; + var configuration = new TestScenarioConfigurationPerFailureMechanismSection(section, (RoundedDouble) a); // Call double actualN = configuration.GetN(b); // Assert Assert.AreEqual(expectedN, actualN); } + + private class TestScenarioConfigurationPerFailureMechanismSection : ScenarioConfigurationPerFailureMechanismSection + { + public TestScenarioConfigurationPerFailureMechanismSection(FailureMechanismSection section, RoundedDouble a) : base(section, a) {} + } } } \ No newline at end of file