Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs =================================================================== diff -u -r175cb39b49a146149811954e3800bebfc0819e3d -r83ad808e24b4781346cbf61955354127fd942a75 --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 175cb39b49a146149811954e3800bebfc0819e3d) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 83ad808e24b4781346cbf61955354127fd942a75) @@ -21,6 +21,8 @@ using System; using System.ComponentModel; +using System.Linq; +using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; @@ -33,15 +35,17 @@ public static class AssessmentSectionExtensions { /// - /// Gets the normative assessment level from a . + /// Gets the normative assessment level for a . /// - /// The assessment section. + /// The assessment section to get the normative assessment + /// level from. /// The hydraulic boundary location to get the normative - /// assessment level from. + /// assessment level for. /// The normative assessment level or when: /// /// is null; - /// contains no corresponding calculation output. + /// is not part of . + /// contains no corresponding calculation output. /// /// /// Thrown when @@ -66,15 +70,23 @@ typeof(NormType)); } + IObservableEnumerable calculations; + switch (normType) { case NormType.Signaling: - return hydraulicBoundaryLocation?.DesignWaterLevelCalculation2.Output?.Result ?? RoundedDouble.NaN; + calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; + break; case NormType.LowerLimit: - return hydraulicBoundaryLocation?.DesignWaterLevelCalculation3.Output?.Result ?? RoundedDouble.NaN; + calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + break; default: throw new NotSupportedException(); } + + HydraulicBoundaryLocationCalculation calculation = calculations.FirstOrDefault(calc => ReferenceEquals(calc.HydraulicBoundaryLocation, hydraulicBoundaryLocation)); + + return calculation?.Output?.Result ?? RoundedDouble.NaN; } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs =================================================================== diff -u -r812934f2d315f3e88151a988cb621070cee72791 -r83ad808e24b4781346cbf61955354127fd942a75 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs (.../AssessmentSectionExtensionsTest.cs) (revision 812934f2d315f3e88151a988cb621070cee72791) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/AssessmentSection/AssessmentSectionExtensionsTest.cs (.../AssessmentSectionExtensionsTest.cs) (revision 83ad808e24b4781346cbf61955354127fd942a75) @@ -22,6 +22,7 @@ using System; using System.ComponentModel; using System.Linq; +using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.TestUtil; using NUnit.Framework; @@ -70,57 +71,160 @@ mocks.VerifyAll(); } + private static FailureMechanismContribution CreateFailureMechanismContribution(NormType normType) + { + var random = new Random(21); + int otherContribution = random.Next(0, 100); + const double norm = 1.0 / 30000; + + return new FailureMechanismContribution(Enumerable.Empty(), + otherContribution, + norm, + norm) + { + NormativeNorm = normType + }; + } + + #region Norm type signaling + [Test] - public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeSignaling_ReturnsCorrespondingAssessmentLevel() + public void GetNormativeAssessmentLevel_AssessmentSectionWithOutputAndNormTypeSignaling_ReturnsCorrespondingAssessmentLevel() { // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + double expectedNormativeAssessmentLevel = new Random(21).NextDouble(); + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.Signaling)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForSignalingNorm).Return(new ObservableList + { + new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + { + Output = new TestHydraulicBoundaryLocationOutput(expectedNormativeAssessmentLevel) + }, + new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()) + }); mocks.ReplayAll(); - HydraulicBoundaryLocation hydraulicBoundaryLocationWithOutput = CreateHydraulicBoundaryLocationWithOutput(); + // Call + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); + // Assert + Assert.AreEqual(expectedNormativeAssessmentLevel, normativeAssessmentLevel, normativeAssessmentLevel.GetAccuracy()); + + mocks.VerifyAll(); + } + + [Test] + public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNullAndNormTypeSignaling_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.Signaling)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForSignalingNorm).Return(new ObservableList()); + mocks.ReplayAll(); + // Call - RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocationWithOutput); + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(null); // Assert - Assert.AreEqual(hydraulicBoundaryLocationWithOutput.DesignWaterLevelCalculation2.Output.Result, normativeAssessmentLevel); + Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel); mocks.VerifyAll(); } [Test] - public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationWithOutputAndNormTypeLowerLimit_ReturnsCorrespondingAssessmentLevel() + public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNotPartOfAssessmentSectionAndNormTypeSignaling_ReturnsNaN() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.LowerLimit)); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.Signaling)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForSignalingNorm).Return(new ObservableList()); mocks.ReplayAll(); - HydraulicBoundaryLocation hydraulicBoundaryLocationWithOutput = CreateHydraulicBoundaryLocationWithOutput(); + // Call + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(new TestHydraulicBoundaryLocation()); + // Assert + Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel); + + mocks.VerifyAll(); + } + + [Test] + public void GetNormativeAssessmentLevel_AssessmentSectionWithoutOutputAndNormTypeSignaling_ReturnsNaN() + { + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.Signaling)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForSignalingNorm).Return(new ObservableList + { + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + }); + mocks.ReplayAll(); + // Call - RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocationWithOutput); + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); // Assert - Assert.AreEqual(hydraulicBoundaryLocationWithOutput.DesignWaterLevelCalculation3.Output.Result, normativeAssessmentLevel); + Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel); mocks.VerifyAll(); } - [TestCase(NormType.Signaling)] - [TestCase(NormType.LowerLimit)] - public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNull_ReturnsNaN(NormType normType) + #endregion + + #region Norm type lower limit + + [Test] + public void GetNormativeAssessmentLevel_AssessmentSectionWithOutputAndNormTypeLowerLimit_ReturnsCorrespondingAssessmentLevel() { // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); + double expectedNormativeAssessmentLevel = new Random(21).NextDouble(); + var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(normType)); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.LowerLimit)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForLowerLimitNorm).Return(new ObservableList + { + new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()), + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + { + Output = new TestHydraulicBoundaryLocationOutput(expectedNormativeAssessmentLevel) + }, + new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation()) + }); mocks.ReplayAll(); // Call + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); + + // Assert + Assert.AreEqual(expectedNormativeAssessmentLevel, normativeAssessmentLevel, normativeAssessmentLevel.GetAccuracy()); + + mocks.VerifyAll(); + } + + [Test] + public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNullAndNormTypeLowerLimit_ReturnsNaN() + { + // Setup + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.LowerLimit)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForLowerLimitNorm).Return(new ObservableList()); + mocks.ReplayAll(); + + // Call RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(null); // Assert @@ -129,14 +233,14 @@ mocks.VerifyAll(); } - [TestCase(NormType.Signaling)] - [TestCase(NormType.LowerLimit)] - public void GetNormativeAssessmentLevel_NoCorrespondingAssessmentLevelOutput_ReturnsNaN(NormType normType) + [Test] + public void GetNormativeAssessmentLevel_HydraulicBoundaryLocationNotPartOfAssessmentSectionAndNormTypeLowerLimit_ReturnsNaN() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub(); - assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(normType)); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.LowerLimit)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForLowerLimitNorm).Return(new ObservableList()); mocks.ReplayAll(); // Call @@ -148,36 +252,30 @@ mocks.VerifyAll(); } - private static FailureMechanismContribution CreateFailureMechanismContribution(NormType normType) + [Test] + public void GetNormativeAssessmentLevel_AssessmentSectionWithoutOutputAndNormTypeLowerLimit_ReturnsNaN() { - var random = new Random(21); - int otherContribution = random.Next(0, 100); - const double norm = 1.0 / 30000; + // Setup + var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); - return new FailureMechanismContribution(Enumerable.Empty(), - otherContribution, - norm, - norm) + var mocks = new MockRepository(); + var assessmentSection = mocks.Stub(); + assessmentSection.Stub(a => a.FailureMechanismContribution).Return(CreateFailureMechanismContribution(NormType.LowerLimit)); + assessmentSection.Stub(a => a.WaterLevelCalculationsForLowerLimitNorm).Return(new ObservableList { - NormativeNorm = normType - }; - } + new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation) + }); + mocks.ReplayAll(); - private static HydraulicBoundaryLocation CreateHydraulicBoundaryLocationWithOutput() - { - var random = new Random(32); + // Call + RoundedDouble normativeAssessmentLevel = assessmentSection.GetNormativeAssessmentLevel(hydraulicBoundaryLocation); - return new TestHydraulicBoundaryLocation - { - DesignWaterLevelCalculation2 = - { - Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) - }, - DesignWaterLevelCalculation3 = - { - Output = new TestHydraulicBoundaryLocationOutput(random.NextDouble()) - } - }; + // Assert + Assert.AreEqual(RoundedDouble.NaN, normativeAssessmentLevel); + + mocks.VerifyAll(); } + + #endregion } } \ No newline at end of file