Index: Ringtoets/Common/src/Ringtoets.Common.Data/StructureBase.cs =================================================================== diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/src/Ringtoets.Common.Data/StructureBase.cs (.../StructureBase.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2) +++ Ringtoets/Common/src/Ringtoets.Common.Data/StructureBase.cs (.../StructureBase.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -80,6 +80,41 @@ /// public RoundedDouble StructureNormalOrientation { get; private set; } + public override string ToString() + { + return Name; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + { + return false; + } + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((StructureBase) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Name.GetHashCode(); + hashCode = (hashCode * 397) ^ Id.GetHashCode(); + hashCode = (hashCode * 397) ^ Location.GetHashCode(); + hashCode = (hashCode * 397) ^ StructureNormalOrientation.GetHashCode(); + + return hashCode; + } + } + /// /// Copies the property values of the to the /// . @@ -100,9 +135,12 @@ StructureNormalOrientation = fromStructure.StructureNormalOrientation; } - public override string ToString() + private bool Equals(StructureBase other) { - return Name; + return Id.Equals(other.Id) + && Name.Equals(other.Name) + && Location.Equals(other.Location) + && StructureNormalOrientation.Equals(other.StructureNormalOrientation); } /// Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs =================================================================== diff -u -r4ed7d0e47818a186806b494223fce3807eca3ab4 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs (.../LogNormalDistributionTest.cs) (revision 4ed7d0e47818a186806b494223fce3807eca3ab4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/LogNormalDistributionTest.cs (.../LogNormalDistributionTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -250,10 +250,10 @@ LogNormalDistribution distribution = CreateFullyDefinedDistribution(); // Call - bool isEqualToNull = distribution.Equals(other); + bool isEqual = distribution.Equals(other); // Assert - Assert.IsFalse(isEqualToNull); + Assert.IsFalse(isEqual); } [Test] @@ -277,7 +277,7 @@ [Test] [TestCaseSource(nameof(DistributionCombinations))] - public void Equal_DifferentProperty_RetunsFalse(LogNormalDistribution distribution, + public void Equal_DifferentProperty_RetunsIsEqual(LogNormalDistribution distribution, LogNormalDistribution otherDistribution, bool expectedToBeEqual) { Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionTest.cs =================================================================== diff -u -r4ed7d0e47818a186806b494223fce3807eca3ab4 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionTest.cs (.../NormalDistributionTest.cs) (revision 4ed7d0e47818a186806b494223fce3807eca3ab4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/NormalDistributionTest.cs (.../NormalDistributionTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -171,10 +171,10 @@ NormalDistribution distribution = CreateFullyDefinedDistribution(); // Call - bool isEqualToNull = distribution.Equals(other); + bool isEqual = distribution.Equals(other); // Assert - Assert.IsFalse(isEqualToNull); + Assert.IsFalse(isEqual); } [Test] @@ -198,7 +198,7 @@ [Test] [TestCaseSource(nameof(DistributionCombinations))] - public void Equal_DifferentProperty_RetunsFalse(NormalDistribution distribution, + public void Equal_DifferentProperty_RetunsIsEqual(NormalDistribution distribution, NormalDistribution otherDistribution, bool expectedToBeEqual) { Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs =================================================================== diff -u -r4ed7d0e47818a186806b494223fce3807eca3ab4 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs (.../VariationCoefficientLogNormalDistributionTest.cs) (revision 4ed7d0e47818a186806b494223fce3807eca3ab4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientLogNormalDistributionTest.cs (.../VariationCoefficientLogNormalDistributionTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -198,10 +198,10 @@ VariationCoefficientLogNormalDistribution distribution = CreateFullyDefinedDistribution(); // Call - bool isEqualToNull = distribution.Equals(other); + bool isEqual = distribution.Equals(other); // Assert - Assert.IsFalse(isEqualToNull); + Assert.IsFalse(isEqual); } [Test] @@ -225,7 +225,7 @@ [Test] [TestCaseSource(nameof(DistributionCombinations))] - public void Equal_DifferentProperty_RetunsFalse(VariationCoefficientLogNormalDistribution distribution, + public void Equal_DifferentProperty_RetunsIsEqual(VariationCoefficientLogNormalDistribution distribution, VariationCoefficientLogNormalDistribution otherDistribution, bool expectedToBeEqual) { Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientNormalDistributionTest.cs =================================================================== diff -u -r4ed7d0e47818a186806b494223fce3807eca3ab4 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientNormalDistributionTest.cs (.../VariationCoefficientNormalDistributionTest.cs) (revision 4ed7d0e47818a186806b494223fce3807eca3ab4) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/Probabilistics/VariationCoefficientNormalDistributionTest.cs (.../VariationCoefficientNormalDistributionTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -180,10 +180,10 @@ VariationCoefficientNormalDistribution distribution = CreateFullyDefinedDistribution(); // Call - bool isEqualToNull = distribution.Equals(other); + bool isEqual = distribution.Equals(other); // Assert - Assert.IsFalse(isEqualToNull); + Assert.IsFalse(isEqual); } [Test] @@ -207,7 +207,7 @@ [Test] [TestCaseSource(nameof(DistributionCombinations))] - public void Equal_DifferentProperty_RetunsFalse(VariationCoefficientNormalDistribution distribution, + public void Equal_DifferentProperty_RetunsIsEqual(VariationCoefficientNormalDistribution distribution, VariationCoefficientNormalDistribution otherDistribution, bool expectedToBeEqual) { Index: Ringtoets/Common/test/Ringtoets.Common.Data.Test/StructureBaseTest.cs =================================================================== diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/Common/test/Ringtoets.Common.Data.Test/StructureBaseTest.cs (.../StructureBaseTest.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2) +++ Ringtoets/Common/test/Ringtoets.Common.Data.Test/StructureBaseTest.cs (.../StructureBaseTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Collections.Generic; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.TestUtil; @@ -31,6 +32,38 @@ [TestFixture] public class StructureBaseTest { + private static IEnumerable StructureCombinations + { + get + { + StructureBase structure = CreateFullyDefinedStructure(); + yield return new TestCaseData(structure, structure, true) + .SetName("SameStructure"); + yield return new TestCaseData(structure, CreateFullyDefinedStructure(), true) + .SetName("EqualStructure"); + + StructureBase.ConstructionProperties differentId = CreateFullyConfiguredConstructionProperties(); + differentId.Id = "differentId"; + yield return new TestCaseData(structure, new TestStructure(differentId), false) + .SetName(nameof(differentId)); + + StructureBase.ConstructionProperties differentName = CreateFullyConfiguredConstructionProperties(); + differentName.Name = "differentName"; + yield return new TestCaseData(structure, new TestStructure(differentName), false) + .SetName(nameof(differentName)); + + StructureBase.ConstructionProperties differentLocation = CreateFullyConfiguredConstructionProperties(); + differentLocation.Location = new Point2D(9, 9); + yield return new TestCaseData(structure, new TestStructure(differentLocation), false) + .SetName(nameof(differentLocation)); + + StructureBase.ConstructionProperties differentOrientation = CreateFullyConfiguredConstructionProperties(); + differentOrientation.StructureNormalOrientation = (RoundedDouble) 90; + yield return new TestCaseData(structure, new TestStructure(differentOrientation), false) + .SetName(nameof(differentOrientation)); + } + } + [Test] [TestCase(null)] [TestCase("")] @@ -186,6 +219,88 @@ Assert.AreEqual(structure.StructureNormalOrientation, otherStructure.StructureNormalOrientation); } + [Test] + [TestCase(null)] + [TestCase("string")] + public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + { + // Setup + StructureBase structure = CreateFullyDefinedStructure(); + + // Call + bool isEqualToDifferentObject = structure.Equals(other); + + // Assert + Assert.IsFalse(isEqualToDifferentObject); + } + + [Test] + public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() + { + // Setup + StructureBase structureX = CreateFullyDefinedStructure(); + StructureBase structureY = CreateFullyDefinedStructure(); + StructureBase structureZ = CreateFullyDefinedStructure(); + + // 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(nameof(StructureCombinations))] + public void Equal_DifferentProperty_RetunsIsEqual(StructureBase structure, + StructureBase otherStructure, + bool expectedToBeEqual) + { + // Call + bool isStructureEqualToOther = structure.Equals(otherStructure); + bool isOtherEqualToStructure = otherStructure.Equals(structure); + + // Assert + Assert.AreEqual(expectedToBeEqual, isStructureEqualToOther); + Assert.AreEqual(expectedToBeEqual, isOtherEqualToStructure); + } + + [Test] + public void GetHashCode_EqualStructures_ReturnsSameHashCode() + { + // Setup + StructureBase structureOne = CreateFullyDefinedStructure(); + StructureBase structureTwo = CreateFullyDefinedStructure(); + + // Call + int hashCodeOne = structureOne.GetHashCode(); + int hashCodeTwo = structureTwo.GetHashCode(); + + // Assert + Assert.AreEqual(hashCodeOne, hashCodeTwo); + } + + private static StructureBase CreateFullyDefinedStructure() + { + return new TestStructure(CreateFullyConfiguredConstructionProperties()); + } + + private static StructureBase.ConstructionProperties CreateFullyConfiguredConstructionProperties() + { + const string id = "structure id"; + const string name = "Structure name"; + return new StructureBase.ConstructionProperties + { + Id = id, + Name = name, + Location = new Point2D(1, 1), + StructureNormalOrientation = (RoundedDouble) 25 + }; + } + private class TestStructure : StructureBase { public TestStructure(ConstructionProperties constructionProperties) : base(constructionProperties) {} Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs =================================================================== diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Data/HeightStructure.cs (.../HeightStructure.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -151,6 +151,39 @@ WidthFlowApertures.StandardDeviation = fromStructure.WidthFlowApertures.StandardDeviation; } + public override bool Equals(object obj) + { + return base.Equals(obj) && Equals((HeightStructure) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = base.GetHashCode(); + hashCode = (hashCode * 397) ^ AllowedLevelIncreaseStorage.GetHashCode(); + hashCode = (hashCode * 397) ^ CriticalOvertoppingDischarge.GetHashCode(); + hashCode = (hashCode * 397) ^ FailureProbabilityStructureWithErosion.GetHashCode(); + hashCode = (hashCode * 397) ^ FlowWidthAtBottomProtection.GetHashCode(); + hashCode = (hashCode * 397) ^ LevelCrestStructure.GetHashCode(); + hashCode = (hashCode * 397) ^ StorageStructureArea.GetHashCode(); + hashCode = (hashCode * 397) ^ WidthFlowApertures.GetHashCode(); + + return hashCode; + } + } + + private bool Equals(HeightStructure other) + { + return AllowedLevelIncreaseStorage.Equals(other.AllowedLevelIncreaseStorage) + && CriticalOvertoppingDischarge.Equals(other.CriticalOvertoppingDischarge) + && FailureProbabilityStructureWithErosion.Equals(other.FailureProbabilityStructureWithErosion) + && FlowWidthAtBottomProtection.Equals(other.FlowWidthAtBottomProtection) + && LevelCrestStructure.Equals(other.LevelCrestStructure) + && StorageStructureArea.Equals(other.StorageStructureArea) + && WidthFlowApertures.Equals(other.WidthFlowApertures); + } + /// /// Class holding the various construction parameters for . /// Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs =================================================================== diff -u -r064653222d1d4df89ac7c644f2227f2fe0aa2070 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision 064653222d1d4df89ac7c644f2227f2fe0aa2070) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/FileImporters/HeightStructureUpdateDataStrategy.cs (.../HeightStructureUpdateDataStrategy.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -120,7 +120,6 @@ affectedObjects.Add(affectedCalculation.InputParameters); if (affectedCalculation.HasOutput) { - affectedObjects.Add(affectedCalculation); affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(affectedCalculation)); } } Index: Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs =================================================================== diff -u -r4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2 -rce24d4fc808e32e5cebe7114ab03919770240d07 --- Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision 4954f3a3c5eab3aff1b2d4c5a58364f06fe4bbd2) +++ Ringtoets/HeightStructures/test/Ringtoets.HeightStructures.Data.Test/HeightStructureTest.cs (.../HeightStructureTest.cs) (revision ce24d4fc808e32e5cebe7114ab03919770240d07) @@ -20,6 +20,8 @@ // 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; @@ -31,6 +33,119 @@ [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() { @@ -41,7 +156,9 @@ var heightStructure = new HeightStructure( new HeightStructure.ConstructionProperties { - Name = "aName", Id = "anId", Location = location, + Name = "aName", + Id = "anId", + Location = location, StructureNormalOrientation = (RoundedDouble) 0.12345, LevelCrestStructure = { @@ -240,24 +357,137 @@ Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Mean, structure.AllowedLevelIncreaseStorage.Mean); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.StandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation); Assert.AreEqual(structure.AllowedLevelIncreaseStorage.Shift, structure.AllowedLevelIncreaseStorage.Shift); - + Assert.AreEqual(structure.CriticalOvertoppingDischarge.Mean, structure.CriticalOvertoppingDischarge.Mean); Assert.AreEqual(structure.CriticalOvertoppingDischarge.CoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation); - + Assert.AreEqual(structure.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); - + Assert.AreEqual(structure.FlowWidthAtBottomProtection.Mean, structure.FlowWidthAtBottomProtection.Mean); Assert.AreEqual(structure.FlowWidthAtBottomProtection.StandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation); Assert.AreEqual(structure.FlowWidthAtBottomProtection.Shift, structure.FlowWidthAtBottomProtection.Shift); - + Assert.AreEqual(structure.LevelCrestStructure.Mean, structure.LevelCrestStructure.Mean); Assert.AreEqual(structure.LevelCrestStructure.StandardDeviation, structure.LevelCrestStructure.StandardDeviation); - + Assert.AreEqual(structure.StorageStructureArea.Mean, structure.StorageStructureArea.Mean); Assert.AreEqual(structure.StorageStructureArea.CoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation); - + Assert.AreEqual(structure.WidthFlowApertures.Mean, structure.WidthFlowApertures.Mean); Assert.AreEqual(structure.WidthFlowApertures.StandardDeviation, structure.WidthFlowApertures.StandardDeviation); } + + [Test] + [TestCase(null)] + [TestCase("string")] + public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + { + // Setup + HeightStructure structure = CreateFullyDefinedStructure(); + + // Call + bool isEqual = structure.Equals(other); + + // Assert + Assert.IsFalse(isEqual); + } + + [Test] + public void Equals_TransitivePropertyAllPropertiesEqual_ReturnsTrue() + { + // Setup + HeightStructure structureX = CreateFullyDefinedStructure(); + HeightStructure structureY = CreateFullyDefinedStructure(); + HeightStructure structureZ = CreateFullyDefinedStructure(); + + // 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(nameof(StructureCombinations))] + public void Equal_DifferentProperty_RetunsIsEqual(HeightStructure structure, + HeightStructure otherStructure, + bool expectedToBeEqual) + { + // Call + bool isStructureEqualToOther = structure.Equals(otherStructure); + bool isOtherEqualToStructure = otherStructure.Equals(structure); + + // Assert + Assert.AreEqual(expectedToBeEqual, isStructureEqualToOther); + Assert.AreEqual(expectedToBeEqual, isOtherEqualToStructure); + } + + [Test] + public void GetHashCode_EqualStructures_ReturnsSameHashCode() + { + // Setup + HeightStructure structureOne = CreateFullyDefinedStructure(); + HeightStructure structureTwo = CreateFullyDefinedStructure(); + + // Call + int hashCodeOne = structureOne.GetHashCode(); + int hashCodeTwo = structureTwo.GetHashCode(); + + // 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