Beispiel #1
0
        public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelWithCompleteOutput_ReturnsExpectedFailureMechanismSectionAssembly()
        {
            // Setup
            const double maximumAllowableFloodingProbability = 0.001;
            const double signalFloodingProbability           = 0.0001;

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub        categoryLimitsKernel     = factory.LastCreatedAssemblyCategoryLimitsKernel;
                CategoriesList <InterpretationCategory> interpretationCategories = CreateInterpretationCategories();
                categoryLimitsKernel.InterpretationCategoryLimits = interpretationCategories;

                var calculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                IEnumerable <FailureMechanismSectionAssemblyGroupBoundaries> result =
                    calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

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

                FailureMechanismSectionAssemblyGroupBoundariesAssert.AssertFailureMechanismSectionAssemblyGroupBoundaries(interpretationCategories, result);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public void AssembleFailureMechanismSection_WithValidInputAndProbabilityDefined_InputCorrectlySentToKernel(
            FailureMechanismSectionAssemblyInput input)
        {
            // Setup
            var random = new Random(21);

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub        categoryLimitsKernel     = factory.LastCreatedAssemblyCategoryLimitsKernel;
                CategoriesList <InterpretationCategory> interpretationCategories = CreateInterpretationCategories();
                categoryLimitsKernel.InterpretationCategoryLimits = interpretationCategories;

                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
                var sectionProbability = new Probability(random.NextDouble(0.0, 0.01));
                failureMechanismSectionAssemblyKernel.SectionProbability = sectionProbability;
                failureMechanismSectionAssemblyKernel.CategoryOutput     = EInterpretationCategory.Zero;

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                calculator.AssembleFailureMechanismSection(input);

                // Assert
                AssessmentSection assessmentSection = categoryLimitsKernel.AssessmentSection;
                ProbabilityAssert.AreEqual(input.MaximumAllowableFloodingProbability, assessmentSection.MaximumAllowableFloodingProbability);
                ProbabilityAssert.AreEqual(input.SignalFloodingProbability, assessmentSection.SignalFloodingProbability);

                Assert.AreSame(interpretationCategories, failureMechanismSectionAssemblyKernel.Categories);
                Assert.AreEqual(input.FurtherAnalysisType != FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, failureMechanismSectionAssemblyKernel.RefinementNecessary);
                Assert.AreEqual(input.InitialSectionProbability, failureMechanismSectionAssemblyKernel.ProbabilityInitialMechanismSection);
                Assert.AreEqual(input.RefinedSectionProbability, failureMechanismSectionAssemblyKernel.RefinedProbabilitySection);
                Assert.AreEqual(sectionProbability, failureMechanismSectionAssemblyKernel.SectionProbabilityInput);
            }
        }
Beispiel #4
0
        public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelWithInCompleteOutput_ThrowsAssemblyGroupBoundariesCalculatorException()
        {
            // Setup
            const double maximumAllowableFloodingProbability = 0.001;
            const double signalFloodingProbability           = 0.0001;

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedAssemblyCategoryLimitsKernel;
                var interpretationCategories = new CategoriesList <InterpretationCategory>(new[]
                {
                    new InterpretationCategory((EInterpretationCategory)99, new Probability(0), new Probability(1))
                });
                categoryLimitsKernel.InterpretationCategoryLimits = interpretationCategories;

                var calculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculator(factory);

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

                // Assert
                var exception = Assert.Throws <FailureMechanismSectionAssemblyGroupBoundariesCalculatorException>(Call);
                Assert.IsInstanceOf <Exception>(exception.InnerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);

                Assert.IsTrue(categoryLimitsKernel.Calculated);
            }
        }
        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);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Creates a new instance of <see cref="TestAssemblyToolKernelFactory"/>.
 /// </summary>
 public TestAssemblyToolKernelFactory()
 {
     LastCreatedAssemblyCategoryLimitsKernel                  = new AssemblyCategoryLimitsKernelStub();
     LastCreatedFailureMechanismSectionAssemblyKernel         = new FailureMechanismSectionAssemblyKernelStub();
     LastCreatedFailureMechanismAssemblyKernel                = new FailureMechanismAssemblyKernelStub();
     LastCreatedCombinedFailureMechanismSectionAssemblyKernel = new CombinedFailureMechanismSectionAssemblyKernelStub();
     LastCreatedAssessmentSectionAssemblyKernel               = new AssessmentSectionAssemblyKernelStub();
 }
        public void AssembleAssessmentSection_WithValidInput_InputCorrectlySetToKernel()
        {
            // Setup
            var    random = new Random(21);
            double signalFloodingProbability           = random.NextDouble();
            double maximumAllowableFloodingProbability = signalFloodingProbability + 1e-3;

            int nrOfProbabilities = random.Next(1, 10);
            IEnumerable <double> failureMechanismProbabilities = Enumerable.Repeat(random.NextDouble(), nrOfProbabilities)
                                                                 .ToArray();

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;

                var assessmentSectionCategories = new CategoriesList <AssessmentSectionCategory>(new[]
                {
                    new AssessmentSectionCategory(random.NextEnumValue <EAssessmentGrade>(), new Probability(0), new Probability(1))
                });
                AssemblyCategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedAssemblyCategoryLimitsKernel;
                categoryLimitsKernel.AssessmentSectionCategoryLimits = assessmentSectionCategories;

                AssessmentSectionAssemblyKernelStub assessmentSectionAssemblyKernel = factory.LastCreatedAssessmentSectionAssemblyKernel;
                var assemblyProbability = new Probability(random.NextDouble());
                assessmentSectionAssemblyKernel.AssemblyProbability = assemblyProbability;
                assessmentSectionAssemblyKernel.AssemblyGroup       = random.NextEnumValue <EAssessmentGrade>();

                var calculator = new AssessmentSectionAssemblyCalculator(factory);

                // Call
                calculator.AssembleAssessmentSection(failureMechanismProbabilities, maximumAllowableFloodingProbability, signalFloodingProbability);

                // Assert
                Assert.IsTrue(categoryLimitsKernel.Calculated);
                ProbabilityAssert.AreEqual(maximumAllowableFloodingProbability, categoryLimitsKernel.AssessmentSection.MaximumAllowableFloodingProbability);
                ProbabilityAssert.AreEqual(signalFloodingProbability, categoryLimitsKernel.AssessmentSection.SignalFloodingProbability);

                Assert.IsTrue(assessmentSectionAssemblyKernel.ProbabilityCalculated);
                Assert.IsTrue(assessmentSectionAssemblyKernel.AssemblyGroupCalculated);
                Assert.IsFalse(assessmentSectionAssemblyKernel.PartialAssembly);
                Assert.AreSame(assessmentSectionCategories, assessmentSectionAssemblyKernel.Categories);

                IEnumerable <Probability> actualProbabilitiesInput = assessmentSectionAssemblyKernel.FailureMechanismProbabilities;
                Assert.AreEqual(nrOfProbabilities, actualProbabilitiesInput.Count());
                for (var i = 0; i < nrOfProbabilities; i++)
                {
                    ProbabilityAssert.AreEqual(failureMechanismProbabilities.ElementAt(i),
                                               actualProbabilitiesInput.ElementAt(i));
                }

                Assert.AreEqual(assemblyProbability, assessmentSectionAssemblyKernel.AssemblyProbabilityInput);
            }
        }
Beispiel #8
0
        public void AssembleFailureMechanismSectionWithLengthEffect_InputWithProbabilityDefinedKernelWithCompleteOutput_ReturnsExpectedFailureMechanismSectionAssembly()
        {
            // Setup
            var random = new Random(21);
            var input  = new FailureMechanismSectionWithProfileProbabilityAssemblyInput(
                0.001, 0.0001, true, true, random.NextDouble(), random.NextDouble(),
                FailureMechanismSectionResultFurtherAnalysisType.Executed,
                random.NextDouble(), random.NextDouble());

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

                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
                var categoryOutput = random.NextEnumValue <EInterpretationCategory>();

                var kernelResult = new ResultWithProfileAndSectionProbabilities(
                    new Probability(random.NextDouble(0.0001, 0.001)),
                    new Probability(random.NextDouble(0.001, 0.01)));
                failureMechanismSectionAssemblyKernel.ProfileAndSectionProbabilities = kernelResult;
                failureMechanismSectionAssemblyKernel.CategoryOutput = categoryOutput;

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                FailureMechanismSectionAssemblyResultWrapper resultWrapper = calculator.AssembleFailureMechanismSection(input);

                // Assert
                Assert.IsTrue(categoryLimitsKernel.Calculated);
                Assert.IsTrue(failureMechanismSectionAssemblyKernel.Calculated);

                FailureMechanismSectionAssemblyResult result = resultWrapper.AssemblyResult;
                Assert.AreEqual((double)kernelResult.ProbabilityProfile, result.ProfileProbability);
                Assert.AreEqual((double)kernelResult.ProbabilitySection, result.SectionProbability);
                Assert.AreEqual(kernelResult.LengthEffectFactor, result.N);
                Assert.AreEqual(FailureMechanismSectionAssemblyGroupConverter.ConvertTo(categoryOutput),
                                result.FailureMechanismSectionAssemblyGroup);
                Assert.AreEqual(AssemblyMethod.BOI0A2, resultWrapper.ProbabilityMethod);
                Assert.AreEqual(AssemblyMethod.BOI0B1, resultWrapper.AssemblyGroupMethod);
            }
        }
Beispiel #9
0
        public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_WithValidInput_InputCorrectlySentToKernel()
        {
            // Setup
            const double maximumAllowableFloodingProbability = 0.001;
            const double signalFloodingProbability           = 0.0001;

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

                var calculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                AssessmentSection assessmentSection = categoryLimitsKernel.AssessmentSection;
                ProbabilityAssert.AreEqual(maximumAllowableFloodingProbability, assessmentSection.MaximumAllowableFloodingProbability);
                ProbabilityAssert.AreEqual(signalFloodingProbability, assessmentSection.SignalFloodingProbability);
            }
        }
        public void CalculateAssessmentSectionAssemblyGroupBoundaries_KernelWithCompleteOutput_OutputCorrectlyReturnedByCalculator()
        {
            // Setup
            var    random = new Random(11);
            double maximumAllowableFloodingProbability = random.NextDouble(0.5, 1.0);
            double signalFloodingProbability           = random.NextDouble(0.0, 0.5);
            CategoriesList <AssessmentSectionCategory> assessmentSectionCategories = CreateAssessmentSectionCategories();

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

                var calculator = new AssessmentSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                IEnumerable <AssessmentSectionAssemblyGroupBoundaries> result = calculator.CalculateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                AssessmentSectionAssemblyGroupBoundariesAssert.AssertAssessmentSectionAssemblyGroupBoundaries(assessmentSectionCategories, result);
            }
        }
        public void CalculateAssessmentSectionAssemblyGroupBoundaries_WithInput_InputCorrectlySetToKernel()
        {
            // 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.AssessmentSectionCategoryLimits = CreateAssessmentSectionCategories();

                var calculator = new AssessmentSectionAssemblyGroupBoundariesCalculator(factory);

                // Call
                calculator.CalculateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability);

                // Assert
                Assert.AreEqual(maximumAllowableFloodingProbability, kernel.AssessmentSection.MaximumAllowableFloodingProbability);
                Assert.AreEqual(signalFloodingProbability, kernel.AssessmentSection.SignalFloodingProbability);
            }
        }