public void DetailedAssessmentDirectFailureMechanismsFromProbabilitySelectsCorrectCategory(double probability, FailureMechanismSectionCategoryGroup expectedCategoryGroup, double expectedProbability) { var categories = new[] { new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.Iv, (Probability)0, (Probability)0.1), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.IIv, (Probability)0.1, (Probability)0.2), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.IIIv, (Probability)0.2, (Probability)0.3), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.IVv, (Probability)0.3, (Probability)0.4), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.Vv, (Probability)0.4, (Probability)0.5), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.VIv, (Probability)0.5, (Probability)1), }; var input = new DetailedCalculationInputFromProbability((Probability)probability, categories); var calculationOutput = new FailureMechanismSectionAssemblyCalculator().DetailedAssessmentDirectFailureMechanisms(input); Assert.IsNotNull(calculationOutput); Assert.IsEmpty(calculationOutput.WarningMessages); Assert.IsNotNull(calculationOutput.Result); Assert.AreEqual(expectedCategoryGroup, calculationOutput.Result.CategoryGroup); Assert.AreEqual(expectedProbability, calculationOutput.Result.EstimatedProbabilityOfFailure); }
public void DetailedAssessmentDirectFailureMechanismsFromProbabilityThrowsOnNonMatchingCategories() { var categories = new[] { new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.IVv, (Probability)0.3, (Probability)0.4), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.Vv, (Probability)0.4, (Probability)0.5), new FailureMechanismSectionCategory(FailureMechanismSectionCategoryGroup.VIv, (Probability)0.5, (Probability)1), }; var input = new DetailedCalculationInputFromProbability((Probability)0.1549874856, categories); try { new FailureMechanismSectionAssemblyCalculator().DetailedAssessmentDirectFailureMechanisms(input); Assert.Fail("Expected exception"); } catch (AssemblyToolKernelException e) { Assert.AreEqual(1, e.Code.Length); Assert.AreEqual(ErrorCode.NoMatchingCategory, e.Code[0]); } }
public CalculationOutput <FailureMechanismSectionAssemblyCategoryResult> DetailedAssessmentDirectFailureMechanisms(DetailedCalculationInputFromProbability input) { if (input == null) { throw new AssemblyToolKernelException(ErrorCode.InputIsNull); } if (double.IsNaN(input.Probability)) { return(new CalculationOutput <FailureMechanismSectionAssemblyCategoryResult>(new FailureMechanismSectionAssemblyCategoryResult(FailureMechanismSectionCategoryGroup.None, Probability.NaN))); } var resultCategory = input.Categories.FirstOrDefault(c => c.LowerBoundary <= input.Probability && c.UpperBoundary >= input.Probability); if (resultCategory == null) { throw new AssemblyToolKernelException(ErrorCode.NoMatchingCategory); } return(new CalculationOutput <FailureMechanismSectionAssemblyCategoryResult>(new FailureMechanismSectionAssemblyCategoryResult(resultCategory.CategoryGroup, input.Probability))); }