public void AssembleCombinedFailureMechanismSections_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
        {
            // Setup
            var random = new Random(21);

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel;
                kernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new AssessmentSectionAssemblyCalculator(factory);

                // Call
                void Call() =>
                calculator.AssembleCombinedFailureMechanismSections(new[]
                {
                    new[]
                    {
                        new CombinedAssemblyFailureMechanismSection(0, 1, random.NextEnumValue <FailureMechanismSectionAssemblyGroup>())
                    }
                }, random.NextDouble());

                // Assert
                var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call);
                Assert.IsInstanceOf <AssemblyException>(exception.InnerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
                {
                    AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.EmptyResultsList)
                }), exception.Message);
            }
        }
Esempio n. 2
0
        public FailureMechanismAssemblyResultWrapper Assemble(double failureMechanismN, IEnumerable <RiskeerFailureMechanismSectionAssemblyResult> sectionAssemblyResults,
                                                              bool applySectionLengthEffect)
        {
            if (sectionAssemblyResults == null)
            {
                throw new ArgumentNullException(nameof(sectionAssemblyResults));
            }

            try
            {
                IFailureMechanismResultAssembler kernel = factory.CreateFailureMechanismAssemblyKernel();

                FailureMechanismAssemblyResult result;
                if (applySectionLengthEffect)
                {
                    result = kernel.CalculateFailureMechanismFailureProbabilityWithLengthEffectBoi1A2(
                        failureMechanismN, sectionAssemblyResults.Select(FailureMechanismAssemblyCalculatorInputCreator.CreateResultWithProfileAndSectionProbabilities),
                        false);
                    return(new FailureMechanismAssemblyResultWrapper(result.Probability, AssemblyMethod.BOI1A2));
                }

                result = kernel.CalculateFailureMechanismFailureProbabilityBoi1A1(
                    failureMechanismN, sectionAssemblyResults.Select(sr => AssemblyCalculatorInputCreator.CreateProbability(sr.SectionProbability)),
                    false);
                return(new FailureMechanismAssemblyResultWrapper(result.Probability, AssemblyMethod.BOI1A1));
            }
            catch (AssemblyException e)
            {
                throw new FailureMechanismAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new FailureMechanismAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }
        public void AssembleAssessmentSection_KernelThrowsAssemblyException_ThrowsAssessmentSectionAssemblyCalculatorException()
        {
            // Setup
            var    random = new Random(21);
            double signalFloodingProbability           = random.NextDouble();
            double maximumAllowableFloodingProbability = signalFloodingProbability + 1e-3;

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssessmentSectionAssemblyKernelStub kernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
                kernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new AssessmentSectionAssemblyCalculator(factory);

                // Call
                void Call() => calculator.AssembleAssessmentSection(Enumerable.Empty <double>(), maximumAllowableFloodingProbability, signalFloodingProbability);

                // Assert
                var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call);
                Assert.IsInstanceOf <AssemblyException>(exception.InnerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
                {
                    AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.InvalidCategoryLimits)
                }), exception.Message);
            }
        }
Esempio n. 4
0
        public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelThrowsAssemblyException_ThrowsAssemblyGroupBoundariesCalculatorException()
        {
            // Setup
            const double maximumAllowableFloodingProbability = 0.001;
            const double signalFloodingProbability           = 0.0001;

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedAssemblyCategoryLimitsKernel;
                categoryLimitsKernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                void Call() => calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                Assert.IsFalse(categoryLimitsKernel.Calculated);

                var exception      = Assert.Throws <FailureMechanismSectionAssemblyGroupBoundariesCalculatorException>(Call);
                var innerException = exception.InnerException as AssemblyException;
                Assert.IsNotNull(innerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(innerException.Errors), exception.Message);
            }
        }
Esempio n. 5
0
        public FailureMechanismSectionAssemblyResultWrapper AssembleFailureMechanismSection(FailureMechanismSectionAssemblyInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            try
            {
                IAssessmentResultsTranslator kernel = factory.CreateFailureMechanismSectionAssemblyKernel();

                if (!IsProbabilityDefined(input))
                {
                    return(AssembleWithUndefinedProbabilities(input, kernel));
                }

                Probability sectionProbability = kernel.DetermineRepresentativeProbabilityBoi0A1(
                    input.FurtherAnalysisType != FailureMechanismSectionResultFurtherAnalysisType.NotNecessary,
                    AssemblyCalculatorInputCreator.CreateProbability(input.InitialSectionProbability),
                    AssemblyCalculatorInputCreator.CreateProbability(input.RefinedSectionProbability));
                EInterpretationCategory interpretationCategory = AssembleInterpretationCategory(input, kernel, sectionProbability);

                return(new FailureMechanismSectionAssemblyResultWrapper(
                           FailureMechanismSectionAssemblyResultCreator.Create(sectionProbability, interpretationCategory),
                           AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1));
            }
            catch (AssemblyException e)
            {
                throw new FailureMechanismSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new FailureMechanismSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }
Esempio n. 6
0
        public void AssembleFailureMechanismSectionWithLengthEffect_KernelThrowsAssemblyException_ThrowsFailureMechanismSectionAssemblyCalculatorException()
        {
            // Setup
            FailureMechanismSectionWithProfileProbabilityAssemblyInput input = CreateFailureMechanismSectionWithProfileProbabilityAssemblyInput();

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
                failureMechanismSectionAssemblyKernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                void Call() => calculator.AssembleFailureMechanismSection(input);

                // Assert
                var exception      = Assert.Throws <FailureMechanismSectionAssemblyCalculatorException>(Call);
                var innerException = exception.InnerException as AssemblyException;
                Assert.IsNotNull(innerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(innerException.Errors), exception.Message);

                Assert.IsFalse(failureMechanismSectionAssemblyKernel.Calculated);
            }
        }
        public void Assemble_KernelThrowsAssemblyException_ThrowsFailureMechanismAssemblyCalculatorException()
        {
            // Setup
            var random = new Random(21);

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel;
                kernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new FailureMechanismAssemblyCalculator(factory);

                // Call
                void Call() => calculator.Assemble(random.NextDouble(), Enumerable.Empty <RiskeerFailureMechanismSectionAssemblyResult>(),
                                                   random.NextBoolean());

                // Assert
                Assert.IsFalse(kernel.Calculated);

                var exception      = Assert.Throws <FailureMechanismAssemblyCalculatorException>(Call);
                var innerException = exception.InnerException as AssemblyException;
                Assert.IsNotNull(innerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(innerException.Errors), exception.Message);
            }
        }
        public void CalculateAssessmentSectionAssemblyGroupBoundaries_KernelThrowsAssemblyException_ThrowAssessmentSectionAssemblyGroupBoundariesCalculatorException()
        {
            // Setup
            var    random = new Random(11);
            double maximumAllowableFloodingProbability = random.NextDouble(0.5, 1.0);
            double signalFloodingProbability           = random.NextDouble(0.0, 0.5);

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub kernel = factory.LastCreatedAssemblyCategoryLimitsKernel;
                kernel.ThrowAssemblyExceptionOnCalculate = true;

                var calculator = new AssessmentSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                void Call() => calculator.CalculateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                var exception = Assert.Throws <AssessmentSectionAssemblyGroupBoundariesCalculatorException>(Call);
                Assert.IsInstanceOf <AssemblyException>(exception.InnerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateErrorMessage(new[]
                {
                    AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.EmptyResultsList)
                }), exception.Message);
            }
        }
        public void CreateErrorMessage_NoAssemblyErrors_ReturnsEmptyErrorMessage()
        {
            // Call
            string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(Enumerable.Empty <AssemblyErrorMessage>());

            // Assert
            Assert.IsEmpty(errorMessage);
        }
        public void CreateErrorMessage_ErrorMessagesNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => AssemblyErrorMessageCreator.CreateErrorMessage(null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("errorMessages", exception.ParamName);
        }
        public void CreateErrorMessage_SingleAssemblyError_ReturnsExpectedErrorMessage(EAssemblyErrors assemblyError, string expectedErrorMessage)
        {
            // Call
            string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(new[]
            {
                AssemblyErrorMessageTestHelper.Create(string.Empty, assemblyError)
            });

            // Assert
            Assert.AreEqual(expectedErrorMessage, errorMessage);
        }
        public void CreateErrorMessage_InvalidAssemblyError_ThrowsInvalidEnumArgumentException()
        {
            // Call
            void Call() => AssemblyErrorMessageCreator.CreateErrorMessage(new[]
            {
                AssemblyErrorMessageTestHelper.Create(string.Empty, (EAssemblyErrors)9999)
            });

            // Assert
            var expectedMessage = $"The value of argument 'assemblyError' (9999) is invalid for Enum type '{nameof(EAssemblyErrors)}'.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage);
        }
        public void CreateErrorMessage_MultipleAssemblyErrors_ReturnsExpectedErrorMessage()
        {
            // Call
            string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(new[]
            {
                AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.LengthEffectFactorOutOfRange),
                AssemblyErrorMessageTestHelper.Create(string.Empty, EAssemblyErrors.FailureProbabilityOutOfRange)
            });

            // Assert
            Assert.AreEqual("- Lengte-effect factor moet minimaal 1 zijn.\n" +
                            "- De gespecificeerde kans moet in het bereik [0,1] liggen.\n", errorMessage);
        }
Esempio n. 14
0
        public AssessmentSectionAssemblyResultWrapper AssembleAssessmentSection(IEnumerable <double> failureMechanismProbabilities,
                                                                                double maximumAllowableFloodingProbability,
                                                                                double signalFloodingProbability)
        {
            if (failureMechanismProbabilities == null)
            {
                throw new ArgumentNullException(nameof(failureMechanismProbabilities));
            }

            try
            {
                ICategoryLimitsCalculator categoryLimitsKernel = factory.CreateAssemblyGroupsKernel();
                CategoriesList <AssessmentSectionCategory> assessmentSectionCategories = categoryLimitsKernel.CalculateAssessmentSectionCategoryLimitsBoi21(
                    new AssessmentSection(AssemblyCalculatorInputCreator.CreateProbability(signalFloodingProbability),
                                          AssemblyCalculatorInputCreator.CreateProbability(maximumAllowableFloodingProbability)));

                IAssessmentGradeAssembler assessmentSectionAssemblyKernel = factory.CreateAssessmentSectionAssemblyKernel();
                IEnumerable <Probability> probabilities = failureMechanismProbabilities.Select(AssemblyCalculatorInputCreator.CreateProbability)
                                                          .ToArray();

                Probability      assemblyProbability = assessmentSectionAssemblyKernel.CalculateAssessmentSectionFailureProbabilityBoi2A1(probabilities, false);
                EAssessmentGrade assemblyCategory    = assessmentSectionAssemblyKernel.DetermineAssessmentGradeBoi2B1(assemblyProbability, assessmentSectionCategories);

                return(new AssessmentSectionAssemblyResultWrapper(
                           new AssessmentSectionAssemblyResult(assemblyProbability,
                                                               AssessmentSectionAssemblyGroupCreator.CreateAssessmentSectionAssemblyGroup(assemblyCategory)),
                           AssemblyMethod.BOI2A1, AssemblyMethod.BOI2B1));
            }
            catch (AssemblyException e)
            {
                throw new AssessmentSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new AssessmentSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }
Esempio n. 15
0
        public CombinedFailureMechanismSectionAssemblyResultWrapper AssembleCombinedFailureMechanismSections(
            IEnumerable <IEnumerable <CombinedAssemblyFailureMechanismSection> > input, double assessmentSectionLength)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            try
            {
                ICommonFailureMechanismSectionAssembler kernel = factory.CreateCombinedFailureMechanismSectionAssemblyKernel();

                IEnumerable <FailureMechanismSectionList> failureMechanismSections = FailureMechanismSectionListCreator.Create(input);
                FailureMechanismSectionList commonSections = kernel.FindGreatestCommonDenominatorSectionsBoi3A1(
                    failureMechanismSections, assessmentSectionLength);

                FailureMechanismSectionList[] failureMechanismResults = failureMechanismSections.Select(fmsl => kernel.TranslateFailureMechanismResultsToCommonSectionsBoi3B1(
                                                                                                            fmsl, commonSections))
                                                                        .ToArray();

                IEnumerable <FailureMechanismSectionWithCategory> combinedSectionResults =
                    kernel.DetermineCombinedResultPerCommonSectionBoi3C1(failureMechanismResults, false);

                return(new CombinedFailureMechanismSectionAssemblyResultWrapper(
                           CombinedFailureMechanismSectionAssemblyCreator.Create(failureMechanismResults, combinedSectionResults),
                           AssemblyMethod.BOI3A1, AssemblyMethod.BOI3B1, AssemblyMethod.BOI3C1));
            }
            catch (AssemblyException e)
            {
                throw new AssessmentSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new AssessmentSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }
Esempio n. 16
0
        public IEnumerable <AssessmentSectionAssemblyGroupBoundaries> CalculateAssessmentSectionAssemblyGroupBoundaries(double signalFloodingProbability, double maximumAllowableFloodingProbability)
        {
            try
            {
                ICategoryLimitsCalculator kernel = factory.CreateAssemblyGroupsKernel();
                CategoriesList <AssessmentSectionCategory> assessmentSectionCategories = kernel.CalculateAssessmentSectionCategoryLimitsBoi21(
                    new AssessmentSection(AssemblyCalculatorInputCreator.CreateProbability(signalFloodingProbability),
                                          AssemblyCalculatorInputCreator.CreateProbability(maximumAllowableFloodingProbability)));

                return(AssessmentSectionAssemblyGroupCreator.CreateAssessmentSectionAssemblyGroupBoundaries(assessmentSectionCategories));
            }
            catch (AssemblyException e)
            {
                throw new AssessmentSectionAssemblyGroupBoundariesCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new AssessmentSectionAssemblyGroupBoundariesCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }