Index: Riskeer/Common/src/Riskeer.Common.Forms/Helpers/FailureMechanismSectionResultRowHelper.cs =================================================================== diff -u -r938ec5a0df29d420cc61321aff9bf288bba57971 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/Common/src/Riskeer.Common.Forms/Helpers/FailureMechanismSectionResultRowHelper.cs (.../FailureMechanismSectionResultRowHelper.cs) (revision 938ec5a0df29d420cc61321aff9bf288bba57971) +++ Riskeer/Common/src/Riskeer.Common.Forms/Helpers/FailureMechanismSectionResultRowHelper.cs (.../FailureMechanismSectionResultRowHelper.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -20,8 +20,10 @@ // All rights reserved. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.Linq; using Core.Common.Controls.DataGrid; using Riskeer.AssemblyTool.Data; using Riskeer.Common.Data.Calculation; @@ -66,6 +68,60 @@ } /// + /// Gets the error text to display when the detailed assessment probability fails. + /// + /// The type of . + /// All relevant scenario's to use. + /// The to get + /// the total contribution. + /// The + /// to get the detailed assessment probability. + /// The error message when an error is present; otherwise. + /// Thrown when any parameter is null. + public static string GetDetailedAssessmentProbabilityError( + TCalculationScenario[] relevantScenarios, Func, double> getTotalContributionFunc, + Func, double> getDetailedAssessmentProbabilityFunc) + where TCalculationScenario : ICalculationScenario + { + if (relevantScenarios == null) + { + throw new ArgumentNullException(nameof(relevantScenarios)); + } + + if (getTotalContributionFunc == null) + { + throw new ArgumentNullException(nameof(getTotalContributionFunc)); + } + + if (getDetailedAssessmentProbabilityFunc == null) + { + throw new ArgumentNullException(nameof(getDetailedAssessmentProbabilityFunc)); + } + + if (relevantScenarios.Length == 0) + { + return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; + } + + if (Math.Abs(getTotalContributionFunc(relevantScenarios) - 1.0) > 1e-6) + { + return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; + } + + if (!relevantScenarios.All(s => s.HasOutput)) + { + return Resources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; + } + + if (double.IsNaN(getDetailedAssessmentProbabilityFunc(relevantScenarios))) + { + return Resources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; + } + + return string.Empty; + } + + /// /// Helper method that determines whether the simple assessment is sufficient. /// /// The simple assessment result to check. Index: Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/FailureMechanismSectionResultRowHelperTest.cs =================================================================== diff -u -rb70c5fe23fc35933af143bba669d3e2239377307 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/FailureMechanismSectionResultRowHelperTest.cs (.../FailureMechanismSectionResultRowHelperTest.cs) (revision b70c5fe23fc35933af143bba669d3e2239377307) +++ Riskeer/Common/test/Riskeer.Common.Forms.Test/Helpers/FailureMechanismSectionResultRowHelperTest.cs (.../FailureMechanismSectionResultRowHelperTest.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -26,6 +26,7 @@ using Core.Common.Controls.DataGrid; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Riskeer.AssemblyTool.Data; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.TestUtil; @@ -55,6 +56,148 @@ } [Test] + public void GetDetailedAssessmentProbabilityError_RelevantScenariosNull_ThrowsArgumentNullException() + { + // Call + void Call() => FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + null, scenarios => double.NaN, scenarios => double.NaN); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("relevantScenarios", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_GetTotalContributionFuncNull_ThrowsArgumentNullException() + { + // Call + void Call() => FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + new ICalculationScenario[0], null, scenarios => double.NaN); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("getTotalContributionFunc", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_GetDetailedAssessmentProbabilityFuncNull_ThrowsArgumentNullException() + { + // Call + void Call() => FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + new ICalculationScenario[0], scenarios => double.NaN, null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("getDetailedAssessmentProbabilityFunc", exception.ParamName); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_RelevantScenariosEmpty_ReturnsErrorMessage() + { + // Setup + var random = new Random(21); + + // Call + string errorMessage = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + new ICalculationScenario[0], scenarios => random.NextDouble(), scenarios => random.NextDouble()); + + // Assert + Assert.AreEqual("Er moet minimaal één maatgevende berekening voor dit vak worden geselecteerd.", errorMessage); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_TotalContributionNotHundred_ReturnsErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var calculationScenario = mocks.Stub(); + mocks.ReplayAll(); + + var random = new Random(21); + ICalculationScenario[] calculationScenarios = + { + calculationScenario + }; + + // Call + string errorMessage = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + calculationScenarios, scenarios => random.NextDouble(0, 0.99), scenarios => random.NextDouble()); + + // Assert + Assert.AreEqual("Bijdrage van de geselecteerde scenario's voor dit vak moet opgeteld gelijk zijn aan 100%.", errorMessage); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_CalculationScenariosWithoutOutput_ReturnsErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var calculationScenario1 = mocks.Stub(); + calculationScenario1.Stub(cs => cs.HasOutput).Return(true); + var calculationScenario2 = mocks.Stub(); + mocks.ReplayAll(); + + var random = new Random(21); + ICalculationScenario[] calculationScenarios = + { + calculationScenario1, + calculationScenario2 + }; + + // Call + string errorMessage = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + calculationScenarios, scenarios => 1, scenarios => random.NextDouble()); + + // Assert + Assert.AreEqual("Alle berekeningen voor dit vak moeten uitgevoerd zijn.", errorMessage); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_DetailedAssessmentProbabilityNaN_ReturnsErrorMessage() + { + // Setup + var mocks = new MockRepository(); + var calculationScenario = mocks.Stub(); + calculationScenario.Stub(cs => cs.HasOutput).Return(true); + mocks.ReplayAll(); + + ICalculationScenario[] calculationScenarios = + { + calculationScenario + }; + + // Call + string errorMessage = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + calculationScenarios, scenarios => 1, scenarios => double.NaN); + + // Assert + Assert.AreEqual("Alle berekeningen voor dit vak moeten een geldige uitkomst hebben.", errorMessage); + } + + [Test] + public void GetDetailedAssessmentProbabilityError_ValidData_ReturnsEmptyMessage() + { + // Setup + var mocks = new MockRepository(); + var calculationScenario = mocks.Stub(); + calculationScenario.Stub(cs => cs.HasOutput).Return(true); + mocks.ReplayAll(); + + var random = new Random(21); + ICalculationScenario[] calculationScenarios = + { + calculationScenario + }; + + // Call + string errorMessage = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + calculationScenarios, scenarios => 1, scenarios => random.NextDouble()); + + // Assert + Assert.IsEmpty(errorMessage); + } + + [Test] [TestCase(SimpleAssessmentResultType.None, false)] [TestCase(SimpleAssessmentResultType.NotApplicable, true)] [TestCase(SimpleAssessmentResultType.ProbabilityNegligible, true)] Index: Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -r4aaa3bae2b899be0c171803ef8111e7d84af1f01 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision 4aaa3bae2b899be0c171803ef8111e7d84af1f01) +++ Riskeer/GrassCoverErosionInwards/src/Riskeer.GrassCoverErosionInwards.Forms/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRow.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -32,7 +32,6 @@ using Riskeer.Common.Forms.Views; using Riskeer.Common.Primitives; using Riskeer.GrassCoverErosionInwards.Data; -using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.GrassCoverErosionInwards.Forms.Views { @@ -269,37 +268,13 @@ } else { - ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = GetDetailedAssessmentProbabilityError(); + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + SectionResult.GetCalculationScenarios(calculationScenarios).ToArray(), + scenarios => SectionResult.GetTotalContribution(scenarios), + scenarios => SectionResult.GetDetailedAssessmentProbability(scenarios, failureMechanism, assessmentSection)); } } - private string GetDetailedAssessmentProbabilityError() - { - GrassCoverErosionInwardsCalculationScenario[] relevantScenarios = SectionResult.GetCalculationScenarios(calculationScenarios).ToArray(); - - if (relevantScenarios.Length == 0) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; - } - - if (Math.Abs(SectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; - } - - if (!relevantScenarios.All(s => s.HasOutput)) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; - } - - if (double.IsNaN(SectionResult.GetDetailedAssessmentProbability(calculationScenarios, failureMechanism, assessmentSection))) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; - } - - return string.Empty; - } - private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); Index: Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs =================================================================== diff -u -r4aaa3bae2b899be0c171803ef8111e7d84af1f01 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision 4aaa3bae2b899be0c171803ef8111e7d84af1f01) +++ Riskeer/GrassCoverErosionInwards/test/Riskeer.GrassCoverErosionInwards.Forms.Test/Views/GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs (.../GrassCoverErosionInwardsFailureMechanismSectionResultRowTest.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -732,133 +732,6 @@ } } - // [Test] - // [TestCase(SimpleAssessmentValidityOnlyResultType.None)] - // [TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)] - // public void Constructor_SectionResultWithoutCalculation_DetailedAssessmentProbabilityHasErrorText( - // SimpleAssessmentValidityOnlyResultType simpleAssessmentResult) - // { - // // Setup - // var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - // - // var mocks = new MockRepository(); - // IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); - // mocks.ReplayAll(); - // - // FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - // var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) - // { - // SimpleAssessmentResult = simpleAssessmentResult - // }; - // - // GrassCoverErosionInwardsCalculationScenario[] calculationScenarios = - // { - // GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateGrassCoverErosionInwardsCalculationScenario(section) - // }; - // - // using (new AssemblyToolCalculatorFactoryConfig()) - // { - // // Call - // var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - // sectionResult, calculationScenarios, failureMechanism, assessmentSection, ConstructionProperties); - // - // // Assert - // Assert.IsNaN(resultRow.DetailedAssessmentProbability); - // Assert.AreEqual("Er moet een maatgevende berekening voor dit vak worden geselecteerd.", - // resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); - // mocks.VerifyAll(); - // } - // } - // - // [Test] - // [TestCase(SimpleAssessmentValidityOnlyResultType.None)] - // [TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)] - // public void Constructor_SectionResultAndCalculationNotCalculated_DetailedAssessmentProbabilityHasErrorText( - // SimpleAssessmentValidityOnlyResultType simpleAssessmentResult) - // { - // // Setup - // var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - // - // var mocks = new MockRepository(); - // IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); - // mocks.ReplayAll(); - // - // FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - // var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) - // { - // Calculation = new GrassCoverErosionInwardsCalculation(), - // SimpleAssessmentResult = simpleAssessmentResult - // }; - // - // GrassCoverErosionInwardsCalculationScenario[] calculationScenarios = - // { - // GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateNotCalculatedGrassCoverErosionInwardsCalculationScenario(section) - // }; - // - // using (new AssemblyToolCalculatorFactoryConfig()) - // { - // // Call - // var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - // sectionResult, calculationScenarios, failureMechanism, assessmentSection, ConstructionProperties); - // - // // Assert - // Assert.IsNaN(resultRow.DetailedAssessmentProbability); - // Assert.AreEqual("De maatgevende berekening voor dit vak moet nog worden uitgevoerd.", - // resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); - // mocks.VerifyAll(); - // } - // } - // - // [Test] - // [TestCase(SimpleAssessmentValidityOnlyResultType.None)] - // [TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)] - // public void Constructor_SectionResultAndFailedCalculation_DetailedAssessmentProbabilityHasErrorText( - // SimpleAssessmentValidityOnlyResultType simpleAssessmentResult) - // { - // // Setup - // var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); - // - // var mocks = new MockRepository(); - // IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks); - // mocks.ReplayAll(); - // - // var calculation = new GrassCoverErosionInwardsCalculation - // { - // Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(double.NaN), - // new TestDikeHeightOutput(double.NaN), - // new TestOvertoppingRateOutput(double.NaN)) - // }; - // FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(); - // var sectionResult = new GrassCoverErosionInwardsFailureMechanismSectionResult(section) - // { - // Calculation = calculation, - // SimpleAssessmentResult = simpleAssessmentResult - // }; - // - // GrassCoverErosionInwardsCalculationScenario calculationScenario = GrassCoverErosionInwardsCalculationScenarioTestFactory.CreateNotCalculatedGrassCoverErosionInwardsCalculationScenario(section); - // calculationScenario.Output = new GrassCoverErosionInwardsOutput(new TestOvertoppingOutput(double.NaN), null, null); - // - // using (new AssemblyToolCalculatorFactoryConfig()) - // { - // // Call - // var resultRow = new GrassCoverErosionInwardsFailureMechanismSectionResultRow( - // sectionResult, - // new[] - // { - // calculationScenario - // }, - // failureMechanism, - // assessmentSection, - // ConstructionProperties); - // - // // Assert - // Assert.IsNaN(resultRow.DetailedAssessmentProbability); - // Assert.AreEqual("De maatgevende berekening voor dit vak moet een geldige uitkomst hebben.", - // resultRow.ColumnStateDefinitions[ConstructionProperties.DetailedAssessmentProbabilityIndex].ErrorText); - // mocks.VerifyAll(); - // } - // } - [Test] [TestCase(SimpleAssessmentValidityOnlyResultType.None)] [TestCase(SimpleAssessmentValidityOnlyResultType.Applicable)] Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -r3af68bc0c3e12d97181e1799c0b22e7e6ac1e934 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision 3af68bc0c3e12d97181e1799c0b22e7e6ac1e934) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -32,7 +32,6 @@ using Riskeer.Common.Forms.Views; using Riskeer.Common.Primitives; using Riskeer.MacroStabilityInwards.Data; -using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.MacroStabilityInwards.Forms.Views { @@ -130,10 +129,7 @@ /// is a valid value, but unsupported. public SimpleAssessmentResultType SimpleAssessmentResult { - get - { - return SectionResult.SimpleAssessmentResult; - } + get => SectionResult.SimpleAssessmentResult; set { SectionResult.SimpleAssessmentResult = value; @@ -148,10 +144,7 @@ /// is a valid value, but unsupported. public DetailedAssessmentProbabilityOnlyResultType DetailedAssessmentResult { - get - { - return SectionResult.DetailedAssessmentResult; - } + get => SectionResult.DetailedAssessmentResult; set { SectionResult.DetailedAssessmentResult = value; @@ -163,13 +156,7 @@ /// Gets the detailed assessment probability a of the . /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double DetailedAssessmentProbability - { - get - { - return SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); - } - } + public double DetailedAssessmentProbability => SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); /// /// Gets or sets the value representing the tailor made assessment result. @@ -178,10 +165,7 @@ /// is a valid value, but unsupported. public TailorMadeAssessmentProbabilityCalculationResultType TailorMadeAssessmentResult { - get - { - return SectionResult.TailorMadeAssessmentResult; - } + get => SectionResult.TailorMadeAssessmentResult; set { SectionResult.TailorMadeAssessmentResult = value; @@ -199,10 +183,7 @@ [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double TailorMadeAssessmentProbability { - get - { - return SectionResult.TailorMadeAssessmentProbability; - } + get => SectionResult.TailorMadeAssessmentProbability; set { SectionResult.TailorMadeAssessmentProbability = value; @@ -213,46 +194,22 @@ /// /// Gets the simple assembly category group. /// - public string SimpleAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(simpleAssemblyCategoryGroup); - } - } + public string SimpleAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(simpleAssemblyCategoryGroup); /// /// Gets the detailed assembly category group. /// - public string DetailedAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(detailedAssemblyCategoryGroup); - } - } + public string DetailedAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(detailedAssemblyCategoryGroup); /// /// Gets the tailor made assembly category group. /// - public string TailorMadeAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(tailorMadeAssemblyCategoryGroup); - } - } + public string TailorMadeAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(tailorMadeAssemblyCategoryGroup); /// /// Gets the combined assembly category group. /// - public string CombinedAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(combinedAssemblyCategoryGroup); - } - } + public string CombinedAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(combinedAssemblyCategoryGroup); /// /// Gets the combined assembly probability. @@ -268,10 +225,7 @@ /// is a valid value, but unsupported. public bool UseManualAssembly { - get - { - return SectionResult.UseManualAssembly; - } + get => SectionResult.UseManualAssembly; set { SectionResult.UseManualAssembly = value; @@ -289,10 +243,7 @@ [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double ManualAssemblyProbability { - get - { - return SectionResult.ManualAssemblyProbability; - } + get => SectionResult.ManualAssemblyProbability; set { SectionResult.ManualAssemblyProbability = value; @@ -317,38 +268,13 @@ } else { - ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = GetDetailedAssessmentProbabilityError(); + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + SectionResult.GetCalculationScenarios(calculations).ToArray(), + scenarios => SectionResult.GetTotalContribution(scenarios), + scenarios => SectionResult.GetDetailedAssessmentProbability(scenarios, failureMechanism, assessmentSection)); } } - private string GetDetailedAssessmentProbabilityError() - { - MacroStabilityInwardsCalculationScenario[] relevantScenarios = SectionResult.GetCalculationScenarios(calculations).ToArray(); - bool relevantScenarioAvailable = relevantScenarios.Length != 0; - - if (!relevantScenarioAvailable) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; - } - - if (Math.Abs(SectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; - } - - if (!relevantScenarios.All(s => s.HasOutput)) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; - } - - if (double.IsNaN(SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection))) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; - } - - return string.Empty; - } - private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs =================================================================== diff -u -r948f2515a260904928ef82614996881afbadf615 -rcdac80ab39c90895c74566f3bde0077bcc936de2 --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision 948f2515a260904928ef82614996881afbadf615) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingFailureMechanismSectionResultRow.cs (.../PipingFailureMechanismSectionResultRow.cs) (revision cdac80ab39c90895c74566f3bde0077bcc936de2) @@ -32,7 +32,6 @@ using Riskeer.Common.Forms.Views; using Riskeer.Common.Primitives; using Riskeer.Piping.Data; -using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; namespace Riskeer.Piping.Forms.Views { @@ -129,10 +128,7 @@ /// is a valid value, but unsupported. public SimpleAssessmentResultType SimpleAssessmentResult { - get - { - return SectionResult.SimpleAssessmentResult; - } + get => SectionResult.SimpleAssessmentResult; set { SectionResult.SimpleAssessmentResult = value; @@ -147,10 +143,7 @@ /// is a valid value, but unsupported. public DetailedAssessmentProbabilityOnlyResultType DetailedAssessmentResult { - get - { - return SectionResult.DetailedAssessmentResult; - } + get => SectionResult.DetailedAssessmentResult; set { SectionResult.DetailedAssessmentResult = value; @@ -162,13 +155,7 @@ /// Gets the detailed assessment probability a of the . /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double DetailedAssessmentProbability - { - get - { - return SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); - } - } + public double DetailedAssessmentProbability => SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); /// /// Gets or sets the value representing the tailor made assessment result. @@ -177,10 +164,7 @@ /// is a valid value, but unsupported. public TailorMadeAssessmentProbabilityCalculationResultType TailorMadeAssessmentResult { - get - { - return SectionResult.TailorMadeAssessmentResult; - } + get => SectionResult.TailorMadeAssessmentResult; set { SectionResult.TailorMadeAssessmentResult = value; @@ -198,10 +182,7 @@ [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double TailorMadeAssessmentProbability { - get - { - return SectionResult.TailorMadeAssessmentProbability; - } + get => SectionResult.TailorMadeAssessmentProbability; set { SectionResult.TailorMadeAssessmentProbability = value; @@ -212,46 +193,22 @@ /// /// Gets the simple assembly category group. /// - public string SimpleAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(simpleAssemblyCategoryGroup); - } - } + public string SimpleAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(simpleAssemblyCategoryGroup); /// /// Gets the detailed assembly category group. /// - public string DetailedAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(detailedAssemblyCategoryGroup); - } - } + public string DetailedAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(detailedAssemblyCategoryGroup); /// /// Gets the tailor made assembly category group. /// - public string TailorMadeAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(tailorMadeAssemblyCategoryGroup); - } - } + public string TailorMadeAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(tailorMadeAssemblyCategoryGroup); /// /// Gets the combined assembly category group. /// - public string CombinedAssemblyCategoryGroup - { - get - { - return FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(combinedAssemblyCategoryGroup); - } - } + public string CombinedAssemblyCategoryGroup => FailureMechanismSectionAssemblyCategoryGroupHelper.GetCategoryGroupDisplayName(combinedAssemblyCategoryGroup); /// /// Gets the combined assembly probability. @@ -267,10 +224,7 @@ /// is a valid value, but unsupported. public bool UseManualAssembly { - get - { - return SectionResult.UseManualAssembly; - } + get => SectionResult.UseManualAssembly; set { SectionResult.UseManualAssembly = value; @@ -288,10 +242,7 @@ [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double ManualAssemblyProbability { - get - { - return SectionResult.ManualAssemblyProbability; - } + get => SectionResult.ManualAssemblyProbability; set { SectionResult.ManualAssemblyProbability = value; @@ -316,38 +267,13 @@ } else { - ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = GetDetailedAssessmentProbabilityError(); + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = FailureMechanismSectionResultRowHelper.GetDetailedAssessmentProbabilityError( + SectionResult.GetCalculationScenarios(calculations).ToArray(), + scenarios => SectionResult.GetTotalContribution(scenarios), + scenarios => SectionResult.GetDetailedAssessmentProbability(scenarios, failureMechanism, assessmentSection)); } } - private string GetDetailedAssessmentProbabilityError() - { - PipingCalculationScenario[] relevantScenarios = SectionResult.GetCalculationScenarios(calculations).ToArray(); - bool relevantScenarioAvailable = relevantScenarios.Length != 0; - - if (!relevantScenarioAvailable) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; - } - - if (Math.Abs(SectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; - } - - if (!relevantScenarios.All(s => s.HasOutput)) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; - } - - if (double.IsNaN(SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection))) - { - return RiskeerCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; - } - - return string.Empty; - } - private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition());