// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.GrassCoverErosionInwards.Data; namespace Ringtoets.GrassCoverErosionInwards.Utils.Test { [TestFixture] public class GrassCoverErosionInwardsHelperTest { private const string firstSectionName = "firstSection"; private const string secondSectionName = "secondSection"; private readonly FailureMechanismSection[] oneSection = { new FailureMechanismSection("testFailureMechanismSection", new List { new Point2D(0.0, 0.0) }) }; private readonly FailureMechanismSection[] twoSections = { new FailureMechanismSection(firstSectionName, new List { new Point2D(0.0, 0.0), new Point2D(10.0, 10.0), }), new FailureMechanismSection(secondSectionName, new List { new Point2D(11.0, 11.0), new Point2D(100.0, 100.0), }) }; private readonly GrassCoverErosionInwardsCalculation[] twoCalculations = { new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } }, new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(3.3, 4.4), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } } }; [Test] public void CollectCalculationsPerSegment_SectionResultsNull_ThrowsArgumentNullException() { // Setup var calculations = new GrassCoverErosionInwardsCalculation[0]; // Call TestDelegate call = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(null, calculations); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("sections", paramName); } [Test] public void CollectCalculationsPerSegment_CalculationsNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, null); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("calculations", paramName); } [Test] public void CollectCalculationsPerSegment_ValidEmptySectionResults_EmptyDictionary() { // Setup var emptySections = new FailureMechanismSection[0]; // Call Dictionary> collectCalculationsPerSegment = GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(emptySections, twoCalculations); // Assert Assert.AreEqual(0, collectCalculationsPerSegment.Count); } [Test] public void CollectCalculationsPerSegment_ValidEmptyCalculations_EmptyDictionary() { // Setup var calculations = new GrassCoverErosionInwardsCalculation[0]; // Call Dictionary> collectCalculationsPerSegment = GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, calculations); // Assert Assert.AreEqual(0, collectCalculationsPerSegment.Count); } [Test] public void CollectCalculationsPerSegment_CalculationsWithoutDikeProfiles_EmptyDictionary() { // Setup GrassCoverErosionInwardsCalculation[] calculations = { new GrassCoverErosionInwardsCalculation(), new GrassCoverErosionInwardsCalculation() }; // Call Dictionary> collectCalculationsPerSegment = GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(oneSection, calculations); // Assert Assert.AreEqual(0, collectCalculationsPerSegment.Count); } [Test] public void CollectCalculationsPerSegment_MultipleCalculationsInSegment_OneSegmentHasAllCalculations() { // Call Dictionary> collectCalculationsPerSegment = GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(twoSections, twoCalculations); // Assert Assert.AreEqual(1, collectCalculationsPerSegment.Count); Assert.IsTrue(collectCalculationsPerSegment.ContainsKey(firstSectionName)); CollectionAssert.AreEqual(twoCalculations, collectCalculationsPerSegment[firstSectionName]); } [Test] public void CollectCalculationsPerSegment_SingleCalculationPerSegment_OneCalculationPerSegment() { // Setup GrassCoverErosionInwardsCalculation[] calculations = { new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } }, new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(50.0, 66.0), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } } }; // Call Dictionary> collectCalculationsPerSegment = GrassCoverErosionInwardsHelper.CollectCalculationsPerSegment(twoSections, calculations); // Assert Assert.AreEqual(2, collectCalculationsPerSegment.Count); Assert.AreEqual(1, collectCalculationsPerSegment[firstSectionName].Count); Assert.AreSame(calculations[0], collectCalculationsPerSegment[firstSectionName][0]); Assert.AreEqual(1, collectCalculationsPerSegment[secondSectionName].Count); Assert.AreSame(calculations[1], collectCalculationsPerSegment[secondSectionName][0]); } [Test] public void FailureMechanismSectionForCalculation_SectionResultAndCalculationNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(null, null); // Assert Assert.Throws(call); } [Test] public void FailureMechanismSectionForCalculation_SectionResultsNull_ThrowsArgumentNullException() { // Setup var calculation = new GrassCoverErosionInwardsCalculation(); // Call TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(null, calculation); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("sections", paramName); } [Test] public void FailureMechanismSectionForCalculation_CalculationNull_ThrowsArgumentNullException() { // Call TestDelegate call = () => GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, null); // Assert string paramName = Assert.Throws(call).ParamName; Assert.AreEqual("calculation", paramName); } [Test] public void FailureMechanismSectionForCalculation_CalculationWithoutDikeProfile_ReturnsNull() { // Setup var calculation = new GrassCoverErosionInwardsCalculation(); // Call FailureMechanismSection failureMechanismSection = GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, calculation); // Assert Assert.IsNull(failureMechanismSection); } [Test] public void FailureMechanismSectionForCalculation_SectionResultsEmpty_ReturnsNull() { // Setup var calculation = new GrassCoverErosionInwardsCalculation(); // Call FailureMechanismSection failureMechanismSection = GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(oneSection, calculation); // Assert Assert.IsNull(failureMechanismSection); } [Test] public void FailureMechanismSectionForCalculation_ValidEmptySectionResults_ReturnsNull() { // Setup var emptySections = new FailureMechanismSection[0]; var calculation = new GrassCoverErosionInwardsCalculation(); // Call FailureMechanismSection failureMechanismSection = GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(emptySections, calculation); // Assert Assert.IsNull(failureMechanismSection); } [Test] public void FailureMechanismSectionForCalculation_FirstSectionResultContainsCalculation_FailureMechanismSectionOfFirstSectionResult() { // Setup var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(1.1, 2.2), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } }; // Call FailureMechanismSection failureMechanismSection = GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculation); // Assert Assert.AreSame(twoSections[0], failureMechanismSection); } [Test] public void FailureMechanismSectionForCalculation_SecondSectionResultContainsCalculation_FailureMechanismSectionOfSecondSectionResult() { // Setup var calculation = new GrassCoverErosionInwardsCalculation { InputParameters = { DikeProfile = new DikeProfile(new Point2D(50.0, 66.0), new RoughnessPoint[0], new Point2D[0], null, new DikeProfile.ConstructionProperties()) } }; // Call FailureMechanismSection failureMechanismSection = GrassCoverErosionInwardsHelper.FailureMechanismSectionForCalculation(twoSections, calculation); // Assert Assert.AreSame(twoSections[1], failureMechanismSection); } } }