// Copyright (C) Stichting Deltares 2017. 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 Core.Common.TestUtil; using NUnit.Framework; namespace Ringtoets.ClosingStructures.Data.TestUtil { /// /// Helper containing a source of modified entities that can /// be used in tests as a TestCaseSource. /// public static class ClosingStructurePermutationHelper { /// /// Returns a collection of modified entities, which all differ /// except for their id. /// /// The name of the target to test while using the test case source. /// A description of the result of the test while using the test case source. /// The collection of test case data. /// /// [TestCaseSource(typeof(ClosingStructurePermutationHelper), /// nameof(ClosingStructurePermutationHelper.DifferentClosingStructuresWithSameId), /// new object[] /// { /// "TargetMethodName", /// "TestResult" /// })] /// public static IEnumerable DifferentClosingStructuresWithSameId(string targetName, string testResultDescription) { var referenceStructure = new TestClosingStructure(); var testCaseData = new List { new TestCaseData(new TestClosingStructure(referenceStructure.Id, "Different name")) .SetName($"{targetName}_DifferentName_{testResultDescription}"), new TestCaseData(new TestClosingStructure(new Point2D(1, 1), referenceStructure.Id)) .SetName($"{targetName}_DifferentLocation_{testResultDescription}") }; testCaseData.AddRange(DifferentClosingStructuresWithSameIdNameAndLocation(targetName, testResultDescription)); return testCaseData; } /// /// Returns a collection of modified entities, which all differ /// except for their id, name and location. /// /// The name of the target to test while using the test case source. /// A description of the result of the test while using the test case source. /// The collection of test case data. /// /// [TestCaseSource(typeof(ClosingStructurePermutationHelper), /// nameof(ClosingStructurePermutationHelper.DifferentClosingStructuresWithSameIdNameAndLocation), /// new object[] /// { /// "TargetMethodName", /// "TestResult" /// })] /// public static IEnumerable DifferentClosingStructuresWithSameIdNameAndLocation(string targetName, string testResultDescription) { var random = new Random(532); yield return new TestCaseData(new TestClosingStructure { AllowedLevelIncreaseStorage = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentAllowedLevelIncreaseStorage_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { AreaFlowApertures = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentAreaFlowApertures_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { CriticalOvertoppingDischarge = { Mean = random.NextRoundedDouble(), CoefficientOfVariation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentCriticalOvertoppingDischarge_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { FlowWidthAtBottomProtection = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentFlowWidthAtBottomProtection_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { InsideWaterLevel = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentInsideWaterLevel_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { LevelCrestStructureNotClosing = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentLevelCrestStructureNotClosing_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { StorageStructureArea = { Mean = random.NextRoundedDouble(), CoefficientOfVariation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentStorageStructureArea_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { ThresholdHeightOpenWeir = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentThresholdHeightOpenWeir_{testResultDescription}"); yield return new TestCaseData(new TestClosingStructure { WidthFlowApertures = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }).SetName($"{targetName}_DifferentWidthFlowApertures_{testResultDescription}"); ClosingStructure.ConstructionProperties differentFailureProbabilityReparationConstructionProperties = CreateTestClosingStructureConstructionProperties(); differentFailureProbabilityReparationConstructionProperties.FailureProbabilityReparation = random.NextDouble(); yield return new TestCaseData(new ClosingStructure(differentFailureProbabilityReparationConstructionProperties)) .SetName($"{targetName}_DifferentFailureProbabilityReparation_{testResultDescription}"); ClosingStructure.ConstructionProperties differentFailureProbabilityOpenStructureConstructionProperties = CreateTestClosingStructureConstructionProperties(); differentFailureProbabilityOpenStructureConstructionProperties.FailureProbabilityOpenStructure = random.NextDouble(); yield return new TestCaseData(new ClosingStructure(differentFailureProbabilityOpenStructureConstructionProperties)) .SetName($"{targetName}_DifferentFailureProbabilityOpenStructure_{testResultDescription}"); ClosingStructure.ConstructionProperties differentIdenticalAperturesProperties = CreateTestClosingStructureConstructionProperties(); differentIdenticalAperturesProperties.IdenticalApertures = random.Next(); yield return new TestCaseData(new ClosingStructure(differentIdenticalAperturesProperties)) .SetName($"{targetName}_DifferentIdenticalApertures_{testResultDescription}"); ClosingStructure.ConstructionProperties differentInflowModelTypeConstructionProperties = CreateTestClosingStructureConstructionProperties(); differentInflowModelTypeConstructionProperties.InflowModelType = random.NextEnumValue(); yield return new TestCaseData(new ClosingStructure(differentInflowModelTypeConstructionProperties)) .SetName($"{targetName}_DifferentInflowModelType_{testResultDescription}"); ClosingStructure.ConstructionProperties differentProbabilityOrFrequencyOpenStructureBeforeFloodingConstructionProperties = CreateTestClosingStructureConstructionProperties(); differentProbabilityOrFrequencyOpenStructureBeforeFloodingConstructionProperties.ProbabilityOrFrequencyOpenStructureBeforeFlooding = random.NextDouble(); yield return new TestCaseData(new ClosingStructure(differentProbabilityOrFrequencyOpenStructureBeforeFloodingConstructionProperties)) .SetName($"{targetName}_DifferentProbabilityOrFrequencyOpenStructureBeforeFlooding_{testResultDescription}"); ClosingStructure.ConstructionProperties differentStructureNormalOrientationConstructionProperties = CreateTestClosingStructureConstructionProperties(); differentStructureNormalOrientationConstructionProperties.StructureNormalOrientation = random.NextRoundedDouble(); yield return new TestCaseData(new ClosingStructure(differentStructureNormalOrientationConstructionProperties)) .SetName($"{targetName}_DifferentStructureNormalOrientation_{testResultDescription}"); } private static ClosingStructure.ConstructionProperties CreateTestClosingStructureConstructionProperties() { var referenceStructure = new TestClosingStructure(); return new ClosingStructure.ConstructionProperties { Name = referenceStructure.Name, Id = referenceStructure.Id, Location = referenceStructure.Location, AllowedLevelIncreaseStorage = { Mean = referenceStructure.AllowedLevelIncreaseStorage.Mean, StandardDeviation = referenceStructure.AllowedLevelIncreaseStorage.StandardDeviation }, AreaFlowApertures = { Mean = referenceStructure.AreaFlowApertures.Mean, StandardDeviation = referenceStructure.AreaFlowApertures.StandardDeviation }, CriticalOvertoppingDischarge = { Mean = referenceStructure.CriticalOvertoppingDischarge.Mean, CoefficientOfVariation = referenceStructure.CriticalOvertoppingDischarge.CoefficientOfVariation }, FlowWidthAtBottomProtection = { Mean = referenceStructure.FlowWidthAtBottomProtection.Mean, StandardDeviation = referenceStructure.FlowWidthAtBottomProtection.StandardDeviation }, InsideWaterLevel = { Mean = referenceStructure.InsideWaterLevel.Mean, StandardDeviation = referenceStructure.InsideWaterLevel.StandardDeviation }, LevelCrestStructureNotClosing = { Mean = referenceStructure.LevelCrestStructureNotClosing.Mean, StandardDeviation = referenceStructure.LevelCrestStructureNotClosing.StandardDeviation }, StorageStructureArea = { Mean = referenceStructure.StorageStructureArea.Mean, CoefficientOfVariation = referenceStructure.StorageStructureArea.CoefficientOfVariation }, ThresholdHeightOpenWeir = { Mean = referenceStructure.ThresholdHeightOpenWeir.Mean, StandardDeviation = referenceStructure.ThresholdHeightOpenWeir.StandardDeviation }, WidthFlowApertures = { Mean = referenceStructure.WidthFlowApertures.Mean, StandardDeviation = referenceStructure.WidthFlowApertures.StandardDeviation }, FailureProbabilityReparation = referenceStructure.FailureProbabilityReparation, FailureProbabilityOpenStructure = referenceStructure.FailureProbabilityOpenStructure, IdenticalApertures = referenceStructure.IdenticalApertures, InflowModelType = referenceStructure.InflowModelType, ProbabilityOrFrequencyOpenStructureBeforeFlooding = referenceStructure.ProbabilityOrFrequencyOpenStructureBeforeFlooding, StructureNormalOrientation = referenceStructure.StructureNormalOrientation }; } } }