Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Probability; + +namespace Ringtoets.ClosingStructures.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the + /// closing structures failure mechanism. + /// + public static class ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there is no + /// calculation assigned to the section result or the calculation is not performed. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this ClosingStructuresFailureMechanismSectionResult sectionResult, + ClosingStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (sectionResult.Calculation == null || !sectionResult.Calculation.HasOutput) + { + return double.NaN; + } + + ProbabilityAssessmentOutput derivedOutput = ClosingStructuresProbabilityAssessmentOutputFactory.Create(sectionResult.Calculation.Output, + failureMechanism, assessmentSection); + + return derivedOutput.Probability; + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj =================================================================== diff -u -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj (.../Ringtoets.ClosingStructures.Data.csproj) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Data/Ringtoets.ClosingStructures.Data.csproj (.../Ringtoets.ClosingStructures.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -13,7 +13,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.ClosingStructures.Data.TestUtil; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; + +namespace Ringtoets.ClosingStructures.Data.Test +{ + [TestFixture] + public class ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => ClosingStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability( + null, + new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_SectionResultWithoutCalculation_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithoutOutput_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestClosingStructuresCalculation() + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithOutput_ReturnsDerivedProbability() + { + // Setup + var failureMechanism = new ClosingStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new ClosingStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestClosingStructuresCalculation + { + Output = new TestStructuresOutput(0.45) + } + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new ClosingStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.AreEqual(0.32635522028792008, detailedAssessmentProbability); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj =================================================================== diff -u -r773fa9dbb96e3e391ee0abff808550fc2e70d7d0 -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision 773fa9dbb96e3e391ee0abff808550fc2e70d7d0) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Data.Test/Ringtoets.ClosingStructures.Data.Test.csproj (.../Ringtoets.ClosingStructures.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -20,7 +20,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionDetailedAssessmentProbabilityResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Probability; + +namespace Ringtoets.GrassCoverErosionInwards.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the + /// grass cover erosion inwards failure mechanism. + /// + public static class GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability or when there is no + /// calculation assigned to the section result or the calculation is not performed. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this GrassCoverErosionInwardsFailureMechanismSectionResult sectionResult, + GrassCoverErosionInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (sectionResult.Calculation == null || !sectionResult.Calculation.HasOutput) + { + return double.NaN; + } + + ProbabilityAssessmentOutput derivedOutput = GrassCoverErosionInwardsProbabilityAssessmentOutputFactory.Create(sectionResult.Calculation.Output.OvertoppingOutput, + failureMechanism, assessmentSection); + + return derivedOutput.Probability; + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/Ringtoets.GrassCoverErosionInwards.Data.csproj =================================================================== diff -u -rc7425b8f799095f2dc812351e14103931c672fba -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/Ringtoets.GrassCoverErosionInwards.Data.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.csproj) (revision c7425b8f799095f2dc812351e14103931c672fba) +++ Ringtoets/GrassCoverErosionInwards/src/Ringtoets.GrassCoverErosionInwards.Data/Ringtoets.GrassCoverErosionInwards.Data.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -12,7 +12,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionDetailedAssessmentProbabilityResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,157 @@ +// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.GrassCoverErosionInwards.Data.TestUtil; + +namespace Ringtoets.GrassCoverErosionInwards.Data.Test +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => GrassCoverErosionInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability(null, + new GrassCoverErosionInwardsFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(new GrassCoverErosionInwardsFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_SectionResultWithoutCalculation_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithoutOutput_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = new GrassCoverErosionInwardsCalculation() + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new GrassCoverErosionInwardsFailureMechanism(), assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithOutput_ReturnsDerivedProbability() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) + { + Calculation = new GrassCoverErosionInwardsCalculation + { + Output = new TestGrassCoverErosionInwardsOutput() + } + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(0.5, detailedAssessmentProbability); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj =================================================================== diff -u -rc7425b8f799095f2dc812351e14103931c672fba -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision c7425b8f799095f2dc812351e14103931c672fba) +++ Ringtoets/GrassCoverErosionInwards/test/Ringtoets.GrassCoverErosionInwards.Data.Test/Ringtoets.GrassCoverErosionInwards.Data.Test.csproj (.../Ringtoets.GrassCoverErosionInwards.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -20,7 +20,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Probability; + +namespace Ringtoets.HeightStructures.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the + /// height structures failure mechanism. + /// + public static class HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there is no + /// calculation assigned to the section result or the calculation is not performed. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this HeightStructuresFailureMechanismSectionResult sectionResult, + HeightStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (sectionResult.Calculation == null || !sectionResult.Calculation.HasOutput) + { + return double.NaN; + } + + ProbabilityAssessmentOutput derivedOutput = HeightStructuresProbabilityAssessmentOutputFactory.Create(sectionResult.Calculation.Output, + failureMechanism, assessmentSection); + + return derivedOutput.Probability; + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Ringtoets.HeightStructures.Data.csproj =================================================================== diff -u -r91b6773de2fccf52417609b4ed9463f98d6451dd -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Ringtoets.HeightStructures.Data.csproj (.../Ringtoets.HeightStructures.Data.csproj) (revision 91b6773de2fccf52417609b4ed9463f98d6451dd) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/Ringtoets.HeightStructures.Data.csproj (.../Ringtoets.HeightStructures.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -14,7 +14,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.HeightStructures.Data.TestUtil; + +namespace Ringtoets.HeightStructures.Data.Test +{ + [TestFixture] + public class HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => HeightStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability( + null, + new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new HeightStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new HeightStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(new HeightStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_SectionResultWithoutCalculation_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new HeightStructuresFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithoutOutput_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new HeightStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestHeightStructuresCalculation() + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithOutput_ReturnsDerivedProbability() + { + // Setup + var failureMechanism = new HeightStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new HeightStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestHeightStructuresCalculation + { + Output = new TestStructuresOutput(0.8) + } + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new HeightStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.AreEqual(0.21185539858339669, detailedAssessmentProbability); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/Ringtoets.HeightStructures.Data.Test.csproj =================================================================== diff -u -r91b6773de2fccf52417609b4ed9463f98d6451dd -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/Ringtoets.HeightStructures.Data.Test.csproj (.../Ringtoets.HeightStructures.Data.Test.csproj) (revision 91b6773de2fccf52417609b4ed9463f98d6451dd) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/Ringtoets.HeightStructures.Data.Test.csproj (.../Ringtoets.HeightStructures.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -20,7 +20,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionDetailedAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,179 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; + +namespace Ringtoets.MacroStabilityInwards.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of + /// the macro stability inwards failure mechanism. + /// + public static class MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// All calculations in the failure mechanism. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there are no + /// performed or relevant calculations. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this MacroStabilityInwardsFailureMechanismSectionResult sectionResult, + IEnumerable calculations, + MacroStabilityInwardsFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + MacroStabilityInwardsCalculationScenario[] relevantScenarios = sectionResult.GetCalculationScenarios(calculations).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (relevantScenarioAvailable && Math.Abs(sectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) + { + return double.NaN; + } + + if (!relevantScenarioAvailable || sectionResult.GetCalculationScenarioStatus(relevantScenarios) != CalculationScenarioStatus.Done) + { + return double.NaN; + } + + double totalDetailedAssessmentProbability = 0; + foreach (MacroStabilityInwardsCalculationScenario scenario in relevantScenarios) + { + DerivedMacroStabilityInwardsOutput derivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(scenario.Output, + failureMechanism, + assessmentSection); + + totalDetailedAssessmentProbability += derivedOutput.MacroStabilityInwardsProbability * (double) scenario.Contribution; + } + + return totalDetailedAssessmentProbability; + } + + /// + /// Gets the contribution of all relevant together. + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + public static RoundedDouble GetTotalContribution(this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, + IEnumerable calculations) + { + return (RoundedDouble) macroStabilityInwardsFailureMechanismSectionResult + .GetCalculationScenarios(calculations) + .Aggregate(0, (current, calculationScenario) => current + calculationScenario.Contribution); + } + + /// + /// Gets a list of the relevant . + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + public static IEnumerable GetCalculationScenarios(this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, + IEnumerable calculations) + { + IEnumerable lineSegments = Math2D.ConvertLinePointsToLineSegments(macroStabilityInwardsFailureMechanismSectionResult.Section.Points); + + return calculations + .Where(pc => pc.IsRelevant && pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); + } + + /// + /// Gets the status of the section result depending on the relevant calculation scenarios. + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + /// Thrown when any of the relevant calculations + /// in has an invalid . + /// Thrown when any of the relevant scenarios has an unsupported value of . + public static CalculationScenarioStatus GetCalculationScenarioStatus( + this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, + IEnumerable calculations) + { + var failed = false; + var notCalculated = false; + foreach (MacroStabilityInwardsCalculationScenario calculationScenario in macroStabilityInwardsFailureMechanismSectionResult.GetCalculationScenarios(calculations).Where(cs => cs.IsRelevant)) + { + CalculationScenarioStatus calculationScenarioStatus = calculationScenario.Status; + if (!Enum.IsDefined(typeof(CalculationScenarioStatus), calculationScenarioStatus)) + { + throw new InvalidEnumArgumentException(nameof(macroStabilityInwardsFailureMechanismSectionResult), + (int) calculationScenarioStatus, + typeof(CalculationScenarioStatus)); + } + + switch (calculationScenario.Status) + { + case CalculationScenarioStatus.Failed: + failed = true; + break; + case CalculationScenarioStatus.NotCalculated: + notCalculated = true; + break; + case CalculationScenarioStatus.Done: + continue; + default: + throw new NotSupportedException($"The enum value {nameof(CalculationScenarioStatus)}.{calculationScenarioStatus} is not supported."); + } + } + + if (failed) + { + return CalculationScenarioStatus.Failed; + } + + if (notCalculated) + { + return CalculationScenarioStatus.NotCalculated; + } + + return CalculationScenarioStatus.Done; + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/Ringtoets.MacroStabilityInwards.Data.csproj =================================================================== diff -u -r9871a2374e0f08658f7bec58412958b35f8a849b -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/Ringtoets.MacroStabilityInwards.Data.csproj (.../Ringtoets.MacroStabilityInwards.Data.csproj) (revision 9871a2374e0f08658f7bec58412958b35f8a849b) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Data/Ringtoets.MacroStabilityInwards.Data.csproj (.../Ringtoets.MacroStabilityInwards.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -21,7 +21,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,438 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Linq; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Data.TestUtil; + +namespace Ringtoets.MacroStabilityInwards.Data.Test +{ + [TestFixture] + public class MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => MacroStabilityInwardsFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability( + null, Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, new MacroStabilityInwardsFailureMechanism(), assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + new MacroStabilityInwardsFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + const double factorOfStability1 = 1.0 / 1000000.0; + const double factorOfStability2 = 1.0 / 2000000.0; + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section); + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section); + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(0.0, section); + + macroStabilityInwardsCalculationScenario1.IsRelevant = true; + macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble) 0.2; + + macroStabilityInwardsCalculationScenario2.IsRelevant = true; + macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble) 0.8; + + macroStabilityInwardsCalculationScenario3.IsRelevant = false; + + var calculations = new[] + { + macroStabilityInwardsCalculationScenario1, + macroStabilityInwardsCalculationScenario2, + macroStabilityInwardsCalculationScenario3 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(0.99801160064610306, detailedAssessmentProbability, 1e-8); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_NoScenarios_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_NoRelevantScenarios_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario calculationScenario1 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section); + MacroStabilityInwardsCalculationScenario calculationScenario2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section); + + var calculationScenarios = new[] + { + calculationScenario1, + calculationScenario2 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculationScenarios, + failureMechanism, + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_ScenarioNotCalculated_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new[] + { + macroStabilityInwardsCalculationScenario + }, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_ScenarioWithNanResults_ReturnsNaN() + { + // Setup + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + const double contribution1 = 0.2; + const double contribution2 = 0.8; + + MacroStabilityInwardsCalculationScenario calculationScenario1 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(0, section); + MacroStabilityInwardsCalculationScenario calculationScenario2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + + calculationScenario1.IsRelevant = true; + calculationScenario1.Contribution = (RoundedDouble) contribution1; + + calculationScenario2.IsRelevant = true; + calculationScenario2.Contribution = (RoundedDouble) contribution2; + calculationScenario2.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(); + + var calculations = new[] + { + calculationScenario1, + calculationScenario2 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + [TestCase(0.2, 0.8 - 1e5)] + [TestCase(0.0, 0.5)] + [TestCase(0.3, 0.7 + 1e-5)] + [TestCase(-5, -8)] + [TestCase(13, 2)] + public void GetDetailedAssessmentProbability_RelevantScenarioContributionDontAddUpTo1_ReturnNaN(double contributionA, double contributionB) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new MacroStabilityInwardsFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + MacroStabilityInwardsCalculationScenario scenarioA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + MacroStabilityInwardsCalculationScenario scenarioB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + scenarioA.Contribution = (RoundedDouble) contributionA; + scenarioB.Contribution = (RoundedDouble) contributionB; + + var result = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = result.GetDetailedAssessmentProbability(new[] + { + scenarioA, + scenarioB + }, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetTotalContribution_Always_ReturnsTotalRelevantScenarioContribution() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + macroStabilityInwardsCalculationScenario.Contribution = (RoundedDouble) 0.3; + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section); + macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble) 0.5; + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section); + + var calculationScenarios = new[] + { + macroStabilityInwardsCalculationScenario, + macroStabilityInwardsCalculationScenario2, + macroStabilityInwardsCalculationScenario3 + }; + + // Call + RoundedDouble totalContribution = failureMechanismSectionResult.GetTotalContribution(calculationScenarios); + + // Assert + Assert.AreEqual((RoundedDouble) 0.8, totalContribution); + } + + [Test] + public void GetCalculationScenarioStatus_ScenarioNotCalculated_ReturnsStatusNotCalculated() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + macroStabilityInwardsCalculationScenario + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.NotCalculated, status); + } + + [Test] + public void GetCalculationScenarioStatus_ScenarioNaNOutput_ReturnsStatusDone() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + macroStabilityInwardsCalculationScenario + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.Done, status); + } + + [Test] + public void GetCalculationScenarioStatus_ScenariosWithNotCalculatedScenario_ReturnsStatusNotCalculated() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateNotCalculatedMacroStabilityInwardsCalculationScenario(section); + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section); + + var calculationScenarios = new[] + { + macroStabilityInwardsCalculationScenario, + macroStabilityInwardsCalculationScenario2 + }; + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(calculationScenarios); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.NotCalculated, status); + } + + [Test] + public void GetCalculationScenarioStatus_ScenarioCalculated_ReturnsStatusDone() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(0.1, section); + macroStabilityInwardsCalculationScenario.Contribution = (RoundedDouble) 1.0; + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + macroStabilityInwardsCalculationScenario + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.Done, status); + } + + [Test] + public void GetCalculationScenarioStatus_NoScenarios_ReturnsStatusDone() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new MacroStabilityInwardsFailureMechanismSectionResult(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(Enumerable.Empty()); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.Done, status); + } + } +} \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/Ringtoets.MacroStabilityInwards.Data.Test.csproj =================================================================== diff -u -re5aeb6eac84e0b295dd48c7b356d0d132e344e1b -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/Ringtoets.MacroStabilityInwards.Data.Test.csproj (.../Ringtoets.MacroStabilityInwards.Data.Test.csproj) (revision e5aeb6eac84e0b295dd48c7b356d0d132e344e1b) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Data.Test/Ringtoets.MacroStabilityInwards.Data.Test.csproj (.../Ringtoets.MacroStabilityInwards.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -38,7 +38,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionDetailedAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/PipingFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,175 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Base.Geometry; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; + +namespace Ringtoets.Piping.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the piping failure mechanism. + /// + public static class PipingFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// All calculations in the failure mechanism. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there are no + /// performed or relevant calculations. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this PipingFailureMechanismSectionResult sectionResult, + IEnumerable calculations, + PipingFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (calculations == null) + { + throw new ArgumentNullException(nameof(calculations)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + PipingCalculationScenario[] relevantScenarios = sectionResult.GetCalculationScenarios(calculations).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (relevantScenarioAvailable && Math.Abs(sectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) + { + return double.NaN; + } + + if (!relevantScenarioAvailable || sectionResult.GetCalculationScenarioStatus(relevantScenarios) != CalculationScenarioStatus.Done) + { + return double.NaN; + } + + double totalDetailedAssessmentProbability = 0; + foreach (PipingCalculationScenario scenario in relevantScenarios) + { + DerivedPipingOutput derivedOutput = DerivedPipingOutputFactory.Create(scenario.Output, failureMechanism, assessmentSection); + + totalDetailedAssessmentProbability += derivedOutput.PipingProbability * (double) scenario.Contribution; + } + + return totalDetailedAssessmentProbability; + } + + /// + /// Gets the contribution of all relevant together. + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + public static RoundedDouble GetTotalContribution(this PipingFailureMechanismSectionResult pipingFailureMechanismSectionResult, + IEnumerable calculations) + { + return (RoundedDouble) pipingFailureMechanismSectionResult + .GetCalculationScenarios(calculations) + .Aggregate(0, (current, calculationScenario) => current + calculationScenario.Contribution); + } + + /// + /// Gets a list of the relevant . + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + public static IEnumerable GetCalculationScenarios(this PipingFailureMechanismSectionResult pipingFailureMechanismSectionResult, + IEnumerable calculations) + { + IEnumerable lineSegments = Math2D.ConvertLinePointsToLineSegments(pipingFailureMechanismSectionResult.Section.Points); + + return calculations + .Where(pc => pc.IsRelevant && pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); + } + + /// + /// Gets the status of the section result depending on the relevant calculation scenarios. + /// + /// The result to get the result for. + /// All calculations in the failure mechanism. + /// Thrown when any of the relevant calculations + /// in has an invalid . + /// Thrown when any of the relevant scenarios has an unsupported value of . + public static CalculationScenarioStatus GetCalculationScenarioStatus(this PipingFailureMechanismSectionResult pipingFailureMechanismSectionResult, + IEnumerable calculations) + { + var failed = false; + var notCalculated = false; + foreach (PipingCalculationScenario calculationScenario in pipingFailureMechanismSectionResult.GetCalculationScenarios(calculations).Where(cs => cs.IsRelevant)) + { + CalculationScenarioStatus calculationScenarioStatus = calculationScenario.Status; + if (!Enum.IsDefined(typeof(CalculationScenarioStatus), calculationScenarioStatus)) + { + throw new InvalidEnumArgumentException(nameof(pipingFailureMechanismSectionResult), + (int) calculationScenarioStatus, + typeof(CalculationScenarioStatus)); + } + + switch (calculationScenarioStatus) + { + case CalculationScenarioStatus.Failed: + failed = true; + break; + case CalculationScenarioStatus.NotCalculated: + notCalculated = true; + break; + case CalculationScenarioStatus.Done: + continue; + default: + throw new NotSupportedException($"The enum value {nameof(CalculationScenarioStatus)}.{calculationScenarioStatus} is not supported."); + } + } + + if (failed) + { + return CalculationScenarioStatus.Failed; + } + + if (notCalculated) + { + return CalculationScenarioStatus.NotCalculated; + } + + return CalculationScenarioStatus.Done; + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj =================================================================== diff -u -r4cced5dc46fe7dd8896ad15d1ec190dec9b2358e -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision 4cced5dc46fe7dd8896ad15d1ec190dec9b2358e) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -19,7 +19,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/PipingFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,413 @@ +// Copyright (C) Stichting Deltares 2017. 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 System.Linq; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.Piping.Data.TestUtil; + +namespace Ringtoets.Piping.Data.Test +{ + [TestFixture] + public class PipingFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => PipingFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability( + null, Enumerable.Empty(), + new PipingFailureMechanism(), assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationsNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, new PipingFailureMechanism(), assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("calculations", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + null, + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + new PipingFailureMechanism(), + null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario1 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + PipingCalculationScenario pipingCalculationScenario2 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + PipingCalculationScenario pipingCalculationScenario3 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + + pipingCalculationScenario1.IsRelevant = true; + pipingCalculationScenario1.Contribution = (RoundedDouble) 0.2; + + pipingCalculationScenario2.IsRelevant = true; + pipingCalculationScenario2.Contribution = (RoundedDouble) 0.8; + + pipingCalculationScenario3.IsRelevant = false; + + var calculations = new[] + { + pipingCalculationScenario1, + pipingCalculationScenario2, + pipingCalculationScenario3 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + + // Assert + Assert.AreEqual(0.028693041013187315, detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_NoScenarios_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(Enumerable.Empty(), + failureMechanism, + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_NoRelevantScenarios_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario calculationScenario1 = PipingCalculationScenarioTestFactory.CreateIrrelevantPipingCalculationScenario(section); + PipingCalculationScenario calculationScenario2 = PipingCalculationScenarioTestFactory.CreateIrrelevantPipingCalculationScenario(section); + + var calculationScenarios = new[] + { + calculationScenario1, + calculationScenario2 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculationScenarios, + failureMechanism, + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_ScenarioNotCalculated_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new[] + { + pipingCalculationScenario + }, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_ScenarioWithNanResults_ReturnsNaN() + { + // Setup + var failureMechanism = new PipingFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + const double contribution1 = 0.2; + const double contribution2 = 0.8; + + PipingCalculationScenario pipingCalculationScenario1 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + PipingCalculationScenario pipingCalculationScenario2 = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + + pipingCalculationScenario1.IsRelevant = true; + pipingCalculationScenario1.Contribution = (RoundedDouble) contribution1; + + pipingCalculationScenario2.IsRelevant = true; + pipingCalculationScenario2.Contribution = (RoundedDouble) contribution2; + pipingCalculationScenario2.Output = new PipingOutput(new PipingOutput.ConstructionProperties()); + + var calculations = new[] + { + pipingCalculationScenario1, + pipingCalculationScenario2 + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + [TestCase(0.2, 0.8 - 1e5)] + [TestCase(0.0, 0.5)] + [TestCase(0.3, 0.7 + 1e-5)] + [TestCase(-5, -8)] + [TestCase(13, 2)] + public void GetDetailedAssessmentProbability_RelevantScenarioContributionDontAddUpTo1_ReturnNaN(double contributionA, double contributionB) + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism(); + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + PipingCalculationScenario scenarioA = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + PipingCalculationScenario scenarioB = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + scenarioA.Contribution = (RoundedDouble) contributionA; + scenarioB.Contribution = (RoundedDouble) contributionB; + + var result = new PipingFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = result.GetDetailedAssessmentProbability(new[] + { + scenarioA, + scenarioB + }, failureMechanism, assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetTotalContribution_Always_ReturnsTotalRelevantScenarioContribution() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + pipingCalculationScenario.Contribution = (RoundedDouble) 0.3; + + PipingCalculationScenario pipingCalculationScenario2 = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + pipingCalculationScenario2.Contribution = (RoundedDouble) 0.5; + + PipingCalculationScenario pipingCalculationScenario3 = PipingCalculationScenarioTestFactory.CreateIrrelevantPipingCalculationScenario(section); + + var calculationScenarios = new[] + { + pipingCalculationScenario, + pipingCalculationScenario2, + pipingCalculationScenario3 + }; + + // Call + RoundedDouble totalContribution = failureMechanismSectionResult.GetTotalContribution(calculationScenarios); + + // Assert + Assert.AreEqual((RoundedDouble) 0.8, totalContribution); + } + + [Test] + public void GetCalculationScenarioStatus_ScenarioNotCalculated_ReturnsStatusNotCalculated() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + pipingCalculationScenario + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.NotCalculated, status); + } + + [Test] + public void GetCalculationScenarioStatus_ScenarioCalculated_ReturnsStatusDone() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + pipingCalculationScenario + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.Done, status); + } + + [Test] + public void GetCalculationScenarioStatus_NoScenarios_ReturnsStatusDone() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(Enumerable.Empty()); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.Done, status); + } + + [Test] + public void GetCalculationScenarioStatus_DifferentScenarios_ReturnsStatusNotCalculated() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new PipingFailureMechanismSectionResult(section); + + PipingCalculationScenario pipingCalculationScenario1 = PipingCalculationScenarioTestFactory.CreateNotCalculatedPipingCalculationScenario(section); + PipingCalculationScenario pipingCalculationScenario2 = PipingCalculationScenarioTestFactory.CreatePipingCalculationScenario(section); + + // Call + CalculationScenarioStatus status = failureMechanismSectionResult.GetCalculationScenarioStatus(new[] + { + pipingCalculationScenario1, + pipingCalculationScenario2 + }); + + // Assert + Assert.AreEqual(CalculationScenarioStatus.NotCalculated, status); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj =================================================================== diff -u -r4cced5dc46fe7dd8896ad15d1ec190dec9b2358e -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 4cced5dc46fe7dd8896ad15d1ec190dec9b2358e) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -27,7 +27,7 @@ - + Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/Ringtoets.StabilityPointStructures.Data.csproj =================================================================== diff -u -ra0a6258257c414bfebdab21480a2278aa9748c35 -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/Ringtoets.StabilityPointStructures.Data.csproj (.../Ringtoets.StabilityPointStructures.Data.csproj) (revision a0a6258257c414bfebdab21480a2278aa9748c35) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/Ringtoets.StabilityPointStructures.Data.csproj (.../Ringtoets.StabilityPointStructures.Data.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -21,7 +21,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismSectionDetailedAssessmentResultExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 0) +++ Ringtoets/StabilityPointStructures/src/Ringtoets.StabilityPointStructures.Data/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,73 @@ +// Copyright (C) Stichting Deltares 2017. 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 Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Probability; + +namespace Ringtoets.StabilityPointStructures.Data +{ + /// + /// Extension methods for obtaining detailed assessment probabilities from output for an assessment of the + /// stability point structures failure mechanism. + /// + public static class StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensions + { + /// + /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. + /// + /// The section result to get the detailed assessment probability for. + /// The failure mechanism the calculations belong to. + /// The assessment section the calculations belong to. + /// The calculated detailed assessment probability; or when there is no + /// calculation assigned to the section result or the calculation is not performed. + /// Thrown when any parameter is null. + public static double GetDetailedAssessmentProbability(this StabilityPointStructuresFailureMechanismSectionResult sectionResult, + StabilityPointStructuresFailureMechanism failureMechanism, + IAssessmentSection assessmentSection) + { + if (sectionResult == null) + { + throw new ArgumentNullException(nameof(sectionResult)); + } + + if (failureMechanism == null) + { + throw new ArgumentNullException(nameof(failureMechanism)); + } + + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + if (sectionResult.Calculation == null || !sectionResult.Calculation.HasOutput) + { + return double.NaN; + } + + ProbabilityAssessmentOutput derivedOutput = StabilityPointStructuresProbabilityAssessmentOutputFactory.Create(sectionResult.Calculation.Output, + failureMechanism, assessmentSection); + + return derivedOutput.Probability; + } + } +} \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/Ringtoets.StabilityPointStructures.Data.Test.csproj =================================================================== diff -u -ra0a6258257c414bfebdab21480a2278aa9748c35 -r739752c5cc7ed800dacf74e12221c227183ddc6f --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/Ringtoets.StabilityPointStructures.Data.Test.csproj (.../Ringtoets.StabilityPointStructures.Data.Test.csproj) (revision a0a6258257c414bfebdab21480a2278aa9748c35) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/Ringtoets.StabilityPointStructures.Data.Test.csproj (.../Ringtoets.StabilityPointStructures.Data.Test.csproj) (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -21,7 +21,7 @@ - + Fisheye: Tag 739752c5cc7ed800dacf74e12221c227183ddc6f refers to a dead (removed) revision in file `Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismSectionDetailedAssessmentResultExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs =================================================================== diff -u --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 0) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Data.Test/StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest.cs (revision 739752c5cc7ed800dacf74e12221c227183ddc6f) @@ -0,0 +1,161 @@ +// Copyright (C) Stichting Deltares 2017. 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 NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.TestUtil; +using Ringtoets.StabilityPointStructures.Data.TestUtil; + +namespace Ringtoets.StabilityPointStructures.Data.Test +{ + [TestFixture] + public class StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensionsTest + { + [Test] + public void GetDetailedAssessmentProbability_SectionResultNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + // Call + TestDelegate call = () => StabilityPointStructuresFailureMechanismSectionResultDetailedAssessmentExtensions.GetDetailedAssessmentProbability( + null, + new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("sectionResult", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_FailureMechanismNull_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(null, assessmentSection); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("failureMechanism", exception.ParamName); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section); + + // Call + TestDelegate call = () => failureMechanismSectionResult.GetDetailedAssessmentProbability(new StabilityPointStructuresFailureMechanism(), null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbability_SectionResultWithoutCalculation_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section); + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithoutOutput_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestStabilityPointStructuresCalculation() + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.IsNaN(detailedAssessmentProbability); + mocks.VerifyAll(); + } + + [Test] + public void GetDetailedAssessmentProbability_CalculationWithOutput_ReturnsDerivedProbability() + { + // Setup + var failureMechanism = new StabilityPointStructuresFailureMechanism(); + + var mocks = new MockRepository(); + IAssessmentSection assessmentSection = AssessmentSectionHelper.CreateAssessmentSectionStub(failureMechanism, mocks); + mocks.ReplayAll(); + + FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); + var failureMechanismSectionResult = new StabilityPointStructuresFailureMechanismSectionResult(section) + { + Calculation = new TestStabilityPointStructuresCalculation + { + Output = new TestStructuresOutput(0.75) + } + }; + + // Call + double detailedAssessmentProbability = failureMechanismSectionResult.GetDetailedAssessmentProbability(new StabilityPointStructuresFailureMechanism(), + assessmentSection); + + // Assert + Assert.AreEqual(0.22662735237686821, detailedAssessmentProbability); + mocks.VerifyAll(); + } + } +} \ No newline at end of file