Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Categories/AssemblyCategoriesCalculatorStubTest.cs =================================================================== diff -u -r20d123c40d0d306e64a2d7881d428e36bde9dc2d -rd092c6839036b4971bf5d288f2a1ae7dcdcb2a4c --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Categories/AssemblyCategoriesCalculatorStubTest.cs (.../AssemblyCategoriesCalculatorStubTest.cs) (revision 20d123c40d0d306e64a2d7881d428e36bde9dc2d) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Categories/AssemblyCategoriesCalculatorStubTest.cs (.../AssemblyCategoriesCalculatorStubTest.cs) (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using Ringtoets.AssemblyTool.Data.Input; using Ringtoets.AssemblyTool.Data.Output; @@ -44,16 +45,30 @@ } [Test] - public void CalculateAssessmentSectionCategories_Always_ReturnEmptyCategories() + public void CalculateAssessmentSectionCategories_Always_ReturnsCategories() { // Setup var calculator = new AssemblyCategoriesCalculatorStub(); // Call - IEnumerable result = calculator.CalculateAssessmentSectionCategories(null); + AssessmentSectionAssemblyCategoryResult[] result = calculator.CalculateAssessmentSectionCategories(null).ToArray(); // Assert - CollectionAssert.IsEmpty(result); + Assert.AreEqual(3, result.Length); + CollectionAssert.AreEqual(new[] + { + 1, 2.01, 3.01 + }, result.Select(r => r.LowerBoundary)); + CollectionAssert.AreEqual(new[] + { + 2, 3, 4 + }, result.Select(r => r.UpperBoundary)); + CollectionAssert.AreEqual(new[] + { + AssessmentSectionAssemblyCategoryResultType.A, + AssessmentSectionAssemblyCategoryResultType.B, + AssessmentSectionAssemblyCategoryResultType.C + }, result.Select(r => r.Category)); } [Test] Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyCategoriesCalculatorStub.cs =================================================================== diff -u -r20d123c40d0d306e64a2d7881d428e36bde9dc2d -rd092c6839036b4971bf5d288f2a1ae7dcdcb2a4c --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyCategoriesCalculatorStub.cs (.../AssemblyCategoriesCalculatorStub.cs) (revision 20d123c40d0d306e64a2d7881d428e36bde9dc2d) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Categories/AssemblyCategoriesCalculatorStub.cs (.../AssemblyCategoriesCalculatorStub.cs) (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -47,7 +47,12 @@ Input = input; return AssessmentSectionCategoriesOutput - ?? (AssessmentSectionCategoriesOutput = new AssessmentSectionAssemblyCategoryResult[0]); + ?? (AssessmentSectionCategoriesOutput = new[] + { + new AssessmentSectionAssemblyCategoryResult(1, 2, AssessmentSectionAssemblyCategoryResultType.A), + new AssessmentSectionAssemblyCategoryResult(2.01, 3, AssessmentSectionAssemblyCategoryResultType.B), + new AssessmentSectionAssemblyCategoryResult(3.01, 4, AssessmentSectionAssemblyCategoryResultType.C) + }); } } } \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyToolCategoriesCalculationService.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyToolCategoriesCalculationService.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Service/AssemblyTool/AssemblyToolCategoriesCalculationService.cs (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -0,0 +1,59 @@ +// 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 Ringtoets.AssemblyTool.Data.Output; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Categories; +using Ringtoets.AssemblyTool.KernelWrapper.Kernels; +using Ringtoets.Common.Data.AssemblyTool; + +namespace Ringtoets.Common.Service.AssemblyTool +{ + /// + /// Calculation service for calculating the assembly tool categories. + /// + public static class AssemblyToolCategoriesCalculationService + { + /// + /// Calculates the assessment section assembly categories. + /// + /// The input to use in the calculation. + /// An of . + /// Thrown when is null. + public static IEnumerable CalculateAssessmentSectionAssemblyCategories(AssemblyCategoryInput input) + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + IAssemblyCategoriesCalculator calculator = AssemblyToolCalculatorFactory.Instance.CreateAssemblyCategoriesCalculator( + AssemblyToolKernelWrapperFactory.Instance); + + IEnumerable categories = calculator.CalculateAssessmentSectionCategories( + AssemblyCategoryInputConverter.Convert(input)); + + return AssemblyCategoryConverter.ConvertAssessmentSectionAssemblyCategories(categories); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj =================================================================== diff -u -r8c111accea72ca8a9205a8615102e16168f62ce7 -rd092c6839036b4971bf5d288f2a1ae7dcdcb2a4c --- Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision 8c111accea72ca8a9205a8615102e16168f62ce7) +++ Ringtoets/Common/src/Ringtoets.Common.Service/Ringtoets.Common.Service.csproj (.../Ringtoets.Common.Service.csproj) (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -17,6 +17,7 @@ + Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyToolCategoriesCalculationServiceTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyToolCategoriesCalculationServiceTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/AssemblyTool/AssemblyToolCategoriesCalculationServiceTest.cs (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -0,0 +1,119 @@ +// 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 NUnit.Framework; +using Ringtoets.AssemblyTool.Data.Input; +using Ringtoets.AssemblyTool.Data.Output; +using Ringtoets.AssemblyTool.KernelWrapper.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators; +using Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Categories; +using Ringtoets.Common.Data.AssemblyTool; +using Ringtoets.Common.Service.AssemblyTool; + +namespace Ringtoets.Common.Service.Test.AssemblyTool +{ + [TestFixture] + public class AssemblyToolCategoriesCalculationServiceTest + { + [Test] + public void CalculateAssessmentSectionAssemblyCategories_InputNull_ThrowsArgumentNullException() + { + // Call + TestDelegate call = () => AssemblyToolCategoriesCalculationService.CalculateAssessmentSectionAssemblyCategories(null); + + // Assert + var exception = Assert.Throws(call); + Assert.AreEqual("input", exception.ParamName); + } + + [Test] + public void CalculateAssessmentSectionAssemblyCategories_WithInput_SetsInputOnCalculator() + { + // Setup + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerBoundaryNorm = random.NextDouble(); + var input = new AssemblyCategoryInput(signalingNorm, lowerBoundaryNorm); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyCategoriesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + + //Call + AssemblyToolCategoriesCalculationService.CalculateAssessmentSectionAssemblyCategories(input); + + // Assert + AssemblyCategoriesCalculatorInput actualInput = calculator.Input; + Assert.AreEqual(signalingNorm, actualInput.SignalingNorm); + Assert.AreEqual(lowerBoundaryNorm, actualInput.LowerBoundaryNorm); + } + } + + [Test] + public void CalculateAssessmentSectionAssemblyCategories_CalculationRan_ReturnsOutput() + { + var random = new Random(11); + double signalingNorm = random.NextDouble(); + double lowerBoundaryNorm = random.NextDouble(); + var input = new AssemblyCategoryInput(signalingNorm, lowerBoundaryNorm); + + using (new AssemblyToolCalculatorFactoryConfig()) + { + var calculatorFactory = (TestAssemblyToolCalculatorFactory) AssemblyToolCalculatorFactory.Instance; + AssemblyCategoriesCalculatorStub calculator = calculatorFactory.LastCreatedAssemblyCategoriesCalculator; + + //Call + AssessmentSectionAssemblyCategory[] output = AssemblyToolCategoriesCalculationService.CalculateAssessmentSectionAssemblyCategories(input).ToArray(); + + // Assert + AssessmentSectionAssemblyCategoryResult[] calculatorOutput = calculator.AssessmentSectionCategoriesOutput.ToArray(); + + Assert.AreEqual(calculatorOutput.Length, output.Length); + CollectionAssert.AreEqual(calculatorOutput.Select(co => co.LowerBoundary), output.Select(o => o.LowerBoundary)); + CollectionAssert.AreEqual(calculatorOutput.Select(co => co.UpperBoundary), output.Select(o => o.UpperBoundary)); + CollectionAssert.AreEqual(calculatorOutput.Select(co => GetAssessmentSectionAssemblyCategoryType(co.Category)), output.Select(o => o.Type)); + } + } + + private static AssessmentSectionAssemblyCategoryType GetAssessmentSectionAssemblyCategoryType( + AssessmentSectionAssemblyCategoryResultType categoryType) + { + switch (categoryType) + { + case AssessmentSectionAssemblyCategoryResultType.APlus: + return AssessmentSectionAssemblyCategoryType.APlus; + case AssessmentSectionAssemblyCategoryResultType.A: + return AssessmentSectionAssemblyCategoryType.A; + case AssessmentSectionAssemblyCategoryResultType.B: + return AssessmentSectionAssemblyCategoryType.B; + case AssessmentSectionAssemblyCategoryResultType.C: + return AssessmentSectionAssemblyCategoryType.C; + case AssessmentSectionAssemblyCategoryResultType.D: + return AssessmentSectionAssemblyCategoryType.D; + default: + throw new NotSupportedException(); + } + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj =================================================================== diff -u -r8c111accea72ca8a9205a8615102e16168f62ce7 -rd092c6839036b4971bf5d288f2a1ae7dcdcb2a4c --- Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision 8c111accea72ca8a9205a8615102e16168f62ce7) +++ Ringtoets/Common/test/Ringtoets.Common.Service.Test/Ringtoets.Common.Service.Test.csproj (.../Ringtoets.Common.Service.Test.csproj) (revision d092c6839036b4971bf5d288f2a1ae7dcdcb2a4c) @@ -29,6 +29,7 @@ +