Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/AssemblyToolCalculatorFactory.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/AssemblyToolCalculatorFactory.cs (.../AssemblyToolCalculatorFactory.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/AssemblyToolCalculatorFactory.cs (.../AssemblyToolCalculatorFactory.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -43,7 +43,7 @@ internal set => instance = value; } - public IAssemblyGroupLimitsCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory) + public IAssemblyGroupBoundariesCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory) { return new AssemblyGroupBoundariesCalculator(factory); } Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculator.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculator.cs (.../AssemblyGroupBoundariesCalculator.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculator.cs (.../AssemblyGroupBoundariesCalculator.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -35,7 +35,7 @@ /// /// Class representing an assembly group boundaries calculator. /// - public class AssemblyGroupBoundariesCalculator : IAssemblyGroupLimitsCalculator + public class AssemblyGroupBoundariesCalculator : IAssemblyGroupBoundariesCalculator { private readonly IAssemblyToolKernelFactory factory; @@ -63,15 +63,15 @@ CategoriesList output = kernel.CalculateInterpretationCategoryLimitsWbi03( new AssessmentSection(new Probability(signalingNorm), new Probability(lowerLimitNorm))); - return AssemblyGroupLimitsCreator.CreateFailureMechanismSectionAssemblyGroupLimits(output); + return AssemblyGroupBoundariesCreator.CreateFailureMechanismSectionAssemblyGroupBoundaries(output); } catch (AssemblyException e) { - throw new AssemblyGroupLimitsCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e); + throw new AssemblyGroupBoundariesCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e); } catch (Exception e) { - throw new AssemblyGroupLimitsCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e); + throw new AssemblyGroupBoundariesCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e); } } } Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculatorException.cs =================================================================== diff -u --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculatorException.cs (revision 0) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupBoundariesCalculatorException.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,68 @@ +// 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 System.Runtime.Serialization; + +namespace Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories +{ + /// + /// Exception that is thrown when an error occurs while performing an assembly group boundaries calculation. + /// + [Serializable] + public class AssemblyGroupBoundariesCalculatorException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public AssemblyGroupBoundariesCalculatorException() {} + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The message that describes the error. + public AssemblyGroupBoundariesCalculatorException(string message) + : base(message) {} + + /// + /// Initializes a new instance of the class with a specified error message + /// and a reference to the inner exception that is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, + /// or null if no inner exception is specified. + public AssemblyGroupBoundariesCalculatorException(string message, Exception innerException) : base(message, innerException) {} + + /// + /// Initializes a new instance of with + /// serialized data. + /// The that holds the serialized + /// object data about the exception being thrown. + /// The that contains contextual + /// information about the source or destination. + /// The parameter is + /// null. + /// The class name is null or + /// is zero (0). + protected AssemblyGroupBoundariesCalculatorException(SerializationInfo info, StreamingContext context) : base(info, context) {} + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyGroupLimitsCalculatorException.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 57771831fd6bae482a362cb0687e82b08c62b575 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/IAssemblyGroupBoundariesCalculator.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/Categories/IAssemblyGroupLimitsCalculator.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/IAssemblyToolCalculatorFactory.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/IAssemblyToolCalculatorFactory.cs (.../IAssemblyToolCalculatorFactory.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Calculators/IAssemblyToolCalculatorFactory.cs (.../IAssemblyToolCalculatorFactory.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -35,9 +35,9 @@ /// Creates an assembly group boundaries calculator. /// /// The factory responsible for creating the kernel. - /// The assembly group limits calculator. + /// The assembly group boundaries calculator. /// Thrown when is null. - IAssemblyGroupLimitsCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory); + IAssemblyGroupBoundariesCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory); /// /// Creates a failure mechanism section assembly calculator. Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupBoundariesCreator.cs =================================================================== diff -u --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupBoundariesCreator.cs (revision 0) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupBoundariesCreator.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,69 @@ +// 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 System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using Assembly.Kernel.Model.Categories; +using Riskeer.AssemblyTool.Data; + +namespace Riskeer.AssemblyTool.KernelWrapper.Creators +{ + /// + /// Creates instances. + /// + internal static class AssemblyGroupBoundariesCreator + { + /// + /// Creates a collection of + /// based on the information given in the . + /// + /// The with + /// to create the result for. + /// A collection of + /// with information taken from the . + /// Thrown when is null. + /// Thrown when + /// contains an invalid value. + /// Thrown when + /// contains a valid value, but unsupported. + public static IEnumerable CreateFailureMechanismSectionAssemblyGroupBoundaries( + CategoriesList categories) + { + if (categories == null) + { + throw new ArgumentNullException(nameof(categories)); + } + + return categories.Categories.Select(CreateFailureMechanismSectionAssemblyGroupBoundaries) + .ToArray(); + } + + private static FailureMechanismSectionAssemblyGroupBoundaries CreateFailureMechanismSectionAssemblyGroupBoundaries(InterpretationCategory category) + { + return new FailureMechanismSectionAssemblyGroupBoundaries( + FailureMechanismSectionAssemblyResultCreator.CreateFailureMechanismSectionAssemblyGroup(category.Category), + category.LowerLimit, + category.UpperLimit); + } + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupLimitsCreator.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs (.../AssemblyToolCalculatorFactoryTest.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/AssemblyToolCalculatorFactoryTest.cs (.../AssemblyToolCalculatorFactoryTest.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -75,15 +75,15 @@ } [Test] - public void CreateAssemblyGroupLimitsCalculatorCalculator_WithKernelFactory_ReturnsAssemblyCategoriesCalculator() + public void CreateAssemblyGroupBoundariesCalculator_WithKernelFactory_ReturnsAssemblyCategoriesCalculator() { // Setup IAssemblyToolCalculatorFactory factory = AssemblyToolCalculatorFactory.Instance; using (new AssemblyToolKernelFactoryConfig()) { // Call - IAssemblyGroupLimitsCalculator calculator = factory.CreateAssemblyGroupBoundariesCalculator( + IAssemblyGroupBoundariesCalculator calculator = factory.CreateAssemblyGroupBoundariesCalculator( AssemblyToolKernelFactory.Instance); // Assert Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorExceptionTest.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorExceptionTest.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorExceptionTest.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,32 @@ +// 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.KernelWrapper.Calculators.Categories; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Categories +{ + [TestFixture] + public class AssemblyGroupBoundariesCalculatorExceptionTest : + CustomExceptionDesignGuidelinesTestFixture {} +} \ No newline at end of file Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorTest.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorTest.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupBoundariesCalculatorTest.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,222 @@ +// 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 System.Collections.Generic; +using Assembly.Kernel.Exceptions; +using Assembly.Kernel.Model; +using Assembly.Kernel.Model.AssessmentSection; +using Assembly.Kernel.Model.Categories; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.Creators; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Kernels; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Kernels.Categories; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Calculators.Categories +{ + [TestFixture] + public class AssemblyGroupBoundariesCalculatorTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Setup + var mocks = new MockRepository(); + var factory = mocks.Stub(); + mocks.ReplayAll(); + + // Call + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Assert + Assert.IsInstanceOf(calculator); + mocks.VerifyAll(); + } + + [Test] + public void Constructor_FactoryNull_ThrowsArgumentNullException() + { + // Call + void Call() => new AssemblyGroupBoundariesCalculator(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("factory", exception.ParamName); + } + + [Test] + public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_WithValidInput_InputCorrectlySendToKernel() + { + // Setup + const double lowerLimitNorm = 0.001; + const double signalingNorm = 0.0001; + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedCategoryLimitsKernel; + CategoriesList categoryLimits = CreateCategoryLimits(); + categoryLimitsKernel.CategoryLimits = categoryLimits; + + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Call + calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + AssessmentSection assessmentSection = categoryLimitsKernel.AssessmentSection; + ProbabilityAssert.AreEqual(lowerLimitNorm, assessmentSection.FailureProbabilityLowerLimit); + ProbabilityAssert.AreEqual(signalingNorm, assessmentSection.FailureProbabilitySignallingLimit); + } + } + + [Test] + public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelWithCompleteOutput_ReturnsExpectedFailureMechanismSectionAssembly() + { + // Setup + const double lowerLimitNorm = 0.001; + const double signalingNorm = 0.0001; + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedCategoryLimitsKernel; + CategoriesList categoryLimits = CreateCategoryLimits(); + categoryLimitsKernel.CategoryLimits = categoryLimits; + + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Call + IEnumerable result = + calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + Assert.IsTrue(categoryLimitsKernel.Calculated); + + AssemblyGroupBoundariesAssert.AssertFailureMechanismSectionAssemblyGroupBoundaries(categoryLimits, result); + } + } + + [Test] + public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelWithInCompleteOutput_ThrowsAssemblyGroupBoundariesCalculatorException() + { + // Setup + const double lowerLimitNorm = 0.001; + const double signalingNorm = 0.0001; + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedCategoryLimitsKernel; + var categoryLimits = new CategoriesList(new[] + { + new InterpretationCategory((EInterpretationCategory) 99, new Probability(0), new Probability(1)) + }); + categoryLimitsKernel.CategoryLimits = categoryLimits; + + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Call + void Call() => calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + var exception = Assert.Throws(Call); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + + Assert.IsTrue(categoryLimitsKernel.Calculated); + } + } + + [Test] + public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelThrowsException_ThrowsAssemblyGroupBoundariesCalculatorException() + { + // Setup + const double lowerLimitNorm = 0.001; + const double signalingNorm = 0.0001; + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedCategoryLimitsKernel; + categoryLimitsKernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Call + void Call() => calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + Assert.IsFalse(categoryLimitsKernel.Calculated); + + var exception = Assert.Throws(Call); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); + } + } + + [Test] + public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelThrowsAssemblyException_ThrowsAssemblyGroupBoundariesCalculatorException() + { + // Setup + const double lowerLimitNorm = 0.001; + const double signalingNorm = 0.0001; + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + CategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedCategoryLimitsKernel; + categoryLimitsKernel.ThrowAssemblyExceptionOnCalculate = true; + + var calculator = new AssemblyGroupBoundariesCalculator(factory); + + // Call + void Call() => calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + Assert.IsFalse(categoryLimitsKernel.Calculated); + + var exception = Assert.Throws(Call); + var innerException = exception.InnerException as AssemblyException; + Assert.IsNotNull(innerException); + Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(innerException.Errors), exception.Message); + } + } + + private static CategoriesList CreateCategoryLimits() + { + var random = new Random(21); + return new CategoriesList(new[] + { + new InterpretationCategory(random.NextEnumValue(), new Probability(0), new Probability(0.25)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.25), new Probability(0.5)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.5), new Probability(0.75)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.75), new Probability(1)) + }); + } + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupLimitsCalculatorExceptionTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyGroupLimitsCalculatorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupBoundariesCreatorTest.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupBoundariesCreatorTest.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupBoundariesCreatorTest.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,88 @@ +// 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 System.Collections.Generic; +using System.ComponentModel; +using Assembly.Kernel.Model; +using Assembly.Kernel.Model.Categories; +using Core.Common.TestUtil; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Creators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil; + +namespace Riskeer.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class AssemblyGroupBoundariesCreatorTest + { + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_CategoriesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyGroupBoundariesCreator.CreateFailureMechanismSectionAssemblyGroupBoundaries(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("categories", exception.ParamName); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_WithCategories_ReturnFailureMechanismAssemblyCategoryResult() + { + // Setup + var random = new Random(11); + + var categories = new CategoriesList(new[] + { + new InterpretationCategory(random.NextEnumValue(), new Probability(0), new Probability(0.25)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.25), new Probability(0.5)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.5), new Probability(0.75)), + new InterpretationCategory(random.NextEnumValue(), new Probability(0.75), new Probability(1)) + }); + + // Call + IEnumerable result = + AssemblyGroupBoundariesCreator.CreateFailureMechanismSectionAssemblyGroupBoundaries(categories); + + // Assert + AssemblyGroupBoundariesAssert.AssertFailureMechanismSectionAssemblyGroupBoundaries(categories, result); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_CategoryWithInvalidInterpretationCategory_ThrowsInvalidEnumArgumentException() + { + // Setup + var categories = new CategoriesList(new[] + { + new InterpretationCategory((EInterpretationCategory) 99, new Probability(0), new Probability(1)) + }); + + // Call + TestDelegate test = () => AssemblyGroupBoundariesCreator.CreateFailureMechanismSectionAssemblyGroupBoundaries(categories); + + // Assert + var exceptionMessage = $"The value of argument 'category' (99) is invalid for Enum type '{nameof(EInterpretationCategory)}'."; + TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, exceptionMessage); + } + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupLimitsCreatorTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupBoundariesAssert.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupBoundariesAssert.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupBoundariesAssert.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,92 @@ +// 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 System.Collections.Generic; +using System.Linq; +using Assembly.Kernel.Model.Categories; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; + +namespace Riskeer.AssemblyTool.KernelWrapper.TestUtil +{ + /// + /// Class for asserting assembly group boundaries. + /// + public static class AssemblyGroupBoundariesAssert + { + /// + /// Asserts whether is equal to . + /// + /// The original with + /// . + /// The actual collection of . + /// Thrown when + /// is not equal to . + public static void AssertFailureMechanismSectionAssemblyGroupBoundaries(CategoriesList original, + IEnumerable actual) + { + int expectedNrOfCategories = original.Categories.Length; + Assert.AreEqual(expectedNrOfCategories, actual.Count()); + + for (int i = 0; i < expectedNrOfCategories; i++) + { + InterpretationCategory originalItem = original.Categories.ElementAt(i); + FailureMechanismSectionAssemblyGroupBoundaries actualItem = actual.ElementAt(i); + + Assert.AreEqual(GetAssemblyGroup(originalItem.Category), actualItem.Group); + ProbabilityAssert.AreEqual(actualItem.LowerBoundary, originalItem.LowerLimit); + ProbabilityAssert.AreEqual(actualItem.UpperBoundary, originalItem.UpperLimit); + } + } + + private static FailureMechanismSectionAssemblyGroup GetAssemblyGroup(EInterpretationCategory category) + { + switch (category) + { + case EInterpretationCategory.ND: + return FailureMechanismSectionAssemblyGroup.ND; + case EInterpretationCategory.III: + return FailureMechanismSectionAssemblyGroup.III; + case EInterpretationCategory.II: + return FailureMechanismSectionAssemblyGroup.II; + case EInterpretationCategory.I: + return FailureMechanismSectionAssemblyGroup.I; + case EInterpretationCategory.ZeroPlus: + return FailureMechanismSectionAssemblyGroup.ZeroPlus; + case EInterpretationCategory.Zero: + return FailureMechanismSectionAssemblyGroup.Zero; + case EInterpretationCategory.IMin: + return FailureMechanismSectionAssemblyGroup.IMin; + case EInterpretationCategory.IIMin: + return FailureMechanismSectionAssemblyGroup.IIMin; + case EInterpretationCategory.IIIMin: + return FailureMechanismSectionAssemblyGroup.IIIMin; + case EInterpretationCategory.D: + return FailureMechanismSectionAssemblyGroup.D; + case EInterpretationCategory.Gr: + return FailureMechanismSectionAssemblyGroup.Gr; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupLimitsAssert.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyGroupBoundariesCalculatorStub.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyGroupBoundariesCalculatorStub.cs (.../AssemblyGroupBoundariesCalculatorStub.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyGroupBoundariesCalculatorStub.cs (.../AssemblyGroupBoundariesCalculatorStub.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -29,7 +29,7 @@ /// /// Assembly group boundaries calculator stub for testing purposes. /// - public class AssemblyGroupBoundariesCalculatorStub : IAssemblyGroupLimitsCalculator + public class AssemblyGroupBoundariesCalculatorStub : IAssemblyGroupBoundariesCalculator { /// /// Gets the signaling norm that is used in the calculation. @@ -47,9 +47,9 @@ public bool ThrowExceptionOnCalculate { private get; set; } /// - /// Gets or sets the output of the calculation. + /// Gets or sets the output of the calculation. /// - public IEnumerable FailureMechanismSectionAssemblyGroupLimitsOutput { get; set; } + public IEnumerable FailureMechanismSectionAssemblyGroupBoundariesOutput { get; set; } public IEnumerable CalculateFailureMechanismSectionAssemblyGroupBoundaries(double signalingNorm, double lowerLimitNorm) @@ -62,8 +62,8 @@ SignalingNorm = signalingNorm; LowerLimitNorm = lowerLimitNorm; - return FailureMechanismSectionAssemblyGroupLimitsOutput ?? - (FailureMechanismSectionAssemblyGroupLimitsOutput = new[] + return FailureMechanismSectionAssemblyGroupBoundariesOutput ?? + (FailureMechanismSectionAssemblyGroupBoundariesOutput = new[] { new FailureMechanismSectionAssemblyGroupBoundaries(FailureMechanismSectionAssemblyGroup.I, 1, 2), new FailureMechanismSectionAssemblyGroupBoundaries(FailureMechanismSectionAssemblyGroup.II, 2.01, 3), Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/TestAssemblyToolCalculatorFactory.cs =================================================================== diff -u -r9e123cbdd548d60db387f9a11395709ce410da62 -r7547caf55a454c8aa66b1cf88885f520123e4ea9 --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/TestAssemblyToolCalculatorFactory.cs (.../TestAssemblyToolCalculatorFactory.cs) (revision 9e123cbdd548d60db387f9a11395709ce410da62) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/Calculators/TestAssemblyToolCalculatorFactory.cs (.../TestAssemblyToolCalculatorFactory.cs) (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -58,7 +58,7 @@ /// public FailurePathAssemblyCalculatorStub LastCreatedFailurePathAssemblyCalculator { get; } - public IAssemblyGroupLimitsCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory) + public IAssemblyGroupBoundariesCalculator CreateAssemblyGroupBoundariesCalculator(IAssemblyToolKernelFactory factory) { return LastCreatedAssemblyGroupBoundariesCalculator; } Index: Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupBoundariesFactory.cs =================================================================== diff -u --- Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupBoundariesFactory.cs (revision 0) +++ Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupBoundariesFactory.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,59 @@ +// 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.Collections.Generic; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.Kernels; +using Riskeer.Common.Data.Exceptions; + +namespace Riskeer.Common.Data.AssemblyTool +{ + /// + /// Factory for calculating the assembly tool group boundaries. + /// + public static class AssemblyToolGroupBoundariesFactory + { + /// + /// Creates the failure mechanism section assembly group boundaries. + /// + /// The signaling norm to use in the calculation. + /// The lower limit norm to use in the calculation. + /// A collection of . + /// Thrown when an error occurred while creating the assembly group boundaries. + public static IEnumerable CreateFailureMechanismSectionAssemblyGroupBoundaries( + double signalingNorm, double lowerLimitNorm) + { + IAssemblyGroupBoundariesCalculator calculator = AssemblyToolCalculatorFactory.Instance.CreateAssemblyGroupBoundariesCalculator( + AssemblyToolKernelFactory.Instance); + + try + { + return calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + } + catch (AssemblyCategoriesCalculatorException e) + { + throw new AssemblyException(e.Message, e); + } + } + } +} \ No newline at end of file Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/Common/src/Riskeer.Common.Data/AssemblyTool/AssemblyToolGroupLimitsFactory.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupBoundariesFactoryTest.cs =================================================================== diff -u --- Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupBoundariesFactoryTest.cs (revision 0) +++ Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupBoundariesFactoryTest.cs (revision 7547caf55a454c8aa66b1cf88885f520123e4ea9) @@ -0,0 +1,116 @@ +// 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 System.Linq; +using NUnit.Framework; +using Riskeer.AssemblyTool.Data; +using Riskeer.AssemblyTool.KernelWrapper.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.Calculators.Categories; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Riskeer.AssemblyTool.KernelWrapper.TestUtil.Calculators.Categories; +using Riskeer.Common.Data.AssemblyTool; +using Riskeer.Common.Data.Exceptions; + +namespace Riskeer.Common.Data.Test.AssemblyTool +{ + [TestFixture] + public class AssemblyToolGroupBoundariesFactoryTest + { + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerLimitNorm = random.NextDouble(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupBoundariesCalculator; + + // Call + AssemblyToolGroupBoundariesFactory.CreateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm); + + // Assert + Assert.AreEqual(signalingNorm, calculator.SignalingNorm); + Assert.AreEqual(lowerLimitNorm, calculator.LowerLimitNorm); + } + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_CalculatorRan_ReturnsOutput() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerLimitNorm = random.NextDouble(); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupBoundariesCalculator; + + // Call + FailureMechanismSectionAssemblyGroupBoundaries[] output = + AssemblyToolGroupBoundariesFactory.CreateFailureMechanismSectionAssemblyGroupBoundaries(signalingNorm, lowerLimitNorm) + .ToArray(); + + // Assert + FailureMechanismSectionAssemblyGroupBoundaries[] calculatorOutput = calculator.FailureMechanismSectionAssemblyGroupBoundariesOutput.ToArray(); + + int expectedNrOfOutputs = calculatorOutput.Length; + Assert.AreEqual(expectedNrOfOutputs, output.Length); + for (var i = 0; i < expectedNrOfOutputs; i++) + { + FailureMechanismSectionAssemblyGroupBoundaries expectedOutput = calculatorOutput[i]; + FailureMechanismSectionAssemblyGroupBoundaries actualOutput = calculatorOutput[i]; + + Assert.AreEqual(expectedOutput.Group, actualOutput.Group); + Assert.AreEqual(expectedOutput.LowerBoundary, actualOutput.LowerBoundary); + Assert.AreEqual(expectedOutput.UpperBoundary, actualOutput.UpperBoundary); + } + } + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupBoundaries_CalculatorThrowsException_ThrowsAssemblyException() + { + // Setup + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyGroupBoundariesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyGroupBoundariesCalculator; + calculator.ThrowExceptionOnCalculate = true; + + // Call + void Call() => AssemblyToolGroupBoundariesFactory.CreateFailureMechanismSectionAssemblyGroupBoundaries(0, 0); + + // 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 Fisheye: Tag 7547caf55a454c8aa66b1cf88885f520123e4ea9 refers to a dead (removed) revision in file `Riskeer/Common/test/Riskeer.Common.Data.Test/AssemblyTool/AssemblyToolGroupLimitsFactoryTest.cs'. Fisheye: No comparison available. Pass `N' to diff?