public void CalculateProfileProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            var calculationScenario1 = ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var calculationScenario2 = ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var calculationScenario3 = ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);

            calculationScenario1.IsRelevant   = true;
            calculationScenario1.Contribution = (RoundedDouble)0.2111;

            calculationScenario2.IsRelevant   = true;
            calculationScenario2.Contribution = (RoundedDouble)0.7889;

            calculationScenario3.IsRelevant = false;

            ProbabilisticPipingCalculationScenario[] calculations =
            {
                calculationScenario1,
                calculationScenario2,
                calculationScenario3
            };

            var strategy = new ProbabilisticPipingFailureMechanismSectionResultCalculateProbabilityStrategy(sectionResult, calculations);

            // Call
            double profileProbability = strategy.CalculateProfileProbability();

            // Assert
            Assert.AreEqual(0.24284668249632746, profileProbability);
        }
        public void ProbabilisticGetInitialFailureMechanismResultProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            var pipingCalculationScenario1 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenario2 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenario3 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);

            pipingCalculationScenario1.IsRelevant   = true;
            pipingCalculationScenario1.Contribution = (RoundedDouble)0.2111;

            pipingCalculationScenario2.IsRelevant   = true;
            pipingCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            pipingCalculationScenario3.IsRelevant = false;

            ProbabilisticPipingCalculationScenario[] calculations =
            {
                pipingCalculationScenario1,
                pipingCalculationScenario2,
                pipingCalculationScenario3
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(
                calculations, scenario => scenario.Output.ProfileSpecificOutput);

            // Assert
            Assert.AreEqual(0.24284668249632746, initialFailureMechanismResultProbability);
        }
        public void ProbabilisticGetInitialFailureMechanismResultProbability_ScenarioWithNaNResults_ReturnsNaN()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double contribution1 = 0.2;
            const double contribution2 = 0.8;

            var pipingCalculationScenario1 =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenario2 =
                ProbabilisticPipingCalculationTestFactory.CreateNotCalculatedCalculation <ProbabilisticPipingCalculationScenario>(section);

            pipingCalculationScenario1.IsRelevant   = true;
            pipingCalculationScenario1.Contribution = (RoundedDouble)contribution1;

            pipingCalculationScenario2.IsRelevant   = true;
            pipingCalculationScenario2.Contribution = (RoundedDouble)contribution2;
            pipingCalculationScenario2.Output       = new ProbabilisticPipingOutput(new TestPartialProbabilisticPipingOutput(double.NaN, null),
                                                                                    new TestPartialProbabilisticPipingOutput(double.NaN, null));

            ProbabilisticPipingCalculationScenario[] calculations =
            {
                pipingCalculationScenario1,
                pipingCalculationScenario2
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(
                calculations, scenario => scenario.Output.ProfileSpecificOutput);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }
        public void FailureMechanismResultsView_AllDataSet_DataGridViewCorrectlyInitialized(
            PipingScenarioConfigurationType scenarioConfigurationType,
            PipingScenarioConfigurationPerFailureMechanismSectionType scenarioConfigurationPerFailureMechanismSectionType,
            string probability)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection("Section 1");

            var failureMechanism = new PipingFailureMechanism
            {
                ScenarioConfigurationType = scenarioConfigurationType
            };

            FailureMechanismTestHelper.SetSections(failureMechanism, new[]
            {
                section
            });

            failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().ScenarioConfigurationType = scenarioConfigurationPerFailureMechanismSectionType;

            failureMechanism.CalculationsGroup.Children.Add(
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section));
            failureMechanism.CalculationsGroup.Children.Add(
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section));

            // Call
            using (new AssemblyToolCalculatorFactoryConfig())
                using (ShowFailureMechanismResultsView(failureMechanism))
                {
                    DataGridView dataGridView = GetDataGridView();

                    // Assert
                    DataGridViewRowCollection rows = dataGridView.Rows;
                    Assert.AreEqual(1, rows.Count);

                    DataGridViewCellCollection cells = rows[0].Cells;
                    Assert.AreEqual(columnCount, cells.Count);
                    Assert.AreEqual("Section 1", cells[nameColumnIndex].FormattedValue);
                    Assert.AreEqual(true, cells[isRelevantIndex].Value);
                    Assert.AreEqual(AdoptableInitialFailureMechanismResultType.Adopt, cells[initialFailureMechanismResultTypeIndex].Value);
                    Assert.AreEqual(probability, cells[initialFailureMechanismResultProfileProbabilityIndex].FormattedValue);
                    Assert.AreEqual(probability, cells[initialFailureMechanismResultSectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual(FailureMechanismSectionResultFurtherAnalysisType.NotNecessary, cells[furtherAnalysisTypeIndex].Value);
                    Assert.AreEqual(ProbabilityRefinementType.Section, cells[probabilityRefinementTypeIndex].Value);
                    Assert.AreEqual("<afgeleid>", cells[refinedProfileProbabilityIndex].FormattedValue);
                    Assert.AreEqual("-", cells[refinedSectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("1/100", cells[profileProbabilityIndex].FormattedValue);
                    Assert.AreEqual("1/10", cells[sectionProbabilityIndex].FormattedValue);
                    Assert.AreEqual("10,00", cells[sectionNIndex].FormattedValue);
                    Assert.AreEqual("+I", cells[assemblyGroupIndex].FormattedValue);
                }
        }
        public void ProbabilisticGetInitialFailureMechanismResultProbability_RelevantScenarioContributionsDoNotAddUpTo1_ReturnNaN(double contributionA, double contributionB)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var pipingCalculationScenarioA  =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenarioB =
                ProbabilisticPipingCalculationTestFactory.CreateCalculation <ProbabilisticPipingCalculationScenario>(section);

            pipingCalculationScenarioA.Contribution = (RoundedDouble)contributionA;
            pipingCalculationScenarioB.Contribution = (RoundedDouble)contributionB;

            var result = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            // Call
            double initialFailureMechanismResultProbability = result.GetInitialFailureMechanismResultProbability(new[]
            {
                pipingCalculationScenarioA,
                pipingCalculationScenarioB
            }, scenario => null);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }