Ejemplo n.º 1
0
        public void ScenarioConfigurationTypeIsSemiProbabilistic_VariousConfigurations_ReturnsExpectedResult(
            PipingFailureMechanism failureMechanism, PipingScenarioConfigurationPerFailureMechanismSectionType configurationType,
            bool expectedResult)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

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

            PipingScenarioConfigurationPerFailureMechanismSection scenarioConfigurationPerFailureMechanismSection =
                failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.Single();

            scenarioConfigurationPerFailureMechanismSection.ScenarioConfigurationType = configurationType;

            // Call
            bool isSemiProbabilistic = failureMechanism.ScenarioConfigurationTypeIsSemiProbabilistic(scenarioConfigurationPerFailureMechanismSection);

            // Assert
            Assert.AreEqual(expectedResult, isSemiProbabilistic);
        }
Ejemplo n.º 2
0
        public void Constructor_ConstructionPropertiesNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider>();

            mocks.ReplayAll();

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new AdoptableFailureMechanismSectionResult(section);

            // Call
            void Call() => new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider,
                                                                         performAssemblyFunc, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("constructionProperties", exception.ParamName);
            mocks.VerifyAll();
        }
Ejemplo n.º 3
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var random           = new Random(21);
            var failureMechanism = new TestCalculatableFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, string.Empty);

            var assemblyResult = new FailureMechanismSectionAssemblyResult(
                random.NextDouble(), random.NextDouble(), random.NextDouble(),
                random.NextEnumValue <FailureMechanismSectionAssemblyGroup>());

            // Call
            using (var mapLayer = new CalculatableFailureMechanismSectionResultsMapLayer <TestCalculatableFailureMechanism, TestFailureMechanismSectionResult, TestCalculationInput>(
                       failureMechanism, result => assemblyResult))
            {
                // Assert
                Assert.IsInstanceOf <NonCalculatableFailureMechanismSectionResultsMapLayer <TestFailureMechanismSectionResult> >(mapLayer);
            }
        }
Ejemplo n.º 4
0
        public void GivenRowWithFurtherAnalysisNotExecuted_WhenErrorProviderReturnsError_ThenShowsNoError(FailureMechanismSectionResultFurtherAnalysisType furtherAnalysisType)
        {
            // Given
            var    random             = new Random(21);
            double profileProbability = random.NextDouble();
            double sectionProbability = profileProbability + 0.1;

            var mocks         = new MockRepository();
            var errorProvider = mocks.StrictMock <IFailureMechanismSectionResultRowErrorProvider>();

            errorProvider.Stub(ep => ep.GetManualProbabilityValidationError(double.NaN))
            .IgnoreArguments()
            .Return("error");
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(section)
            {
                InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability,
                FurtherAnalysisType       = furtherAnalysisType,
                RefinedProfileProbability = profileProbability,
                RefinedSectionProbability = sectionProbability
            };

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            // When
            var row = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResultRow(result, errorProvider, performAssemblyFunc, ConstructionProperties);

            // Then
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            Assert.IsEmpty(columnStateDefinitions[ConstructionProperties.RefinedProfileProbabilityIndex].ErrorText);
            Assert.IsEmpty(columnStateDefinitions[ConstructionProperties.RefinedSectionProbabilityIndex].ErrorText);

            mocks.VerifyAll();
        }
Ejemplo n.º 5
0
        public void UpdateSectionsWithImportedData_WithEmptyData_ClearsSectionsAndUpdatesPathAndReturnsAffectedObjects()
        {
            // Setup
            const string oldSourcePath = "old/path";
            string       sourcePath    = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();

            failureMechanism.SetSections(new[]
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            }, oldSourcePath);

            var sectionResultUpdateStrategy           = new TestUpdateFailureMechanismSectionResultUpdateStrategy();
            var failureMechanismSectionUpdateStrategy = new FailureMechanismSectionUpdateStrategy <FailureMechanismSectionResult>(
                failureMechanism, sectionResultUpdateStrategy);

            // Precondition
            IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections;

            Assert.AreEqual(1, failureMechanismSections.Count());
            Assert.AreEqual(oldSourcePath, failureMechanism.FailureMechanismSectionSourcePath);

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(
                Enumerable.Empty <FailureMechanismSection>(), sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);
            Assert.IsEmpty(failureMechanismSections);
            Assert.IsFalse(sectionResultUpdateStrategy.Update);
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }
Ejemplo n.º 6
0
        public void GivenScenarioRow_WhenOutputChangedAndUpdate_ThenDerivedOutputUpdated()
        {
            // Given
            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput()
            };
            var failureMechanism = new MacroStabilityInwardsFailureMechanism();
            FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection);

            // Precondition
            DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor);

            Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability);
            Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(
                                failureMechanismSection.Length),
                            row.SectionFailureProbability);

            var random = new Random(11);

            // When
            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties
            {
                FactorOfStability = random.NextDouble()
            });
            row.Update();

            // Then
            DerivedMacroStabilityInwardsOutput newExpectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor);

            Assert.AreEqual(newExpectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability);
            Assert.AreEqual(newExpectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(
                                failureMechanismSection.Length),
                            row.SectionFailureProbability);
        }
Ejemplo n.º 7
0
        public void GetRelevantCalculationScenarios_WithoutScenarioIntersectingSection_ReturnsNoCalculationScenarios()
        {
            // Setup
            var mocks = new MockRepository();
            var calculationScenarioStub1 = mocks.Stub <ICalculationScenario>();
            var calculationScenarioStub2 = mocks.Stub <ICalculationScenario>();

            mocks.ReplayAll();

            calculationScenarioStub1.IsRelevant = true;
            calculationScenarioStub2.IsRelevant = false;

            var calculationScenario1 = new TestCalculationScenario();
            var calculationScenario2 = new TestCalculationScenario
            {
                IsRelevant = false
            };

            ICalculationScenario[] calculationScenarios =
            {
                calculationScenarioStub1,
                calculationScenarioStub2,
                calculationScenario1,
                calculationScenario2
            };

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new TestFailureMechanismSectionResult(section);

            // Call
            IEnumerable <ICalculationScenario> relevantScenarios = sectionResult.GetRelevantCalculationScenarios <TestCalculationScenario>(
                calculationScenarios, (scenario, segments) => false);

            // Assert
            CollectionAssert.IsEmpty(relevantScenarios);
            mocks.VerifyAll();
        }
Ejemplo n.º 8
0
        public void GetRelevantCalculationScenarios_WithRelevantAndIrrelevantScenariosOfDifferentTypes_ReturnsRelevantCalculationScenarios()
        {
            // Setup
            var mocks = new MockRepository();
            var calculationScenarioStub1 = mocks.Stub <ICalculationScenario>();
            var calculationScenarioStub2 = mocks.Stub <ICalculationScenario>();

            mocks.ReplayAll();

            calculationScenarioStub1.IsRelevant = true;
            calculationScenarioStub2.IsRelevant = false;

            var calculationScenario1 = new TestCalculationScenario();
            var calculationScenario2 = new TestCalculationScenario
            {
                IsRelevant = false
            };

            ICalculationScenario[] calculationScenarios =
            {
                calculationScenarioStub1,
                calculationScenarioStub2,
                calculationScenario1,
                calculationScenario2
            };

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new TestFailureMechanismSectionResult(section);

            // Call
            IEnumerable <ICalculationScenario> relevantScenarios = sectionResult.GetRelevantCalculationScenarios <TestCalculationScenario>(
                calculationScenarios, (scenario, segments) => true);

            // Assert
            Assert.AreEqual(calculationScenario1, relevantScenarios.Single());
            mocks.VerifyAll();
        }
Ejemplo n.º 9
0
        public void GivenRowWithFurtherAnalysisTypeExecuted_WhenErrorProviderReturnsError_ThenShowsError()
        {
            // Given
            var    random             = new Random(21);
            double sectionProbability = random.NextDouble();

            const string errorText     = "error";
            var          mocks         = new MockRepository();
            var          errorProvider = mocks.StrictMock <IFailureMechanismSectionResultRowWithCalculatedProbabilityErrorProvider>();

            errorProvider.Stub(ep => ep.GetCalculatedProbabilityValidationError(null))
            .IgnoreArguments()
            .Return(string.Empty);
            errorProvider.Expect(ep => ep.GetManualProbabilityValidationError(sectionProbability))
            .Return(errorText);
            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new AdoptableFailureMechanismSectionResult(section)
            {
                FurtherAnalysisType       = FailureMechanismSectionResultFurtherAnalysisType.Executed,
                RefinedSectionProbability = sectionProbability
            };

            Func <FailureMechanismSectionAssemblyResultWrapper> performAssemblyFunc = FailureMechanismSectionAssemblyResultWrapperTestFactory.Create;

            // When
            var row = new AdoptableFailureMechanismSectionResultRow(result, () => double.NaN, errorProvider,
                                                                    performAssemblyFunc, ConstructionProperties);

            // Then
            IDictionary <int, DataGridViewColumnStateDefinition> columnStateDefinitions = row.ColumnStateDefinitions;

            Assert.AreEqual(errorText, columnStateDefinitions[ConstructionProperties.RefinedSectionProbabilityIndex].ErrorText);

            mocks.VerifyAll();
        }
Ejemplo n.º 10
0
        public void GivenFailureMechanismWithSections_WhenUpdateSectionsWithImportedData_ThenDataUpdatedAndReturnsAffectedObjects()
        {
            // Given
            var failureMechanism = new PipingFailureMechanism();
            var failureMechanismSectionUpdateStrategy = new PipingFailureMechanismSectionUpdateStrategy(
                failureMechanism, new AdoptableWithProfileProbabilityFailureMechanismSectionResultUpdateStrategy());

            FailureMechanismSection[] sections =
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(),
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                {
                    new Point2D(1, 0),
                    new Point2D(3, 0)
                })
            };
            string sourcePath = TestHelper.GetScratchPadPath();

            failureMechanism.SetSections(sections, sourcePath);
            failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First().ScenarioConfigurationType = PipingScenarioConfigurationPerFailureMechanismSectionType.Probabilistic;

            // When
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Then
            CollectionAssert.AreEqual(new[]
            {
                PipingScenarioConfigurationPerFailureMechanismSectionType.Probabilistic,
                PipingScenarioConfigurationPerFailureMechanismSectionType.SemiProbabilistic
            }, failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.Select(sc => sc.ScenarioConfigurationType));
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults,
                failureMechanism.ScenarioConfigurationsPerFailureMechanismSection
            }, affectedObjects);
        }
        public void GivenRowWithoutAssemblyErrors_WhenUpdatingAndAssemblyThrowsException_ThenAssemblyPropertiesSetToDefault()
        {
            // Given
            var mocks         = new MockRepository();
            var errorProvider = mocks.Stub <IFailureMechanismSectionResultRowErrorProvider>();

            mocks.ReplayAll();

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var result = new NonAdoptableFailureMechanismSectionResult(section);

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                var row = new NonAdoptableFailureMechanismSectionResultRow(result, errorProvider, new AssessmentSectionStub(), ConstructionProperties);

                // Precondition
                FailureMechanismSectionAssemblyResult calculatorOutput = calculator.FailureMechanismSectionAssemblyResultOutput.AssemblyResult;
                Assert.AreEqual(calculatorOutput.SectionProbability, row.SectionProbability);
                Assert.AreEqual(EnumDisplayNameHelper.GetDisplayName(calculatorOutput.FailureMechanismSectionAssemblyGroup),
                                row.AssemblyGroup);

                // When
                calculator.ThrowExceptionOnCalculate  = true;
                row.InitialFailureMechanismResultType = NonAdoptableInitialFailureMechanismResultType.NoFailureProbability;

                // Then
                var expectedAssemblyResult = new DefaultFailureMechanismSectionAssemblyResult();
                Assert.AreEqual(expectedAssemblyResult.SectionProbability, row.SectionProbability);
                Assert.AreEqual(EnumDisplayNameHelper.GetDisplayName(expectedAssemblyResult.FailureMechanismSectionAssemblyGroup),
                                row.AssemblyGroup);
            }

            mocks.VerifyAll();
        }
        public void SemiProbabilisticGetInitialFailureMechanismResultProbability_RelevantScenarioContributionsDoNotAddUpTo1_ReturnNaN(double contributionA, double contributionB)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var pipingCalculationScenarioA  =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenarioB =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);

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

            var result = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

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

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }
Ejemplo n.º 13
0
        public void CalculateProfileProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            var calculationScenario1 = SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);
            var calculationScenario2 = SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);
            var calculationScenario3 = SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);

            calculationScenario1.IsRelevant   = true;
            calculationScenario1.Contribution = (RoundedDouble)0.2111;
            calculationScenario1.Output       = PipingTestDataGenerator.GetSemiProbabilisticPipingOutput(1.1, 2.2, 3.3);

            calculationScenario2.IsRelevant   = true;
            calculationScenario2.Contribution = (RoundedDouble)0.7889;
            calculationScenario2.Output       = PipingTestDataGenerator.GetSemiProbabilisticPipingOutput(4.4, 5.5, 6.6);

            calculationScenario3.IsRelevant = false;

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

            var strategy = new SemiProbabilisticPipingFailureMechanismSectionResultCalculateProbabilityStrategy(
                sectionResult, calculations, new PipingFailureMechanism(), new AssessmentSectionStub());

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

            // Assert
            Assert.AreEqual(9.2969543564512289E-16, profileProbability);
        }
        public void GetInitialFailureMechanismResultProbability_RelevantScenarioContributionsDoNotAddUpTo1_ReturnNaN(double contributionA, double contributionB)
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenarioA =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenarioB =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenarioA.Contribution = (RoundedDouble)contributionA;
            macroStabilityInwardsCalculationScenarioB.Contribution = (RoundedDouble)contributionB;

            var result = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            // Call
            double initialFailureMechanismResultProbability = result.GetInitialFailureMechanismResultProbability(new[]
            {
                macroStabilityInwardsCalculationScenarioA,
                macroStabilityInwardsCalculationScenarioB
            }, 0.1);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }
Ejemplo n.º 15
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var    random       = new Random(21);
            double sectionStart = random.NextDouble();
            double sectionEnd   = random.NextDouble();

            var probabilityAssessmentInput  = new TestProbabilityAssessmentInput(0.5, 100);
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            // Call
            var properties = new FailureMechanismSectionProbabilityAssessmentProperties(section, sectionStart, sectionEnd, probabilityAssessmentInput);

            // Assert
            Assert.IsInstanceOf <FailureMechanismSectionProperties>(properties);
            Assert.AreSame(section, properties.Data);
            TestHelper.AssertTypeConverter <FailureMechanismSectionProbabilityAssessmentProperties, ExpandableObjectConverter>();

            Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces);
            Assert.AreEqual(1.0, properties.N, properties.N.GetAccuracy());

            Assert.AreEqual(sectionStart, properties.SectionStart, properties.SectionStart.GetAccuracy());
            Assert.AreEqual(sectionEnd, properties.SectionEnd, properties.SectionEnd.GetAccuracy());
        }
Ejemplo n.º 16
0
        public void UpdateSectionsWithImportedData_WithValidData_SetsSectionsToFailureMechanismAndReturnsAffectedObjects()
        {
            // Setup
            var    failureMechanism = new TestFailureMechanism();
            var    failureMechanismSectionReplaceStrategy = new FailureMechanismSectionReplaceStrategy(failureMechanism);
            string sourcePath = TestHelper.GetScratchPadPath();

            FailureMechanismSection[] sections =
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
            };

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionReplaceStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);
            Assert.AreEqual(sections.Single(), failureMechanism.Sections.Single());
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }
        public void CalculateProfileProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            GrassCoverErosionInwardsCalculationScenario calculationScenario1 = GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section);
            GrassCoverErosionInwardsCalculationScenario calculationScenario2 = GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section);
            GrassCoverErosionInwardsCalculationScenario calculationScenario3 = GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section);

            calculationScenario1.IsRelevant   = true;
            calculationScenario1.Contribution = (RoundedDouble)0.2111;
            calculationScenario1.Output       = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(1.1), null, null);

            calculationScenario2.IsRelevant   = true;
            calculationScenario2.Contribution = (RoundedDouble)0.7889;
            calculationScenario1.Output       = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(2.2), null, null);

            calculationScenario3.IsRelevant = false;

            GrassCoverErosionInwardsCalculationScenario[] calculationScenarios =
            {
                calculationScenario1,
                calculationScenario2,
                calculationScenario3
            };

            var strategy = new GrassCoverErosionInwardsFailureMechanismSectionResultCalculateProbabilityStrategy(
                sectionResult, calculationScenarios);

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

            // Assert
            Assert.AreEqual(0.3973850177700996, profileProbability);
        }
Ejemplo n.º 18
0
        public void UpdateSectionsWithImportedData_WithInvalidSections_ThrowsUpdateDataException()
        {
            // Setup
            string sourcePath = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();
            FailureMechanismSection failureMechanismSection1 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 5.0)
            });
            FailureMechanismSection failureMechanismSection2 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(10.0, 10.0),
                new Point2D(15.0, 15.0)
            });

            var sectionResultUpdateStrategy           = new TestUpdateFailureMechanismSectionResultUpdateStrategy();
            var failureMechanismSectionUpdateStrategy = new FailureMechanismSectionUpdateStrategy <FailureMechanismSectionResult>(failureMechanism, sectionResultUpdateStrategy);

            FailureMechanismSection[] sections =
            {
                failureMechanismSection1,
                failureMechanismSection2
            };

            // Call
            void Call() => failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Assert
            var exception = Assert.Throws <UpdateDataException>(Call);

            Assert.IsInstanceOf <ArgumentException>(exception.InnerException);
            Assert.AreEqual(exception.InnerException.Message, exception.Message);
            Assert.IsFalse(sectionResultUpdateStrategy.Update);
        }
        public void SemiProbabilisticGetInitialFailureMechanismResultProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            var pipingCalculationScenario1 =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenario2 =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);
            var pipingCalculationScenario3 =
                SemiProbabilisticPipingCalculationTestFactory.CreateCalculation <SemiProbabilisticPipingCalculationScenario>(section);

            pipingCalculationScenario1.IsRelevant   = true;
            pipingCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            pipingCalculationScenario1.Output       = PipingTestDataGenerator.GetSemiProbabilisticPipingOutput(1.1, 2.2, 3.3);

            pipingCalculationScenario2.IsRelevant   = true;
            pipingCalculationScenario2.Contribution = (RoundedDouble)0.7889;
            pipingCalculationScenario2.Output       = PipingTestDataGenerator.GetSemiProbabilisticPipingOutput(4.4, 5.5, 6.6);

            pipingCalculationScenario3.IsRelevant = false;

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

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 0.1);

            // Assert
            Assert.AreEqual(4.2467174336864661e-7, initialFailureMechanismResultProbability);
        }
        public void CreateNonAdoptableWithProfileProbabilityFailureMechanismSectionResult_SectionResultWithNaNValues_ReturnsEntityWithExpectedResults()
        {
            // Setup
            var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
            {
                ManualInitialFailureMechanismResultProfileProbability = double.NaN,
                ManualInitialFailureMechanismResultSectionProbability = double.NaN,
                RefinedProfileProbability = double.NaN,
                RefinedSectionProbability = double.NaN
            };

            // Call
            NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntity entity = sectionResult.Create();

            // Assert
            Assert.IsNull(entity.ManualInitialFailureMechanismResultProfileProbability);
            Assert.IsNull(entity.ManualInitialFailureMechanismResultSectionProbability);
            Assert.IsNull(entity.RefinedProfileProbability);
            Assert.IsNull(entity.RefinedSectionProbability);
        }
        public void CreateNonAdoptableWithProfileProbabilityFailureMechanismSectionResult_WithDifferentResults_ReturnsEntityWithExpectedResults()
        {
            // Setup
            var    random     = new Random(21);
            bool   isRelevant = random.NextBoolean();
            var    initialFailureMechanismResultType = random.NextEnumValue <NonAdoptableInitialFailureMechanismResultType>();
            double manualProfileProbability          = random.NextDouble();
            double manualSectionProbability          = random.NextDouble();
            var    furtherAnalysisType       = random.NextEnumValue <FailureMechanismSectionResultFurtherAnalysisType>();
            double refinedProfileProbability = random.NextDouble();
            double refinedSectionProbability = random.NextDouble();

            var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
            {
                IsRelevant = isRelevant,
                InitialFailureMechanismResultType = initialFailureMechanismResultType,
                ManualInitialFailureMechanismResultProfileProbability = manualProfileProbability,
                ManualInitialFailureMechanismResultSectionProbability = manualSectionProbability,
                FurtherAnalysisType       = furtherAnalysisType,
                RefinedProfileProbability = refinedProfileProbability,
                RefinedSectionProbability = refinedSectionProbability
            };

            // Call
            NonAdoptableWithProfileProbabilityFailureMechanismSectionResultEntity entity = sectionResult.Create();

            // Assert
            Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant);
            Assert.AreEqual(Convert.ToByte(initialFailureMechanismResultType), entity.InitialFailureMechanismResultType);
            Assert.AreEqual(manualProfileProbability, entity.ManualInitialFailureMechanismResultProfileProbability);
            Assert.AreEqual(manualSectionProbability, entity.ManualInitialFailureMechanismResultSectionProbability);
            Assert.AreEqual(Convert.ToByte(furtherAnalysisType), entity.FurtherAnalysisType);
            Assert.AreEqual(refinedProfileProbability, entity.RefinedProfileProbability);
            Assert.AreEqual(refinedSectionProbability, entity.RefinedSectionProbability);
        }
Ejemplo n.º 22
0
        public void AssembleSectionNonAdoptableWithProfileProbability_WithInputAndUseLengthEffectTrue_SetsInputOnCalculator(
            NonAdoptableInitialFailureMechanismResultType initialFailureMechanismResultType, bool expectedHasProbabilitySpecified)
        {
            // Setup
            var    random     = new Random(21);
            bool   isRelevant = random.NextBoolean();
            double manualInitialProfileProbability = random.NextDouble();
            double manualInitialSectionProbability = random.NextDouble();
            var    furtherAnalysisType             = random.NextEnumValue <FailureMechanismSectionResultFurtherAnalysisType>();
            double manualRefinedSectionProbability = random.NextDouble();
            double manualRefinedProfileProbability = random.NextDouble();

            var assessmentSection = new AssessmentSectionStub();

            var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
            {
                IsRelevant = isRelevant,
                InitialFailureMechanismResultType = initialFailureMechanismResultType,
                ManualInitialFailureMechanismResultProfileProbability = manualInitialProfileProbability,
                ManualInitialFailureMechanismResultSectionProbability = manualInitialSectionProbability,
                FurtherAnalysisType       = furtherAnalysisType,
                RefinedProfileProbability = manualRefinedProfileProbability,
                RefinedSectionProbability = manualRefinedSectionProbability
            };

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                // Call
                FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, true);

                // Assert
                FailureMechanismSectionWithProfileProbabilityAssemblyInput calculatorInput = calculator.FailureMechanismSectionWithProfileProbabilityAssemblyInput;
                FailureMechanismContribution failureMechanismContribution = assessmentSection.FailureMechanismContribution;
                Assert.AreEqual(failureMechanismContribution.SignalFloodingProbability, calculatorInput.SignalFloodingProbability);
                Assert.AreEqual(failureMechanismContribution.MaximumAllowableFloodingProbability, calculatorInput.MaximumAllowableFloodingProbability);

                Assert.AreEqual(isRelevant, calculatorInput.IsRelevant);
                Assert.AreEqual(expectedHasProbabilitySpecified, calculatorInput.HasProbabilitySpecified);
                Assert.AreEqual(manualInitialProfileProbability, calculatorInput.InitialProfileProbability);
                Assert.AreEqual(manualInitialSectionProbability, calculatorInput.InitialSectionProbability);
                Assert.AreEqual(furtherAnalysisType, calculatorInput.FurtherAnalysisType);
                Assert.AreEqual(manualRefinedProfileProbability, calculatorInput.RefinedProfileProbability);
                Assert.AreEqual(manualRefinedSectionProbability, calculatorInput.RefinedSectionProbability);
            }
        }
Ejemplo n.º 23
0
        public void AssembleSectionNonAdoptableSectionWithProfileProbability_CalculatorRan_ReturnsExpectedOutput()
        {
            // Setup
            var random            = new Random(21);
            var assessmentSection = new AssessmentSectionStub();
            var sectionResult     = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                // Call
                FailureMechanismSectionAssemblyResultWrapper result = FailureMechanismSectionAssemblyResultFactory.AssembleSection(
                    sectionResult, assessmentSection, random.NextBoolean());

                // Assert
                Assert.AreSame(calculator.FailureMechanismSectionAssemblyResultOutput, result);
            }
        }
Ejemplo n.º 24
0
        public void AssembleSectionNonAdoptableSectionWithProfileProbability_CalculatorThrowsException_ThrowsAssemblyException()
        {
            // Setup
            var random            = new Random(21);
            var assessmentSection = new AssessmentSectionStub();
            var sectionResult     = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;
                calculator.ThrowExceptionOnCalculate = true;

                // Call
                void Call() => FailureMechanismSectionAssemblyResultFactory.AssembleSection(
                    sectionResult, assessmentSection, random.NextBoolean());

                // Assert
                var       exception      = Assert.Throws <AssemblyException>(Call);
                Exception innerException = exception.InnerException;
                Assert.IsInstanceOf <FailureMechanismSectionAssemblyCalculatorException>(innerException);
                Assert.AreEqual(innerException.Message, exception.Message);
            }
        }
Ejemplo n.º 25
0
        public void AssembleSectionAdoptableSectionWithProfileProbability_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var random = new Random(21);

            var mocks             = new MockRepository();
            var calculateStrategy = mocks.Stub <IFailureMechanismSectionResultCalculateProbabilityStrategy>();

            mocks.ReplayAll();

            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());

            // Call
            void Call() => FailureMechanismSectionAssemblyResultFactory.AssembleSection(
                sectionResult, null, calculateStrategy, random.NextBoolean(), random.NextDouble());

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("assessmentSection", exception.ParamName);

            mocks.VerifyAll();
        }
Ejemplo n.º 26
0
        public void UpdateSectionsWithImportedData_WithValidData_SetsSectionsToFailureMechanismAndCopiesPropertiesOfEqualSectionsAndReturnsAffectedObjects()
        {
            // Setup
            string sourcePath = TestHelper.GetScratchPadPath();

            var failureMechanism = new TestFailureMechanism();
            FailureMechanismSection failureMechanismSection1 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(0.0, 0.0),
                new Point2D(5.0, 5.0)
            });
            FailureMechanismSection failureMechanismSection2 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
            {
                new Point2D(5.0, 5.0),
                new Point2D(10.0, 10.0)
            });

            failureMechanism.SetSections(new[]
            {
                failureMechanismSection1,
                failureMechanismSection2
            }, sourcePath);

            IObservableEnumerable <FailureMechanismSectionResult> failureMechanismSectionResults = failureMechanism.SectionResults;
            FailureMechanismSectionResult oldSectionResult = failureMechanismSectionResults.First();

            var sectionResultUpdateStrategy           = new TestUpdateFailureMechanismSectionResultUpdateStrategy();
            var failureMechanismSectionUpdateStrategy = new FailureMechanismSectionUpdateStrategy <FailureMechanismSectionResult>(failureMechanism, sectionResultUpdateStrategy);

            FailureMechanismSection[] sections =
            {
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                {
                    new Point2D(0.0, 0.0),
                    new Point2D(5.0, 5.0)
                }),
                FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[]
                {
                    new Point2D(5.0, 5.0),
                    new Point2D(15.0, 15.0)
                })
            };

            // Call
            IEnumerable <IObservable> affectedObjects = failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(sections, sourcePath);

            // Assert
            Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath);

            IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections;

            Assert.AreEqual(2, failureMechanismSections.Count());
            CollectionAssert.AreEqual(sections, failureMechanismSections);
            Assert.AreSame(oldSectionResult, sectionResultUpdateStrategy.Origin);
            Assert.AreSame(failureMechanismSectionResults.First(), sectionResultUpdateStrategy.Target);
            CollectionAssert.AreEqual(new IObservable[]
            {
                failureMechanism,
                failureMechanism.SectionResults
            }, affectedObjects);
        }
Ejemplo n.º 27
0
 protected override NonAdoptableFailureMechanismSectionResult CreateEmptySectionResult()
 {
     return(new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()));
 }
Ejemplo n.º 28
0
        public void AssembleSectionNonAdoptableSectionWithoutProfileProbability_AssessmentSectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var sectionResult = new NonAdoptableWithProfileProbabilityFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());

            // Call
            void Call() => FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("assessmentSection", exception.ParamName);
        }
Ejemplo n.º 29
0
 protected override FailureMechanismSection CreateDataModel()
 {
     return(FailureMechanismSectionTestFactory.CreateFailureMechanismSection());
 }
Ejemplo n.º 30
0
 protected override AdoptableFailureMechanismSectionResult CreateEmptySectionResult()
 {
     return(new AdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection()));
 }