public void AssembleCombinedFailureMechanismSections_KernelThrowsException_ThrowsAssessmentSectionAssemblyCalculatorException() { // Setup var random = new Random(21); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; kernel.ThrowExceptionOnCalculate = 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 <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
public void AssembleCombinedFailureMechanismSections_WithInvalidInput_ThrowsAssessmentSectionAssemblyCalculatorException() { // Setup var random = new Random(21); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; var calculator = new AssessmentSectionAssemblyCalculator(factory); // Call void Call() => calculator.AssembleCombinedFailureMechanismSections(new[] { new[] { new CombinedAssemblyFailureMechanismSection(0, 1, (FailureMechanismSectionAssemblyGroup)99) } }, random.Next()); // Assert var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call); Assert.IsInstanceOf <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
public void AssembleCombinedFailureMechanismSections_KernelWithInvalidOutput_ThrowsAssessmentSectionAssemblyCalculatorException() { // Setup var random = new Random(21); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; CombinedFailureMechanismSectionAssemblyKernelStub kernel = factory.LastCreatedCombinedFailureMechanismSectionAssemblyKernel; kernel.FailureMechanismResult = new FailureMechanismSectionList(new[] { new FailureMechanismSectionWithCategory(0, 1, (EInterpretationCategory)99) }); 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 <InvalidEnumArgumentException>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
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_KernelWithInvalidOutput_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.AssemblyProbability = new Probability(random.NextDouble()); kernel.AssemblyGroup = (EAssessmentGrade)99; var calculator = new AssessmentSectionAssemblyCalculator(factory); // Call void Call() => calculator.AssembleAssessmentSection(Enumerable.Empty <double>(), maximumAllowableFloodingProbability, signalFloodingProbability); // Assert var exception = Assert.Throws <AssessmentSectionAssemblyCalculatorException>(Call); Assert.IsInstanceOf <InvalidEnumArgumentException>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
public void CalculateFailureMechanismSectionAssemblyGroupBoundaries_KernelThrowsException_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.ThrowExceptionOnCalculate = true; var calculator = new FailureMechanismSectionAssemblyGroupBoundariesCalculator(factory); // Call void Call() => calculator.CalculateFailureMechanismSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability); // Assert Assert.IsFalse(categoryLimitsKernel.Calculated); var exception = Assert.Throws <FailureMechanismSectionAssemblyGroupBoundariesCalculatorException>(Call); Assert.IsInstanceOf <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
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); } }
public void Assemble_KernelThrowsException_ThrowsFailureMechanismAssemblyCalculatorException() { // Setup var random = new Random(21); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel; kernel.ThrowExceptionOnCalculate = 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); Assert.IsInstanceOf <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
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 Assemble_WithInvalidInput_ThrowsFailureMechanismAssemblyCalculatorException() { // Setup var random = new Random(21); double probability = random.NextDouble(); var invalidInput = new RiskeerFailureMechanismSectionAssemblyResult(probability, probability, random.NextDouble(), (FailureMechanismSectionAssemblyGroup)99); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; FailureMechanismAssemblyKernelStub kernel = factory.LastCreatedFailureMechanismAssemblyKernel; var calculator = new FailureMechanismAssemblyCalculator(factory); // Call void Call() => calculator.Assemble(random.NextDouble(), new[] { invalidInput }, random.NextBoolean()); // Assert Assert.IsFalse(kernel.Calculated); var exception = Assert.Throws <FailureMechanismAssemblyCalculatorException>(Call); Assert.IsInstanceOf <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
public void CreateGenericErrorMessage_Always_ReturnsExpectedErrorMessage() { // Call string errorMessage = AssemblyErrorMessageCreator.CreateGenericErrorMessage(); // Assert Assert.AreEqual("Er is een onverwachte fout opgetreden tijdens het assembleren.", errorMessage); }
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); } }
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); } }
public void AssembleFailureMechanismSectionWithLengthEffect_KernelThrowsException_ThrowsFailureMechanismSectionAssemblyCalculatorException() { // Setup FailureMechanismSectionWithProfileProbabilityAssemblyInput input = CreateFailureMechanismSectionWithProfileProbabilityAssemblyInput(); using (new AssemblyToolKernelFactoryConfig()) { var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance; FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel; failureMechanismSectionAssemblyKernel.ThrowExceptionOnCalculate = true; var calculator = new FailureMechanismSectionAssemblyCalculator(factory); // Call void Call() => calculator.AssembleFailureMechanismSection(input); // Assert var exception = Assert.Throws <FailureMechanismSectionAssemblyCalculatorException>(Call); Assert.IsInstanceOf <Exception>(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); Assert.IsFalse(failureMechanismSectionAssemblyKernel.Calculated); } }
public void CalculateAssessmentSectionAssemblyGroupBoundaries_KernelThrowsException_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.ThrowExceptionOnCalculate = true; var calculator = new AssessmentSectionAssemblyGroupBoundariesCalculator(factory); // Call void Call() => calculator.CalculateAssessmentSectionAssemblyGroupBoundaries(signalFloodingProbability, maximumAllowableFloodingProbability); // Assert var exception = Assert.Throws <AssessmentSectionAssemblyGroupBoundariesCalculatorException>(Call); Assert.IsNotNull(exception.InnerException); Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message); } }
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); } }