Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs =================================================================== diff -u -rd7696913d8f9239cb80eb2c3bac6cc0ccf23d479 -r82a3504384d5138339e41c6f7b5e586451f54661 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs (.../FailureMechanismSectionAssemblyCalculatorStubTest.cs) (revision d7696913d8f9239cb80eb2c3bac6cc0ccf23d479) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Test/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStubTest.cs (.../FailureMechanismSectionAssemblyCalculatorStubTest.cs) (revision 82a3504384d5138339e41c6f7b5e586451f54661) @@ -19,6 +19,10 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; +using System.Linq; +using AssemblyTool.Kernel.Data.AssemblyCategories; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; @@ -43,8 +47,13 @@ Assert.AreEqual((SimpleAssessmentResultValidityOnlyType) 0, calculator.SimpleAssessmentValidityOnlyInput); Assert.IsNull(calculator.SimpleAssessmentAssemblyOutput); + Assert.IsNull(calculator.DetailedAssessmentWithLengthEffectInput); + Assert.IsNull(calculator.DetailedAssessmentInput); + Assert.IsNull(calculator.DetailedAssessmentAssemblyOutput); } + #region Simple Assessment + [Test] public void AssembleSimpleAssessment_ThrowExceptionOnCalculateFalseAndOutputNotSet_ReturnOutput() { @@ -136,5 +145,172 @@ Assert.AreEqual("Message", exception.Message); Assert.IsNotNull(exception.InnerException); } + + #endregion + + #region Detailed Assessment + + [Test] + public void AssembleDetailedAssessment_ThrowExceptionOnCalculateFalseAndOutputNotSet_ReturnOutput() + { + // Setup + var random = new Random(39); + var calculator = new FailureMechanismSectionAssemblyCalculatorStub(); + + // Call + FailureMechanismSectionAssembly assembly = calculator.AssembleDetailedAssessment( + random.NextDouble(), + new[] + { + new FailureMechanismSectionAssemblyCategory(random.NextRoundedDouble(0.0, 0.5), + random.NextRoundedDouble(0.6, 1.0), + random.NextEnumValue()) + }); + + // Assert + Assert.AreEqual(1.0, assembly.Probability); + Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroup.VIIv, assembly.Group); + } + + [Test] + public void AssembleDetailedAssessment_ThrowExceptionOnCalculateFalse_SetsInput() + { + // Setup + var random = new Random(39); + double probability = random.NextDouble(); + double lowerBoundary = random.NextRoundedDouble(0.0, 0.5); + double upperBoundary = random.NextRoundedDouble(0.6, 1.0); + + var calculator = new FailureMechanismSectionAssemblyCalculatorStub(); + + // Call + calculator.AssembleDetailedAssessment( + probability, + new[] + { + new FailureMechanismSectionAssemblyCategory(lowerBoundary, + upperBoundary, + FailureMechanismSectionAssemblyCategoryGroup.IIv) + }); + + // Assert + Assert.AreEqual(probability, calculator.DetailedAssessmentInput.Probability); + + FailureMechanismSectionCategory actualSectionCategory = calculator.DetailedAssessmentInput.Categories.Single(); + Assert.AreEqual(lowerBoundary, actualSectionCategory.LowerBoundary); + Assert.AreEqual(upperBoundary, actualSectionCategory.UpperBoundary); + Assert.AreEqual(FailureMechanismSectionCategoryGroup.IIv, actualSectionCategory.CategoryGroup); + } + + [Test] + public void AssembleDetailedAssessment_ThrowExceptionOnCalculateTrue_ThrowsFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + var calculator = new FailureMechanismSectionAssemblyCalculatorStub + { + ThrowExceptionOnCalculate = true + }; + + // Call + TestDelegate test = () => calculator.AssembleDetailedAssessment( + random.NextDouble(), + new[] + { + new FailureMechanismSectionAssemblyCategory(random.NextRoundedDouble(0.0, 0.5), + random.NextRoundedDouble(0.6, 1.0), + random.NextEnumValue()) + }); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Message", exception.Message); + Assert.IsNotNull(exception.InnerException); + } + + [Test] + public void AssembleDetailedAssessmentWithLengthEffect_ThrowExceptionOnCalculateFalseAndOutputNotSet_ReturnOutput() + { + // Setup + var random = new Random(39); + var calculator = new FailureMechanismSectionAssemblyCalculatorStub(); + + // Call + FailureMechanismSectionAssembly assembly = calculator.AssembleDetailedAssessment( + random.NextDouble(), + new[] + { + new FailureMechanismSectionAssemblyCategory(random.NextRoundedDouble(0.0, 0.5), + random.NextRoundedDouble(0.6, 1.0), + random.NextEnumValue()) + }, + random.NextRoundedDouble(1.0, 10.0)); + + // Assert + Assert.AreEqual(0.0, assembly.Probability); + Assert.AreEqual(FailureMechanismSectionAssemblyCategoryGroup.VIIv, assembly.Group); + } + + [Test] + public void AssembleDetailedAssessmentWithLengthEffect_ThrowExceptionOnCalculateFalse_SetsInput() + { + // Setup + var random = new Random(39); + double probability = random.NextDouble(); + double lowerBoundary = random.NextRoundedDouble(0.0, 0.5); + double upperBoundary = random.NextRoundedDouble(0.6, 1.0); + double n = random.NextRoundedDouble(1.0, 10.0); + + var calculator = new FailureMechanismSectionAssemblyCalculatorStub(); + + // Call + calculator.AssembleDetailedAssessment( + probability, + new[] + { + new FailureMechanismSectionAssemblyCategory(lowerBoundary, + upperBoundary, + FailureMechanismSectionAssemblyCategoryGroup.IIv) + }, + n); + + // Assert + Assert.AreEqual(probability, calculator.DetailedAssessmentWithLengthEffectInput.Probability); + Assert.AreEqual(n, calculator.DetailedAssessmentWithLengthEffectInput.NValue); + + FailureMechanismSectionCategory actualSectionCategory = calculator.DetailedAssessmentWithLengthEffectInput.Categories.Single(); + Assert.AreEqual(lowerBoundary, actualSectionCategory.LowerBoundary); + Assert.AreEqual(upperBoundary, actualSectionCategory.UpperBoundary); + Assert.AreEqual(FailureMechanismSectionCategoryGroup.IIv, actualSectionCategory.CategoryGroup); + } + + [Test] + public void AssembleDetailedAssessmentWithLengthEffect_ThrowExceptionOnCalculateTrue_ThrowsFailureMechanismSectionAssemblyCalculatorException() + { + // Setup + var random = new Random(39); + var calculator = new FailureMechanismSectionAssemblyCalculatorStub + { + ThrowExceptionOnCalculate = true + }; + + // Call + TestDelegate test = () => calculator.AssembleDetailedAssessment( + random.NextDouble(), + new[] + { + new FailureMechanismSectionAssemblyCategory(random.NextRoundedDouble(0.0, 0.5), + random.NextRoundedDouble(0.6, 1.0), + random.NextEnumValue()) + }, + random.NextRoundedDouble(1.0, 10.0)); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("Message", exception.Message); + Assert.IsNotNull(exception.InnerException); + } + + #endregion } } \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs =================================================================== diff -u -r65088ddf1c49c4df81c8129a7e0ca158455c4281 -r82a3504384d5138339e41c6f7b5e586451f54661 --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 65088ddf1c49c4df81c8129a7e0ca158455c4281) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.TestUtil/Calculators/Assembly/FailureMechanismSectionAssemblyCalculatorStub.cs (.../FailureMechanismSectionAssemblyCalculatorStub.cs) (revision 82a3504384d5138339e41c6f7b5e586451f54661) @@ -21,8 +21,10 @@ using System; using System.Collections.Generic; +using AssemblyTool.Kernel.Assembly.CalculatorInput; using Ringtoets.AssemblyTool.Data; using Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly; +using Ringtoets.AssemblyTool.KernelWrapper.Creators; using Ringtoets.Common.Primitives; namespace Ringtoets.AssemblyTool.KernelWrapper.TestUtil.Calculators.Assembly @@ -33,23 +35,38 @@ public class FailureMechanismSectionAssemblyCalculatorStub : IFailureMechanismSectionAssemblyCalculator { /// - /// Gets or sets the output of the calculation. + /// Gets the output of the simple assessment calculation. /// public FailureMechanismSectionAssembly SimpleAssessmentAssemblyOutput { get; private set; } /// - /// Gets the input of the calculation. + /// Gets the input of the simple assessment calculation. /// public SimpleAssessmentResultType SimpleAssessmentInput { get; private set; } /// - /// Gets the input of the validity only calculation. + /// Gets the input of the simple assessment validity only calculation. /// public SimpleAssessmentResultValidityOnlyType SimpleAssessmentValidityOnlyInput { get; private set; } /// - /// Indicator whether an exception must be thrown when performing a calculation. + /// Gets or sets the output of the detailed assessment calculation. /// + public FailureMechanismSectionAssembly DetailedAssessmentAssemblyOutput { get; private set; } + + /// + /// Gets the input of the detailed assessment calculation. + /// + public DetailedCalculationInputFromProbability DetailedAssessmentInput { get; private set; } + + /// + /// Gets the input of the detailed assessment with length effect calculation. + /// + public DetailedCalculationInputFromProbabilityWithLengthEffect DetailedAssessmentWithLengthEffectInput { get; private set; } + + /// + /// Gets or sets an indicator whether an exception must be thrown when performing a calculation. + /// public bool ThrowExceptionOnCalculate { private get; set; } public FailureMechanismSectionAssembly AssembleSimpleAssessment(SimpleAssessmentResultType input) @@ -73,20 +90,38 @@ SimpleAssessmentValidityOnlyInput = input; - return SimpleAssessmentAssemblyOutput ?? - (SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(1, FailureMechanismSectionAssemblyCategoryGroup.VIIv)); + return SimpleAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(1, FailureMechanismSectionAssemblyCategoryGroup.VIIv); } public FailureMechanismSectionAssembly AssembleDetailedAssessment(double probability, IEnumerable categories) { - throw new NotImplementedException(); + if (ThrowExceptionOnCalculate) + { + throw new FailureMechanismSectionAssemblyCalculatorException("Message", new Exception()); + } + + DetailedAssessmentInput = FailureMechanismSectionAssemblyCalculatorInputCreator.CreateDetailedCalculationInputFromProbability(probability, + categories); + + return DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(1, FailureMechanismSectionAssemblyCategoryGroup.VIIv); } public FailureMechanismSectionAssembly AssembleDetailedAssessment(double probability, IEnumerable categories, double n) { - throw new NotImplementedException(); + if (ThrowExceptionOnCalculate) + { + throw new FailureMechanismSectionAssemblyCalculatorException("Message", new Exception()); + } + + DetailedAssessmentWithLengthEffectInput = + FailureMechanismSectionAssemblyCalculatorInputCreator.CreateDetailedCalculationInputFromProbabilityWithLengthEffect( + probability, + categories, + n); + + return DetailedAssessmentAssemblyOutput = new FailureMechanismSectionAssembly(0, FailureMechanismSectionAssemblyCategoryGroup.VIIv); } } } \ No newline at end of file