public void AssembleSectionAdoptableWithProfileProbability_WithInputAndUseLengthEffectTrueAndVariousProbabilityRefinementType_SetsInputOnCalculator( ProbabilityRefinementType probabilityRefinementType, double sectionN) { // Setup var random = new Random(21); double refinedSectionProbability = random.NextDouble(); double refinedProfileProbability = random.NextDouble(); var mocks = new MockRepository(); var calculateStrategy = mocks.Stub <IFailureMechanismSectionResultCalculateProbabilityStrategy>(); mocks.ReplayAll(); var assessmentSection = new AssessmentSectionStub(); var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()) { ProbabilityRefinementType = probabilityRefinementType, RefinedProfileProbability = refinedProfileProbability, RefinedSectionProbability = refinedSectionProbability }; using (new AssemblyToolCalculatorFactoryConfig()) { var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance; FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator; // Call FailureMechanismSectionAssemblyResultFactory.AssembleSection( sectionResult, assessmentSection, calculateStrategy, true, sectionN); // Assert FailureMechanismSectionWithProfileProbabilityAssemblyInput calculatorInput = calculator.FailureMechanismSectionWithProfileProbabilityAssemblyInput; switch (probabilityRefinementType) { case ProbabilityRefinementType.Profile: Assert.AreEqual(refinedProfileProbability, calculatorInput.RefinedProfileProbability); Assert.AreEqual(Math.Min(1.0, refinedProfileProbability * sectionN), calculatorInput.RefinedSectionProbability); break; case ProbabilityRefinementType.Section: Assert.AreEqual(refinedSectionProbability / sectionN, calculatorInput.RefinedProfileProbability); Assert.AreEqual(refinedSectionProbability, calculatorInput.RefinedSectionProbability); break; case ProbabilityRefinementType.Both: Assert.AreEqual(refinedProfileProbability, calculatorInput.RefinedProfileProbability); Assert.AreEqual(refinedSectionProbability, calculatorInput.RefinedSectionProbability); break; } } }
private static FailureMechanismSectionWithProfileProbabilityAssemblyInput CreateInput( IAssessmentSection assessmentSection, bool isRelevant, AdoptableInitialFailureMechanismResultType initialFailureMechanismResultType, double initialProfileProbability, double initialSectionProbability, FailureMechanismSectionResultFurtherAnalysisType furtherAnalysisType, double refinedProfileProbability, double refinedSectionProbability, ProbabilityRefinementType probabilityRefinementType, double sectionN) { if (probabilityRefinementType == ProbabilityRefinementType.Profile) { refinedSectionProbability = Math.Min(1.0, refinedProfileProbability * sectionN); } if (probabilityRefinementType == ProbabilityRefinementType.Section) { refinedProfileProbability = refinedSectionProbability / sectionN; } bool hasProbabilitySpecified = initialFailureMechanismResultType != AdoptableInitialFailureMechanismResultType.NoFailureProbability; return(CreateInput(assessmentSection, isRelevant, hasProbabilitySpecified, initialProfileProbability, initialSectionProbability, furtherAnalysisType, refinedProfileProbability, refinedSectionProbability)); }