Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/CombinedFailureMechanismSectionAssemblyCreator.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/CombinedFailureMechanismSectionAssemblyCreator.cs (revision 0) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Creators/CombinedFailureMechanismSectionAssemblyCreator.cs (revision 6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe) @@ -0,0 +1,70 @@ +// 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.Linq; +using Assembly.Kernel.Model; +using Ringtoets.AssemblyTool.Data; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Creators +{ + /// + /// Creates instances. + /// + internal static class CombinedFailureMechanismSectionAssemblyCreator + { + /// + /// Creates a collection of + /// based on the . + /// + /// The to create the + /// for. + /// A collection of . + /// Thrown when + /// is null. + public static IEnumerable Create(AssemblyResult result) + { + if (result == null) + { + throw new ArgumentNullException(nameof(result)); + } + + var sectionAssemblies = new List(); + + for (var i = 0; i < result.CombinedSectionResult.Count(); i++) + { + FmSectionWithDirectCategory section = result.CombinedSectionResult.ElementAt(i); + sectionAssemblies.Add(new CombinedFailureMechanismSectionAssembly( + section.SectionStart, section.SectionEnd, + FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup(section.Category), + result.ResultPerFailureMechanism + .Select(failureMechanismSectionList => + (FmSectionWithDirectCategory) failureMechanismSectionList.Results.ElementAt(i)) + .Select(element => + FailureMechanismSectionAssemblyCreator.CreateFailureMechanismSectionAssemblyCategoryGroup( + element.Category)).ToArray())); + } + + return sectionAssemblies; + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj =================================================================== diff -u -r3beb793b4db2bc773a4ae68783902c359db1e6bb -r6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Ringtoets.AssemblyTool.KernelWrapper.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.csproj) (revision 6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe) @@ -30,6 +30,7 @@ + Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs =================================================================== diff -u --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs (revision 0) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Creators/CombinedFailureMechanismSectionAssemblyCreatorTest.cs (revision 6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe) @@ -0,0 +1,135 @@ +// 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.Linq; +using Assembly.Kernel.Model; +using Assembly.Kernel.Model.FmSectionTypes; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.AssemblyTool.Data; +using Ringtoets.AssemblyTool.KernelWrapper.Creators; + +namespace Ringtoets.AssemblyTool.KernelWrapper.Test.Creators +{ + [TestFixture] + public class CombinedFailureMechanismSectionAssemblyCreatorTest + { + [Test] + public void Create_ResultNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => CombinedFailureMechanismSectionAssemblyCreator.Create(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("result", exception.ParamName); + } + + [Test] + public void Create_WithResult_ReturnCombinedFailureMechanismSectionAssemblies() + { + // Setup + var random = new Random(21); + var failureMechanism1 = new FailureMechanism(random.NextDouble(1, 2), random.NextDouble()); + var failureMechanism2 = new FailureMechanism(random.NextDouble(1, 2), random.NextDouble()); + + var sections = new[] + { + new Tuple(0, 2), + new Tuple(2, 5), + new Tuple(5, random.NextDouble(5, 6)) + }; + + var failureMechanismResults = new[] + { + new FailureMechanismSectionList(failureMechanism1, new [] + { + new FmSectionWithDirectCategory(sections[0].Item1, sections[0].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[1].Item1, sections[1].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[2].Item1, sections[2].Item2, random.NextEnumValue()), + }), + new FailureMechanismSectionList(failureMechanism2, new [] + { + new FmSectionWithDirectCategory(sections[0].Item1, sections[0].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[1].Item1, sections[1].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[2].Item1, sections[2].Item2, random.NextEnumValue()), + }) + }; + + var combinedResults = new[] + { + new FmSectionWithDirectCategory(sections[0].Item1, sections[0].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[1].Item1, sections[1].Item2, random.NextEnumValue()), + new FmSectionWithDirectCategory(sections[2].Item1, sections[2].Item2, random.NextEnumValue()), + }; + + var assembly = new AssemblyResult(failureMechanismResults, combinedResults); + + // Call + CombinedFailureMechanismSectionAssembly[] results = CombinedFailureMechanismSectionAssemblyCreator.Create(assembly).ToArray(); + + // Assert + Assert.AreEqual(3, results.Length); + for (var i = 0; i < results.Length; i++) + { + Assert.AreEqual(sections[i].Item1, results[i].SectionStart); + Assert.AreEqual(sections[i].Item2, results[i].SectionEnd); + Assert.AreEqual(GetResultGroup(combinedResults[i].Category), results[i].CombinedResult); + Assert.AreEqual(failureMechanismResults.Length, results[i].FailureMechanismResults.Count()); + + for (var j = 0; j < failureMechanismResults.Length; j++) + { + FailureMechanismSectionAssemblyCategoryGroup expectedGroup = GetResultGroup(((FmSectionWithDirectCategory) failureMechanismResults[j].Results[i]).Category); + Assert.AreEqual(expectedGroup, results[i].FailureMechanismResults.ElementAt(j)); + } + } + } + + private static FailureMechanismSectionAssemblyCategoryGroup GetResultGroup(EFmSectionCategory combinedResult) + { + switch (combinedResult) + { + case EFmSectionCategory.Iv: + return FailureMechanismSectionAssemblyCategoryGroup.Iv; + case EFmSectionCategory.IIv: + return FailureMechanismSectionAssemblyCategoryGroup.IIv; + case EFmSectionCategory.IIIv: + return FailureMechanismSectionAssemblyCategoryGroup.IIIv; + case EFmSectionCategory.IVv: + return FailureMechanismSectionAssemblyCategoryGroup.IVv; + case EFmSectionCategory.Vv: + return FailureMechanismSectionAssemblyCategoryGroup.Vv; + case EFmSectionCategory.VIv: + return FailureMechanismSectionAssemblyCategoryGroup.VIv; + case EFmSectionCategory.VIIv: + return FailureMechanismSectionAssemblyCategoryGroup.VIIv; + case EFmSectionCategory.Gr: + return FailureMechanismSectionAssemblyCategoryGroup.None; + case EFmSectionCategory.NotApplicable: + return FailureMechanismSectionAssemblyCategoryGroup.NotApplicable; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj =================================================================== diff -u -r3beb793b4db2bc773a4ae68783902c359db1e6bb -r6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 3beb793b4db2bc773a4ae68783902c359db1e6bb) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Ringtoets.AssemblyTool.KernelWrapper.Test.csproj (.../Ringtoets.AssemblyTool.KernelWrapper.Test.csproj) (revision 6d88e6a0ed8c51eaf54bc6facfd1b0a9a6d1aafe) @@ -32,6 +32,7 @@ +