Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs =================================================================== diff -u -r9ca2ce99f8b1d93fb1edde4e505b5acc5094a256 -reedbe33e302acab9e9e37fb3ab07ca34ec195846 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 9ca2ce99f8b1d93fb1edde4e505b5acc5094a256) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision eedbe33e302acab9e9e37fb3ab07ca34ec195846) @@ -20,13 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.Common.Data; using Ringtoets.Common.Data.Probabilistics; -using Ringtoets.HeightStructures.Data.TestUtil; namespace Ringtoets.HeightStructures.Data.Test { @@ -282,83 +282,118 @@ TestHelper.AssertAreEqualButNotSame(otherStructure.WidthFlowApertures, structure.WidthFlowApertures); } - [Test] - [TestCase(null)] - [TestCase("string")] - public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + [TestFixture] + private class HeightStructureEqualsTest : EqualsGuidelinesTestFixture { - // Setup - HeightStructure structure = new TestHeightStructure(); + protected override HeightStructure CreateObject() + { + return new HeightStructure(CreateConstructionProperties()); + } - // Call - bool isEqual = structure.Equals(other); + protected override DerivedHeightStructure CreateDerivedObject() + { + return new DerivedHeightStructure(CreateConstructionProperties()); + } - // Assert - Assert.IsFalse(isEqual); - } + private static IEnumerable GetUnequalTestCases() + { + foreach (ChangePropertyData changeSingleDataProperty in ChangeSingleDataProperties()) + { + HeightStructure.ConstructionProperties differentConstructionProperties = CreateConstructionProperties(); + changeSingleDataProperty.ActionToChangeProperty(differentConstructionProperties); - [Test] - public void Equals_ToItself_ReturnsTrue() - { - // Setup - HeightStructure structure = new TestHeightStructure(); + yield return new TestCaseData(new HeightStructure(differentConstructionProperties)) + .SetName(changeSingleDataProperty.PropertyName); + } + } - // Call - bool isEqual = structure.Equals(structure); + private static IEnumerable> ChangeSingleDataProperties() + { + var random = new Random(21); + RoundedDouble offset = random.NextRoundedDouble(); - // Assert - Assert.IsTrue(isEqual); - } + yield return new ChangePropertyData(cp => cp.Name = "Different Name", + "Name"); + yield return new ChangePropertyData(cp => cp.Id = "Different Id", + "Id"); + yield return new ChangePropertyData(cp => cp.Location = new Point2D(random.NextDouble(), random.NextDouble()), + "Location"); + yield return new ChangePropertyData(cp => cp.StructureNormalOrientation = random.NextRoundedDouble(), + "NormalOrientation"); + yield return new ChangePropertyData(cp => cp.LevelCrestStructure.Mean = cp.LevelCrestStructure.Mean + offset, + "LevelCrestStructureMean"); + yield return new ChangePropertyData(cp => cp.LevelCrestStructure.StandardDeviation = cp.LevelCrestStructure.StandardDeviation + offset, + "LevelCrestStructureStandardDeviation"); + yield return new ChangePropertyData(cp => cp.FlowWidthAtBottomProtection.Mean = cp.FlowWidthAtBottomProtection.Mean + offset, + "FlowWidthAtBottomProtectionMean"); + yield return new ChangePropertyData(cp => cp.FlowWidthAtBottomProtection.StandardDeviation = cp.FlowWidthAtBottomProtection.StandardDeviation + offset, + "FlowWidthAtBottomProtectionStandardDeviation"); + yield return new ChangePropertyData(cp => cp.CriticalOvertoppingDischarge.Mean = cp.CriticalOvertoppingDischarge.Mean + offset, + "CriticalOvertoppingDischargeMean"); + yield return new ChangePropertyData(cp => cp.CriticalOvertoppingDischarge.CoefficientOfVariation = cp.CriticalOvertoppingDischarge.CoefficientOfVariation + offset, + "CriticalOvertoppingDischargeCoefficientofVariation"); + yield return new ChangePropertyData(cp => cp.WidthFlowApertures.Mean = cp.WidthFlowApertures.Mean + offset, + "WidthFlowAperturesMean"); + yield return new ChangePropertyData(cp => cp.WidthFlowApertures.StandardDeviation = cp.WidthFlowApertures.StandardDeviation + offset, + "WidthFlowAperturesStandardDeviation"); + yield return new ChangePropertyData(cp => cp.FailureProbabilityStructureWithErosion = random.NextDouble(), + "FailureProbabilityStructureWithErosion"); + yield return new ChangePropertyData(cp => cp.StorageStructureArea.Mean = cp.StorageStructureArea.Mean + offset, + "StorageStructureAreaMean"); + yield return new ChangePropertyData(cp => cp.StorageStructureArea.CoefficientOfVariation = cp.StorageStructureArea.CoefficientOfVariation + offset, + "StorageStructureAreaCoefficientOfVariation"); + yield return new ChangePropertyData(cp => cp.AllowedLevelIncreaseStorage.Mean = cp.AllowedLevelIncreaseStorage.Mean + offset, + "AllowedLevelIncreaseStorageMean"); + yield return new ChangePropertyData(cp => cp.AllowedLevelIncreaseStorage.StandardDeviation = cp.AllowedLevelIncreaseStorage.StandardDeviation + offset, + "AllowedLevelIncreaseStorageStandardDeviation"); + } - [Test] - public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() - { - // Setup - HeightStructure structureX = new TestHeightStructure(); - HeightStructure structureY = new TestHeightStructure(); - HeightStructure structureZ = new TestHeightStructure(); - - // Call - bool isXEqualToY = structureX.Equals(structureY); - bool isYEqualToZ = structureY.Equals(structureZ); - bool isXEqualToZ = structureX.Equals(structureZ); - - // Assert - Assert.IsTrue(isXEqualToY); - Assert.IsTrue(isYEqualToZ); - Assert.IsTrue(isXEqualToZ); - } - - [Test] - [TestCaseSource(typeof(HeightStructurePermutationHelper), - nameof(HeightStructurePermutationHelper.DifferentHeightStructures), - new object[] + private static HeightStructure.ConstructionProperties CreateConstructionProperties() { - "Equals", - "ReturnsFalse" - })] - public void Equals_DifferentProperty_ReturnsFalse(HeightStructure structure) - { - // Call - bool isEqual = structure.Equals(new TestHeightStructure()); - - // Assert - Assert.IsFalse(isEqual); + return new HeightStructure.ConstructionProperties + { + Name = "Name", + Id = "Id", + Location = new Point2D(0.0, 0.0), + StructureNormalOrientation = (RoundedDouble) 0.12345, + LevelCrestStructure = + { + Mean = (RoundedDouble) 234.567, + StandardDeviation = (RoundedDouble) 0.23456 + }, + FlowWidthAtBottomProtection = + { + Mean = (RoundedDouble) 345.68, + StandardDeviation = (RoundedDouble) 0.35 + }, + CriticalOvertoppingDischarge = + { + Mean = (RoundedDouble) 456.79, + CoefficientOfVariation = (RoundedDouble) 0.46 + }, + WidthFlowApertures = + { + Mean = (RoundedDouble) 567.89, + StandardDeviation = (RoundedDouble) 0.57 + }, + FailureProbabilityStructureWithErosion = 0.67890, + StorageStructureArea = + { + Mean = (RoundedDouble) 112.22, + CoefficientOfVariation = (RoundedDouble) 0.11 + }, + AllowedLevelIncreaseStorage = + { + Mean = (RoundedDouble) 225.34, + StandardDeviation = (RoundedDouble) 0.23 + } + }; + } } - [Test] - public void GetHashCode_EqualStructures_ReturnsSameHashCode() + private class DerivedHeightStructure : HeightStructure { - // Setup - HeightStructure structureOne = new TestHeightStructure(); - HeightStructure structureTwo = new TestHeightStructure(); - - // Call - int hashCodeOne = structureOne.GetHashCode(); - int hashCodeTwo = structureTwo.GetHashCode(); - - // Assert - Assert.AreEqual(hashCodeOne, hashCodeTwo); + public DerivedHeightStructure(ConstructionProperties constructionProperties) : base(constructionProperties) {} } } } \ No newline at end of file