Index: Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs =================================================================== diff -u -r19fd80cc583267703afacd8eb812d170d3282fa0 -r32b6141230e0bab9452aadb77760734ae5f4da9c --- Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs (.../AssemblyCategoriesCalculator.cs) (revision 19fd80cc583267703afacd8eb812d170d3282fa0) +++ Ringtoets/AssemblyTool/src/Ringtoets.AssemblyTool.KernelWrapper/Calculators/Categories/AssemblyCategoriesCalculator.cs (.../AssemblyCategoriesCalculator.cs) (revision 32b6141230e0bab9452aadb77760734ae5f4da9c) @@ -72,7 +72,19 @@ public IEnumerable CalculateFailureMechanismSectionCategories(double signalingNorm, double lowerBoundaryNorm, double probabilityDistributionFactor, double n) { - throw new NotImplementedException(); + try + { + var input = new CalculateFailureMechanismSectionCategoriesInput(new Probability(signalingNorm), new Probability(lowerBoundaryNorm), + probabilityDistributionFactor, n); + ICategoriesCalculator kernel = factory.CreateAssemblyCategoriesKernel(); + CalculationOutput output = kernel.CalculateFailureMechanismSectionCategories(input); + + return AssemblyCategoryCreator.CreateFailureMechanismSectionAssemblyCategories(output); + } + catch (Exception e) + { + throw new AssemblyCategoriesCalculatorException(e.Message, e); + } } } } \ No newline at end of file Index: Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs =================================================================== diff -u -r78a2d68d97b329b4c1309349a564b6a52448accd -r32b6141230e0bab9452aadb77760734ae5f4da9c --- Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs (.../AssemblyCategoriesCalculatorTest.cs) (revision 78a2d68d97b329b4c1309349a564b6a52448accd) +++ Ringtoets/AssemblyTool/test/Ringtoets.AssemblyTool.KernelWrapper.Test/Calculators/Categories/AssemblyCategoriesCalculatorTest.cs (.../AssemblyCategoriesCalculatorTest.cs) (revision 32b6141230e0bab9452aadb77760734ae5f4da9c) @@ -77,7 +77,7 @@ { var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; - kernel.AssessmentSectionCategoriesOutput = CreateKernelOutput(); + kernel.AssessmentSectionCategoriesOutput = CreateAssessmentSectionCategoryKernelOutput(); var calculator = new AssemblyCategoriesCalculator(factory); @@ -97,7 +97,7 @@ var random = new Random(11); double lowerBoundaryNorm = random.NextDouble(); double signalingNorm = random.NextDouble(); - CalculationOutput output = CreateKernelOutput(); + CalculationOutput output = CreateAssessmentSectionCategoryKernelOutput(); using (new AssemblyToolKernelFactoryConfig()) { @@ -142,26 +142,95 @@ } [Test] - public void CalculateFailureMechanismSectionCategories_Always_ThrowsNotImplementedException() + public void CalculateFailureMechanismSectionCategories_WithInput_InputCorrectlySetToKernel() { // Setup + var random = new Random(11); + double lowerBoundaryNorm = random.NextDouble(); + double signalingNorm = random.NextDouble(); + double probabilityDistributionFactor = random.NextDouble(); + double n = random.Next(1, 5); + using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = CreateFailureMechanismSectionCategoryKernelOutput(); + var calculator = new AssemblyCategoriesCalculator(factory); // Call - TestDelegate test = () => calculator.CalculateFailureMechanismSectionCategories(0, 0, 0, 0); + calculator.CalculateFailureMechanismSectionCategories(signalingNorm, lowerBoundaryNorm, probabilityDistributionFactor, n); // Assert - Assert.Throws(test); + Assert.AreEqual(lowerBoundaryNorm, kernel.LowerBoundaryNorm); + Assert.AreEqual(signalingNorm, kernel.SignalingNorm); + Assert.AreEqual(probabilityDistributionFactor, kernel.ProbabilityDistributionFactor); + Assert.AreEqual(n, kernel.N); } } - private static CalculationOutput CreateKernelOutput() + [Test] + public void CalculateFailureMechanismSectionCategories_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator() { + // Setup var random = new Random(11); + double lowerBoundaryNorm = random.NextDouble(); + double signalingNorm = random.NextDouble(); + double probabilityDistributionFactor = random.NextDouble(); + double n = random.Next(1, 5); + CalculationOutput output = CreateFailureMechanismSectionCategoryKernelOutput(); + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.FailureMechanismSectionCategoriesOutput = output; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + IEnumerable result = calculator.CalculateFailureMechanismSectionCategories(signalingNorm, lowerBoundaryNorm, + probabilityDistributionFactor, n); + + // Assert + AssemblyCategoryAssert.AssertFailureMechanismSectionAssemblyCategories(output, result); + } + } + + [Test] + public void CalculateFailureMechanismSectionCategories_KernelThrowsException_ThrowAssemblyCategoriesCalculatorException() + { + // Setup + var random = new Random(11); + double lowerBoundaryNorm = random.NextDouble(); + double signalingNorm = random.NextDouble(); + double probabilityDistributionFactor = random.NextDouble(); + double n = random.NextDouble(); + + using (new AssemblyToolKernelFactoryConfig()) + { + var factory = (TestAssemblyToolKernelFactory) AssemblyToolKernelFactory.Instance; + AssemblyCategoriesKernelStub kernel = factory.LastCreatedAssemblyCategoriesKernel; + kernel.ThrowExceptionOnCalculate = true; + + var calculator = new AssemblyCategoriesCalculator(factory); + + // Call + TestDelegate test = () => calculator.CalculateFailureMechanismSectionCategories(signalingNorm, lowerBoundaryNorm, + probabilityDistributionFactor, n); + + // Assert + var exception = Assert.Throws(test); + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(exception.InnerException.Message, exception.Message); + } + } + + private static CalculationOutput CreateAssessmentSectionCategoryKernelOutput() + { + var random = new Random(11); + return new CalculationOutput(new[] { new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), @@ -170,5 +239,18 @@ new AssessmentSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))) }); } + + private static CalculationOutput CreateFailureMechanismSectionCategoryKernelOutput() + { + var random = new Random(11); + + return new CalculationOutput(new[] + { + new FailureMechanismSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new FailureMechanismSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new FailureMechanismSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))), + new FailureMechanismSectionCategory(random.NextEnumValue(), new Probability(random.Next(1)), new Probability(random.Next(1, 2))) + }); + } } } \ No newline at end of file