Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.Data.Test/FailureMechanismSectionAssemblyInputTest.cs =================================================================== diff -u -r5f7afeb5da4572e7e4c9932d7eecb5fac86f44aa -r877f80f8669e3bae22e1a5151480634ebf4c3d0d --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.Data.Test/FailureMechanismSectionAssemblyInputTest.cs (.../FailureMechanismSectionAssemblyInputTest.cs) (revision 5f7afeb5da4572e7e4c9932d7eecb5fac86f44aa) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.Data.Test/FailureMechanismSectionAssemblyInputTest.cs (.../FailureMechanismSectionAssemblyInputTest.cs) (revision 877f80f8669e3bae22e1a5151480634ebf4c3d0d) @@ -17,15 +17,15 @@ bool isRelevant = random.NextBoolean(); double profileProbability = random.NextDouble(); double sectionProbability = random.NextDouble(); - bool needsRefinement = random.NextBoolean(); + bool furtherAnalysisNeeded = random.NextBoolean(); double refinedProfileProbability = random.NextDouble(); double refinedSectionProbability = random.NextDouble(); // Call var input = new FailureMechanismSectionAssemblyInput(signalingNorm, lowerLimitNorm, isRelevant, profileProbability, sectionProbability, - needsRefinement, + furtherAnalysisNeeded, refinedProfileProbability, refinedSectionProbability); // Assert @@ -35,7 +35,7 @@ Assert.AreEqual(isRelevant, input.IsRelevant); Assert.AreEqual(profileProbability, input.InitialProfileProbability); Assert.AreEqual(sectionProbability, input.InitialSectionProbability); - Assert.AreEqual(needsRefinement, input.FurtherAnalysisNeeded); + Assert.AreEqual(furtherAnalysisNeeded, input.FurtherAnalysisNeeded); Assert.AreEqual(refinedProfileProbability, input.RefinedProfileProbability); Assert.AreEqual(refinedSectionProbability, input.RefinedSectionProbability); } Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs =================================================================== diff -u -r5f7afeb5da4572e7e4c9932d7eecb5fac86f44aa -r877f80f8669e3bae22e1a5151480634ebf4c3d0d --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 5f7afeb5da4572e7e4c9932d7eecb5fac86f44aa) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 877f80f8669e3bae22e1a5151480634ebf4c3d0d) @@ -31,16 +31,6 @@ public class FailureMechanismSectionAssemblyCalculatorStub : IFailureMechanismSectionAssemblyCalculator { /// - /// Gets the signaling norm that is used in the calculation. - /// - public double SignalingNorm { get; private set; } - - /// - /// Gets the lower limit norm that is used in the calculation. - /// - public double LowerLimitNorm { get; private set; } - - /// /// Gets the that is used in the calculation. /// public FailureMechanismSectionAssemblyInput FailureMechanismSectionAssemblyInput { get; private set; } Index: Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/FailureMechanismSectionAssemblyGroupFactory.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/FailureMechanismSectionAssemblyGroupFactory.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/FailureMechanismSectionAssemblyGroupFactory.cs (revision 877f80f8669e3bae22e1a5151480634ebf4c3d0d) @@ -0,0 +1,95 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; +using Riskeer.Common.Data.AssessmentSection; +using Riskeer.Common.Data.Contribution; +using Riskeer.Common.Data.Exceptions; + +namespace Riskeer.Common.Data.AssemblyTool +{ + /// + /// Factory for creating results of a failure mechanism section assembly. + /// + public static class FailureMechanismSectionAssemblyGroupFactory + { + /// + /// Assembles the failure mechanism section based on the input arguments. + /// + /// The the section belongs to. + /// The indicator whether the section is relevant. + /// The initial probability for the profile. + /// The initial probability for the section. + /// The indicator whether the section needs further analysis. + /// The refined probability for the profile. + /// The refined probability for the section. + /// Thrown when is null. + /// Thrown when the section could not be successfully assembled. + public static FailureMechanismSectionAssemblyResult AssembleSection(IAssessmentSection assessmentSection, + bool isRelevant, + double initialProfileProbability, double initialSectionProbability, + bool furtherAnalysisNeeded, + double refinedProfileProbability, double refinedSectionProbability) + { + if (assessmentSection == null) + { + throw new ArgumentNullException(nameof(assessmentSection)); + } + + IFailureMechanismSectionAssemblyCalculator calculator = AssemblyToolCalculatorFactory.Instance.CreateFailureMechanismSectionAssemblyCalculator( + AssemblyToolKernelFactory.Instance); + + try + { + FailureMechanismSectionAssemblyInput input = CreateInput(assessmentSection, + isRelevant, + initialProfileProbability, initialSectionProbability, + furtherAnalysisNeeded, + refinedProfileProbability, refinedSectionProbability); + + return calculator.AssembleFailureMechanismSection(input); + } + catch (FailureMechanismSectionAssemblyCalculatorException e) + { + throw new AssemblyException(e.Message, e); + } + } + + private static FailureMechanismSectionAssemblyInput CreateInput(IAssessmentSection assessmentSection, + bool isRelevant, + double initialProfileProbability, double initialSectionProbability, + bool furtherAnalysisNeeded, + double refinedProfileProbability, double refinedSectionProbability) + { + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + return new FailureMechanismSectionAssemblyInput(failureMechanismContribution.SignalingNorm, + failureMechanismContribution.LowerLimitNorm, + isRelevant, + initialProfileProbability, initialSectionProbability, + furtherAnalysisNeeded, + refinedProfileProbability, refinedSectionProbability); + } + } +} \ No newline at end of file Index: Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/FailureMechanismSectionAssemblyGroupFactoryTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/FailureMechanismSectionAssemblyGroupFactoryTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/FailureMechanismSectionAssemblyGroupFactoryTest.cs (revision 877f80f8669e3bae22e1a5151480634ebf4c3d0d) @@ -0,0 +1,152 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Assembly; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly; +using Riskeer.Common.Data.AssemblyTool; +using Riskeer.Common.Data.Contribution; +using Riskeer.Common.Data.Exceptions; +using Riskeer.Common.Data.TestUtil; + +namespace Riskeer.Common.Data.Test.AssemblyTool +{ + [TestFixture] + public class FailureMechanismSectionAssemblyGroupFactoryTest + { + [Test] + public void AssembleSection_AssessmentSectionNull_ThrowsArgumentNullException() + { + // Setup + var random = new Random(21); + + // Call + void Call() => FailureMechanismSectionAssemblyGroupFactory.AssembleSection(null, + random.NextBoolean(), + random.NextDouble(), random.NextDouble(), + random.NextBoolean(), + random.NextDouble(), random.NextDouble()); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("assessmentSection", exception.ParamName); + } + + [Test] + public void AssembleSection_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(21); + bool isRelevant = random.NextBoolean(); + double profileProbability = random.NextDouble(); + double sectionProbability = random.NextDouble(); + bool furtherAnalysisNeeded = random.NextBoolean(); + double refinedProfileProbability = random.NextDouble(); + double refinedSectionProbability = random.NextDouble(); + + var assessmentSection = new AssessmentSectionStub(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyGroupFactory.AssembleSection(assessmentSection, + isRelevant, + profileProbability, sectionProbability, + furtherAnalysisNeeded, + refinedProfileProbability, refinedSectionProbability); + + // Assert + FailureMechanismSectionAssemblyInput calculatorInput = calculator.FailureMechanismSectionAssemblyInput; + FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution; + Assert.AreEqual(failureMechanismContribution.SignalingNorm, calculatorInput.SignalingNorm); + Assert.AreEqual(failureMechanismContribution.LowerLimitNorm, calculatorInput.LowerLimitNorm); + + Assert.AreEqual(isRelevant, calculatorInput.IsRelevant); + Assert.AreEqual(profileProbability, calculatorInput.InitialProfileProbability); + Assert.AreEqual(sectionProbability, calculatorInput.InitialSectionProbability); + Assert.AreEqual(furtherAnalysisNeeded, calculatorInput.FurtherAnalysisNeeded); + Assert.AreEqual(refinedProfileProbability, calculatorInput.RefinedProfileProbability); + Assert.AreEqual(refinedSectionProbability, calculatorInput.RefinedSectionProbability); + } + } + + [Test] + public void AssembleSection_CalculatorRan_ReturnsOutput() + { + // Setup + var random = new Random(21); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + + // Call + FailureMechanismSectionAssemblyResult output = + FailureMechanismSectionAssemblyGroupFactory.AssembleSection(new AssessmentSectionStub(), + random.NextBoolean(), + random.NextDouble(), random.NextDouble(), + random.NextBoolean(), + random.NextDouble(), random.NextDouble()); + + // Assert + FailureMechanismSectionAssemblyResult calculatorOutput = calculator.FailureMechanismSectionAssemblyResultOutput; + Assert.AreEqual(calculatorOutput.N, output.N); + Assert.AreEqual(calculatorOutput.AssemblyGroup, output.AssemblyGroup); + Assert.AreEqual(calculatorOutput.ProfileProbability, output.ProfileProbability); + Assert.AreEqual(calculatorOutput.SectionProbability, output.SectionProbability); + } + } + + [Test] + public void AssembleSection_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + var random = new Random(21); + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + void Call() => FailureMechanismSectionAssemblyGroupFactory.AssembleSection(new AssessmentSectionStub(), + random.NextBoolean(), + random.NextDouble(), random.NextDouble(), + random.NextBoolean(), + random.NextDouble(), random.NextDouble()); + + // Assert + var exception = Assert.Throws(Call); + Exception innerException = exception.InnerException; + Assert.IsInstanceOf(innerException); + Assert.AreEqual(innerException.Message, exception.Message); + } + } + } +} \ No newline at end of file