Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs =================================================================== diff -u -r88d043d47b0976fe2e58c10babb5322b605b16da -r25078f3b8ee4f3007979c40275a1964013adb483 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 88d043d47b0976fe2e58c10babb5322b605b16da) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 25078f3b8ee4f3007979c40275a1964013adb483) @@ -20,132 +20,18 @@ // All rights reserved. using System; -using System.Collections.Generic; -using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using NUnit.Framework; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Probabilistics; +using Ringtoets.HeightStructures.Data.TestUtil; namespace Ringtoets.HeightStructures.Data.Test { [TestFixture] public class HeightStructureTest { - private static IEnumerable StructureCombinations - { - get - { - return GetInequalStructures.Concat(GetEqualStructures); - } - } - - private static IEnumerable GetEqualStructures - { - get - { - HeightStructure structure = CreateFullyDefinedStructure(); - yield return new TestCaseData(structure, structure, true) - .SetName("SameStructure"); - yield return new TestCaseData(structure, CreateFullyDefinedStructure(), true) - .SetName("EqualStructure"); - } - } - - private static IEnumerable GetInequalStructures - { - get - { - HeightStructure structure = CreateFullyDefinedStructure(); - - HeightStructure.ConstructionProperties differentId = CreateFullyConfiguredConstructionProperties(); - differentId.Id = "differentId"; - yield return new TestCaseData(structure, new HeightStructure(differentId), false) - .SetName(nameof(differentId)); - - HeightStructure.ConstructionProperties differentName = CreateFullyConfiguredConstructionProperties(); - differentName.Name = "differentName"; - yield return new TestCaseData(structure, new HeightStructure(differentName), false) - .SetName(nameof(differentName)); - - HeightStructure.ConstructionProperties differentLocation = CreateFullyConfiguredConstructionProperties(); - differentLocation.Location = new Point2D(9, 9); - yield return new TestCaseData(structure, new HeightStructure(differentLocation), false) - .SetName(nameof(differentLocation)); - - HeightStructure.ConstructionProperties differentOrientation = CreateFullyConfiguredConstructionProperties(); - differentOrientation.StructureNormalOrientation = (RoundedDouble) 90; - yield return new TestCaseData(structure, new HeightStructure(differentOrientation), false) - .SetName(nameof(differentOrientation)); - - HeightStructure.ConstructionProperties differentAllowedLevelIncreaseStorageMean = CreateFullyConfiguredConstructionProperties(); - differentAllowedLevelIncreaseStorageMean.AllowedLevelIncreaseStorage.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentAllowedLevelIncreaseStorageMean), false) - .SetName(nameof(differentAllowedLevelIncreaseStorageMean)); - - HeightStructure.ConstructionProperties differentAllowedLevelIncreaseStorageStandardDeviation = CreateFullyConfiguredConstructionProperties(); - differentAllowedLevelIncreaseStorageStandardDeviation.AllowedLevelIncreaseStorage.StandardDeviation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentAllowedLevelIncreaseStorageStandardDeviation), false) - .SetName(nameof(differentAllowedLevelIncreaseStorageStandardDeviation)); - - HeightStructure.ConstructionProperties differentCriticalOvertoppingDischargeMean = CreateFullyConfiguredConstructionProperties(); - differentCriticalOvertoppingDischargeMean.CriticalOvertoppingDischarge.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentCriticalOvertoppingDischargeMean), false) - .SetName(nameof(differentCriticalOvertoppingDischargeMean)); - - HeightStructure.ConstructionProperties differentCriticalOvertoppingDischargeCoefficientOfVariation = CreateFullyConfiguredConstructionProperties(); - differentCriticalOvertoppingDischargeCoefficientOfVariation.CriticalOvertoppingDischarge.CoefficientOfVariation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentCriticalOvertoppingDischargeCoefficientOfVariation), false) - .SetName(nameof(differentCriticalOvertoppingDischargeCoefficientOfVariation)); - - HeightStructure.ConstructionProperties differentFailureProbabilityStructureWithErosion = CreateFullyConfiguredConstructionProperties(); - differentFailureProbabilityStructureWithErosion.FailureProbabilityStructureWithErosion = 987; - yield return new TestCaseData(structure, new HeightStructure(differentFailureProbabilityStructureWithErosion), false) - .SetName(nameof(differentFailureProbabilityStructureWithErosion)); - - HeightStructure.ConstructionProperties differentFlowWidthAtBottomProtectionMean = CreateFullyConfiguredConstructionProperties(); - differentFlowWidthAtBottomProtectionMean.FlowWidthAtBottomProtection.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentFlowWidthAtBottomProtectionMean), false) - .SetName(nameof(differentFlowWidthAtBottomProtectionMean)); - - HeightStructure.ConstructionProperties differentFlowWidthAtBottomProtectionStandardDeviation = CreateFullyConfiguredConstructionProperties(); - differentFlowWidthAtBottomProtectionStandardDeviation.FlowWidthAtBottomProtection.StandardDeviation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentFlowWidthAtBottomProtectionStandardDeviation), false) - .SetName(nameof(differentFlowWidthAtBottomProtectionStandardDeviation)); - - HeightStructure.ConstructionProperties differentLevelCrestStructureMean = CreateFullyConfiguredConstructionProperties(); - differentLevelCrestStructureMean.LevelCrestStructure.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentLevelCrestStructureMean), false) - .SetName(nameof(differentLevelCrestStructureMean)); - - HeightStructure.ConstructionProperties differentLevelCrestStructureStandardDeviation = CreateFullyConfiguredConstructionProperties(); - differentLevelCrestStructureStandardDeviation.LevelCrestStructure.StandardDeviation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentLevelCrestStructureStandardDeviation), false) - .SetName(nameof(differentLevelCrestStructureStandardDeviation)); - - HeightStructure.ConstructionProperties differentStorageStructureAreaMean = CreateFullyConfiguredConstructionProperties(); - differentStorageStructureAreaMean.StorageStructureArea.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentStorageStructureAreaMean), false) - .SetName(nameof(differentStorageStructureAreaMean)); - - HeightStructure.ConstructionProperties differentStorageStructureAreaCoefficientOfVariation = CreateFullyConfiguredConstructionProperties(); - differentStorageStructureAreaCoefficientOfVariation.StorageStructureArea.CoefficientOfVariation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentStorageStructureAreaCoefficientOfVariation), false) - .SetName(nameof(differentStorageStructureAreaCoefficientOfVariation)); - - HeightStructure.ConstructionProperties differentWidthFlowAperturesMean = CreateFullyConfiguredConstructionProperties(); - differentWidthFlowAperturesMean.WidthFlowApertures.Mean = (RoundedDouble) 10.1; - yield return new TestCaseData(structure, new HeightStructure(differentWidthFlowAperturesMean), false) - .SetName(nameof(differentWidthFlowAperturesMean)); - - HeightStructure.ConstructionProperties differentWidthFlowAperturesStandardDeviation = CreateFullyConfiguredConstructionProperties(); - differentWidthFlowAperturesStandardDeviation.WidthFlowApertures.StandardDeviation = (RoundedDouble) 0.1; - yield return new TestCaseData(structure, new HeightStructure(differentWidthFlowAperturesStandardDeviation), false) - .SetName(nameof(differentWidthFlowAperturesStandardDeviation)); - } - } - [Test] public void Constructor_ValidData_ExpectedValues() { @@ -418,7 +304,7 @@ public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) { // Setup - HeightStructure structure = CreateFullyDefinedStructure(); + HeightStructure structure = new TestHeightStructure(); // Call bool isEqual = structure.Equals(other); @@ -428,12 +314,25 @@ } [Test] + public void Equals_ToItself_ReturnsTrue() + { + // Setup + HeightStructure structure = new TestHeightStructure(); + + // Call + bool isEqual = structure.Equals(structure); + + // Assert + Assert.IsTrue(isEqual); + } + + [Test] public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() { // Setup - HeightStructure structureX = CreateFullyDefinedStructure(); - HeightStructure structureY = CreateFullyDefinedStructure(); - HeightStructure structureZ = CreateFullyDefinedStructure(); + HeightStructure structureX = new TestHeightStructure(); + HeightStructure structureY = new TestHeightStructure(); + HeightStructure structureZ = new TestHeightStructure(); // Call bool isXEqualToY = structureX.Equals(structureY); @@ -447,26 +346,28 @@ } [Test] - [TestCaseSource(nameof(StructureCombinations))] - public void Equals_DifferentProperty_ReturnsIsEqual(HeightStructure structure, - HeightStructure otherStructure, - bool expectedToBeEqual) + [TestCaseSource(typeof(HeightStructurePermutationHelper), + nameof(HeightStructurePermutationHelper.DifferentHeightStructures), + new object[] + { + "Equals", + "ReturnsFalse" + })] + public void Equals_DifferentProperty_ReturnsFalse(HeightStructure structure) { // Call - bool isStructureEqualToOther = structure.Equals(otherStructure); - bool isOtherEqualToStructure = otherStructure.Equals(structure); + bool isEqual = structure.Equals(new TestHeightStructure()); // Assert - Assert.AreEqual(expectedToBeEqual, isStructureEqualToOther); - Assert.AreEqual(expectedToBeEqual, isOtherEqualToStructure); + Assert.IsFalse(isEqual); } [Test] public void GetHashCode_EqualStructures_ReturnsSameHashCode() { // Setup - HeightStructure structureOne = CreateFullyDefinedStructure(); - HeightStructure structureTwo = CreateFullyDefinedStructure(); + HeightStructure structureOne = new TestHeightStructure(); + HeightStructure structureTwo = new TestHeightStructure(); // Call int hashCodeOne = structureOne.GetHashCode(); @@ -475,54 +376,5 @@ // Assert Assert.AreEqual(hashCodeOne, hashCodeTwo); } - - private static HeightStructure CreateFullyDefinedStructure() - { - return new HeightStructure(CreateFullyConfiguredConstructionProperties()); - } - - private static HeightStructure.ConstructionProperties CreateFullyConfiguredConstructionProperties() - { - const string id = "structure id"; - const string name = "Structure name"; - return new HeightStructure.ConstructionProperties - { - Id = id, - Name = name, - Location = new Point2D(1, 1), - StructureNormalOrientation = (RoundedDouble) 25, - LevelCrestStructure = - { - Mean = (RoundedDouble) 1, - StandardDeviation = (RoundedDouble) 0.51 - }, - FlowWidthAtBottomProtection = - { - Mean = (RoundedDouble) 2, - StandardDeviation = (RoundedDouble) 0.52 - }, - CriticalOvertoppingDischarge = - { - Mean = (RoundedDouble) 3, - CoefficientOfVariation = (RoundedDouble) 0.53 - }, - WidthFlowApertures = - { - Mean = (RoundedDouble) 4, - StandardDeviation = (RoundedDouble) 0.54 - }, - StorageStructureArea = - { - Mean = (RoundedDouble) 5, - CoefficientOfVariation = (RoundedDouble) 0.55 - }, - AllowedLevelIncreaseStorage = - { - Mean = (RoundedDouble) 6, - StandardDeviation = (RoundedDouble) 0.56 - }, - FailureProbabilityStructureWithErosion = 9 - }; - } } } \ No newline at end of file