Index: Ringtoets/Common/src/Ringtoets.Common.Util/StructuresHelper.cs
===================================================================
diff -u -r5dabca97fffab41012aafa58da5bc4cd0192e947 -r9a637f9e1783f766a92c32ae45ebce60710e4c05
--- Ringtoets/Common/src/Ringtoets.Common.Util/StructuresHelper.cs (.../StructuresHelper.cs) (revision 5dabca97fffab41012aafa58da5bc4cd0192e947)
+++ Ringtoets/Common/src/Ringtoets.Common.Util/StructuresHelper.cs (.../StructuresHelper.cs) (revision 9a637f9e1783f766a92c32ae45ebce60710e4c05)
@@ -56,32 +56,6 @@
}
///
- /// Updates the for each element
- /// of if required due to a change.
- ///
- /// The of
- /// to possibly reassign a calculation to.
- /// The of to try
- /// and match with the .
- /// All affected objects by the deletion.
- /// Thrown when any input parameter is null or when an element
- /// in is null.
- /// Thrown when element in is
- /// null.
- public static IEnumerable> UpdateCalculationToSectionResultAssignments(IEnumerable> sectionResults,
- IEnumerable> calculations)
- where T : IStructuresCalculationInput, new()
- {
- ValidateSectionResults(sectionResults);
-
- return AssignUnassignCalculations.Update(
- sectionResults.Select(AsCalculationAssignment),
- AsCalculationsWithLocations(calculations))
- .Cast>()
- .ToArray();
- }
-
- ///
/// Transforms the into and filter out the calculations
/// for which a could not be made.
///
@@ -99,19 +73,6 @@
return calculations.Select(AsCalculationWithLocation).Where(c => c != null);
}
- private static void ValidateSectionResults(IEnumerable> sectionResults)
- where T : IStructuresCalculationInput, new()
- {
- if (sectionResults == null)
- {
- throw new ArgumentNullException(nameof(sectionResults));
- }
- if (sectionResults.Any(sr => sr == null))
- {
- throw new ArgumentException(@"SectionResults contains an entry without value.", nameof(sectionResults));
- }
- }
-
private static CalculationWithLocation AsCalculationWithLocation(StructuresCalculation calculation)
where T : IStructuresCalculationInput, new()
{
@@ -125,14 +86,5 @@
}
return new CalculationWithLocation(calculation, calculation.InputParameters.Structure.Location);
}
-
- private static SectionResultWithCalculationAssignment AsCalculationAssignment(StructuresFailureMechanismSectionResult failureMechanismSectionResult)
- where T : IStructuresCalculationInput, new()
- {
- return new SectionResultWithCalculationAssignment(
- failureMechanismSectionResult,
- result => ((StructuresFailureMechanismSectionResult) result).Calculation,
- (result, calculation) => ((StructuresFailureMechanismSectionResult) result).Calculation = (StructuresCalculation) calculation);
- }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.Util.Test/StructuresHelperTest.cs
===================================================================
diff -u -rfcad48d7beb394e1ac15cfe4289a7381e05aa883 -r9a637f9e1783f766a92c32ae45ebce60710e4c05
--- Ringtoets/Common/test/Ringtoets.Common.Util.Test/StructuresHelperTest.cs (.../StructuresHelperTest.cs) (revision fcad48d7beb394e1ac15cfe4289a7381e05aa883)
+++ Ringtoets/Common/test/Ringtoets.Common.Util.Test/StructuresHelperTest.cs (.../StructuresHelperTest.cs) (revision 9a637f9e1783f766a92c32ae45ebce60710e4c05)
@@ -23,9 +23,9 @@
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base.Geometry;
-using Core.Common.TestUtil;
using NUnit.Framework;
using Ringtoets.Common.Data;
+using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Data.TestUtil;
@@ -35,9 +35,6 @@
[TestFixture]
public class StructuresHelperTest
{
- private const string firstSectionName = "firstSection";
- private const string secondSectionName = "secondSection";
-
[Test]
public void CollectCalculationsPerSection_SectionsAreNull_ThrowsArgumentNullException()
{
@@ -57,18 +54,26 @@
[Test]
public void CollectCalculationsPerSection_SectionElementsAreNull_ThrowsArgumentException()
{
- // Call
- TestDelegate test = () => StructuresHelper.CollectCalculationsPerSection(
- new FailureMechanismSection[]
+ // Setup
+ var structuresCalculation = new StructuresCalculation
+ {
+ InputParameters =
{
- null,
- null
- },
- new[]
- {
- calculationInSectionA
- });
+ Structure = new TestStructure("anId", "aName", new Point2D(1.1, 2.2))
+ }
+ };
+ // Call
+ TestDelegate test = () => StructuresHelper.CollectCalculationsPerSection(new FailureMechanismSection[]
+ {
+ null,
+ null
+ },
+ new[]
+ {
+ structuresCalculation
+ });
+
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("sections", exception.ParamName);
@@ -79,7 +84,10 @@
{
// Call
TestDelegate test = () => StructuresHelper.CollectCalculationsPerSection(
- twoSections,
+ new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ },
null);
// Assert
@@ -92,7 +100,10 @@
{
// Call
TestDelegate test = () => StructuresHelper.CollectCalculationsPerSection(
- twoSections,
+ new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ },
new StructuresCalculation[]
{
null
@@ -104,122 +115,146 @@
}
[Test]
- public void UpdateCalculationToSectionResultAssignments_SectionResultsNull_ThrowsArgumentNullException()
+ public void CollectCalculationsPerSegment_ValidEmptySectionResults_EmptyDictionary()
{
- // Call
- TestDelegate test = () => StructuresHelper.UpdateCalculationToSectionResultAssignments(
- null,
- new[]
+ // Setup
+ var structuresCalculation = new StructuresCalculation
+ {
+ InputParameters =
{
- calculationInSectionB
- });
+ Structure = new TestStructure(new Point2D(1.1, 2.2))
+ }
+ };
- // Assert
- var exception = Assert.Throws(test);
- Assert.AreEqual("sectionResults", exception.ParamName);
- }
-
- [Test]
- public void UpdateCalculationToSectionResultAssignments_SectionResultElementsNull_ThrowsArgumentException()
- {
// Call
- TestDelegate test = () => StructuresHelper.UpdateCalculationToSectionResultAssignments(
- new TestStructuresFailureMechanismSectionResult[]
+ IDictionary> collectCalculationsPerSegment =
+ StructuresHelper.CollectCalculationsPerSection(Enumerable.Empty(), new[]
{
- null,
- null
- },
- new[]
- {
- calculationInSectionB
+ structuresCalculation
});
// Assert
- var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage(
- test, "SectionResults contains an entry without value.");
- Assert.AreEqual("sectionResults", exception.ParamName);
+ Assert.AreEqual(0, collectCalculationsPerSegment.Count);
}
[Test]
- public void UpdateCalculationToSectionResultAssignments_CalculationsNull_ThrowsArgumentNullException()
+ public void CollectCalculationsPerSegment_ValidEmptyCalculations_EmptyDictionary()
{
// Call
- TestDelegate test = () => StructuresHelper.UpdateCalculationToSectionResultAssignments(
- new[]
- {
- sectionResult
- },
- null);
+ IDictionary> collectCalculationsPerSegment =
+ StructuresHelper.CollectCalculationsPerSection(new[]
+ {
+ FailureMechanismSectionTestFactory.CreateFailureMechanismSection()
+ },
+ Enumerable.Empty>());
// Assert
- var exception = Assert.Throws(test);
- Assert.AreEqual("calculations", exception.ParamName);
+ Assert.AreEqual(0, collectCalculationsPerSegment.Count);
}
[Test]
- public void UpdateCalculationToSectionResultAssignments_CalculationsElementNull_ThrowsArgumentNullException()
+ public void CollectCalculationsPerSegment_MultipleCalculationsInSegment_OneSegmentHasAllCalculations()
{
- // Call
- TestDelegate test = () => StructuresHelper.UpdateCalculationToSectionResultAssignments(
- new[]
+ // Setup
+ const string firstSectionName = "A";
+ var location = new Point2D(1, 1);
+
+ var calculationOne = new StructuresCalculation
+ {
+ InputParameters =
{
- sectionResult
- },
- new StructuresCalculation[]
+ Structure = new TestStructure(location)
+ }
+ };
+ var calculationTwo = new StructuresCalculation
+ {
+ InputParameters =
{
- null
- });
-
- // Assert
- var exception = Assert.Throws(test);
- Assert.AreEqual("calculation", exception.ParamName);
- }
-
- [Test]
- public void UpdateCalculationToSectionResultAssignments_SectionResultWithCalculationNoRemainingCalculations_SectionResultCalculationIsNull()
- {
- // Setup
- var failureMechanismSectionResult = new TestStructuresFailureMechanismSectionResult(
- failureMechanismSectionA)
+ Structure = new TestStructure(location)
+ }
+ };
+ var calculations = new[]
{
- Calculation = calculationInSectionA
+ calculationOne,
+ calculationTwo
};
// Call
- StructuresHelper.UpdateCalculationToSectionResultAssignments(
- new[]
+ IDictionary> collectCalculationsPerSegment =
+ StructuresHelper.CollectCalculationsPerSection(new[]
{
- failureMechanismSectionResult
- },
- Enumerable.Empty>());
+ new FailureMechanismSection(firstSectionName, new[]
+ {
+ location,
+ new Point2D(2, 2)
+ }),
+ new FailureMechanismSection("B", new[]
+ {
+ new Point2D(2, 2),
+ new Point2D(3, 3)
+ })
+ }, calculations);
// Assert
- Assert.IsNull(failureMechanismSectionResult.Calculation);
+ Assert.AreEqual(1, collectCalculationsPerSegment.Count);
+ Assert.IsTrue(collectCalculationsPerSegment.ContainsKey(firstSectionName));
+ CollectionAssert.AreEqual(calculations, collectCalculationsPerSegment[firstSectionName]);
}
[Test]
- public void UpdateCalculationToSectionResultAssignments_SectionResultWithCalculationWithRemainingCalculations_SectionResultCalculationSetToRemainingCalculation()
+ public void CollectCalculationsPerSegment_SingleCalculationPerSegment_OneCalculationPerSegment()
{
// Setup
- var failureMechanismSectionResult = new TestStructuresFailureMechanismSectionResult(
- failureMechanismSectionA)
+ const string firstSectionName = "A";
+ const string secondSectionName = "B";
+
+ var locationOne = new Point2D(1, 1);
+ var locationTwo = new Point2D(3, 3);
+
+ var calculationOne = new StructuresCalculation
{
- Calculation = calculationInSectionA
+ InputParameters =
+ {
+ Structure = new TestStructure(locationOne)
+ }
};
+ var calculationTwo = new StructuresCalculation
+ {
+ InputParameters =
+ {
+ Structure = new TestStructure(locationTwo)
+ }
+ };
+ var calculations = new[]
+ {
+ calculationOne,
+ calculationTwo
+ };
- // Call
- StructuresHelper.UpdateCalculationToSectionResultAssignments(
- new[]
+ var failureMechanismSections = new[]
+ {
+ new FailureMechanismSection(firstSectionName, new[]
{
- failureMechanismSectionResult
- },
- new[]
+ locationOne,
+ new Point2D(2, 2)
+ }),
+ new FailureMechanismSection(secondSectionName, new[]
{
- calculationInSectionB
- });
+ new Point2D(2, 2),
+ locationTwo
+ })
+ };
+ // Call
+ IDictionary> collectCalculationsPerSegment =
+ StructuresHelper.CollectCalculationsPerSection(failureMechanismSections, calculations);
+
// Assert
- Assert.AreSame(calculationInSectionB, failureMechanismSectionResult.Calculation);
+ Assert.AreEqual(2, collectCalculationsPerSegment.Count);
+ Assert.AreEqual(1, collectCalculationsPerSegment[firstSectionName].Count);
+ Assert.AreSame(calculationOne, collectCalculationsPerSegment[firstSectionName][0]);
+ Assert.AreEqual(1, collectCalculationsPerSegment[secondSectionName].Count);
+ Assert.AreSame(calculationTwo, collectCalculationsPerSegment[secondSectionName][0]);
}
private class TestStructuresInput : StructuresInputBase
@@ -234,51 +269,5 @@
public override void SynchronizeStructureInput() {}
}
-
- private class TestStructuresFailureMechanismSectionResult : StructuresFailureMechanismSectionResult
- {
- public TestStructuresFailureMechanismSectionResult(FailureMechanismSection section) : base(section) {}
- }
-
- #region Prepared data
-
- private static readonly FailureMechanismSection failureMechanismSectionA = new FailureMechanismSection(firstSectionName, new List
- {
- new Point2D(0.0, 0.0),
- new Point2D(10.0, 10.0)
- });
-
- private static readonly FailureMechanismSection failureMechanismSectionB = new FailureMechanismSection(secondSectionName, new List
- {
- new Point2D(11.0, 11.0),
- new Point2D(100.0, 100.0)
- });
-
- private static readonly TestStructuresFailureMechanismSectionResult sectionResult = new TestStructuresFailureMechanismSectionResult(
- failureMechanismSectionA);
-
- private readonly FailureMechanismSection[] twoSections =
- {
- failureMechanismSectionA,
- failureMechanismSectionB
- };
-
- private readonly StructuresCalculation calculationInSectionA = new StructuresCalculation
- {
- InputParameters =
- {
- Structure = new TestStructure("anId", "aName", new Point2D(1.1, 2.2))
- }
- };
-
- private readonly StructuresCalculation calculationInSectionB = new StructuresCalculation
- {
- InputParameters =
- {
- Structure = new TestStructure("anId", "aName", new Point2D(50.0, 66.0))
- }
- };
-
- #endregion
}
}
\ No newline at end of file