Index: Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupLimitsCreator.cs =================================================================== diff -u --- Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupLimitsCreator.cs (revision 0) +++ Riskeer/AssemblyTool/src/Riskeer.AssemblyTool.KernelWrapper/Creators/AssemblyGroupLimitsCreator.cs (revision def12301f856177f264aa8d09758716ae45fbc45) @@ -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 AssemblyGroupLimitsCreator + { + /// + /// 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 CreateFailureMechanismSectionAssemblyGroupLimits( + CategoriesList categories) + { + if (categories == null) + { + throw new ArgumentNullException(nameof(categories)); + } + + return categories.Categories.Select(CreateFailureMechanismSectionAssemblyGroupLimits) + .ToArray(); + } + + private static FailureMechanismSectionAssemblyGroupLimits CreateFailureMechanismSectionAssemblyGroupLimits(InterpretationCategory category) + { + return new FailureMechanismSectionAssemblyGroupLimits( + FailureMechanismSectionAssemblyResultCreator.CreateFailureMechanismSectionAssemblyGroup(category.Category), + category.LowerLimit, + category.UpperLimit); + } + } +} \ No newline at end of file Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupLimitsCreatorTest.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupLimitsCreatorTest.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.Test/Creators/AssemblyGroupLimitsCreatorTest.cs (revision def12301f856177f264aa8d09758716ae45fbc45) @@ -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 AssemblyGroupLimitsCreatorTest + { + [Test] + public void CreateFailureMechanismSectionAssemblyGroupLimits_CategoriesNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyGroupLimitsCreator.CreateFailureMechanismSectionAssemblyGroupLimits(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("categories", exception.ParamName); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupLimits_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 = + AssemblyGroupLimitsCreator.CreateFailureMechanismSectionAssemblyGroupLimits(categories); + + // Assert + AssemblyGroupLimitsAssert.AssertFailureMechanismSectionAssemblyGroupLimits(categories, result); + } + + [Test] + public void CreateFailureMechanismSectionAssemblyGroupLimits_CategoryWithInvalidInterpretationCategory_ThrowsInvalidEnumArgumentException() + { + // Setup + var categories = new CategoriesList(new[] + { + new InterpretationCategory((EInterpretationCategory) 99, new Probability(0), new Probability(1)) + }); + + // Call + TestDelegate test = () => AssemblyGroupLimitsCreator.CreateFailureMechanismSectionAssemblyGroupLimits(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 Index: Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupLimitsAssert.cs =================================================================== diff -u --- Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupLimitsAssert.cs (revision 0) +++ Riskeer/AssemblyTool/test/Riskeer.AssemblyTool.KernelWrapper.TestUtil/AssemblyGroupLimitsAssert.cs (revision def12301f856177f264aa8d09758716ae45fbc45) @@ -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 limits. + /// + public static class AssemblyGroupLimitsAssert + { + /// + /// Asserts whether is equal to . + /// + /// The original with + /// . + /// The actual collection of . + /// Thrown when + /// is not equal to . + public static void AssertFailureMechanismSectionAssemblyGroupLimits(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); + FailureMechanismSectionAssemblyGroupLimits 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