Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPhreaticLineTest.cs =================================================================== diff -u -r1aa559e52bc5cea607d34b0a4675d2074f808c83 -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPhreaticLineTest.cs (.../MacroStabilityInwardsPhreaticLineTest.cs) (revision 1aa559e52bc5cea607d34b0a4675d2074f808c83) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsPhreaticLineTest.cs (.../MacroStabilityInwardsPhreaticLineTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; namespace Ringtoets.MacroStabilityInwards.Primitives.Test @@ -73,100 +74,59 @@ }, phreaticLine.Geometry); } - [Test] - [TestCase(null)] - [TestCase("string")] - public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + private class DerivedMacroStabilityInwardsPhreaticLine : MacroStabilityInwardsPhreaticLine { - // Setup - MacroStabilityInwardsPhreaticLine phreaticLine = CreatePhreaticLine(); - - // Call - bool isEqualToDifferentObject = phreaticLine.Equals(other); - - // Assert - Assert.IsFalse(isEqualToDifferentObject); + public DerivedMacroStabilityInwardsPhreaticLine(MacroStabilityInwardsPhreaticLine line) + : base(line.Name, line.Geometry) {} } - [Test] - public void Equals_AllPropertiesEqual_ReturnsTrue() + [TestFixture] + private class MacroStabilityInwardsPhreaticLineEqualsTest + : EqualsGuidelinesTestFixture { - // Setup - MacroStabilityInwardsPhreaticLine phreaticLineX = CreatePhreaticLine(); - MacroStabilityInwardsPhreaticLine phreaticLineY = CreatePhreaticLine(); + protected override MacroStabilityInwardsPhreaticLine CreateObject() + { + return CreatePhreaticLine(); + } - // Call - bool isXEqualToY = phreaticLineX.Equals(phreaticLineY); - bool isYEqualToZ = phreaticLineY.Equals(phreaticLineX); + protected override DerivedMacroStabilityInwardsPhreaticLine CreateDerivedObject() + { + return new DerivedMacroStabilityInwardsPhreaticLine(CreatePhreaticLine()); + } - // Assert - Assert.IsTrue(isXEqualToY); - Assert.IsTrue(isYEqualToZ); - } + public static IEnumerable GetUnequalTestCases() + { + MacroStabilityInwardsPhreaticLine baseLine = CreatePhreaticLine(); - [Test] - [TestCaseSource(nameof(GetPhreaticLineCombinations))] - public void Equals_DifferentProperty_ReturnsFalse(MacroStabilityInwardsPhreaticLine phreaticLine, - MacroStabilityInwardsPhreaticLine otherPhreaticLine) - { - // Call - bool isPhreaticLineEqualToOther = phreaticLine.Equals(otherPhreaticLine); - bool isOtherEqualToPhreaticLine = otherPhreaticLine.Equals(phreaticLine); + yield return new TestCaseData(new MacroStabilityInwardsPhreaticLine("Other name", baseLine.Geometry)) + .SetName("Other name"); - // Assert - Assert.IsFalse(isPhreaticLineEqualToOther); - Assert.IsFalse(isOtherEqualToPhreaticLine); - } + yield return new TestCaseData(new MacroStabilityInwardsPhreaticLine(baseLine.Name, new[] + { + new Point2D(0, 0), + new Point2D(1, 1), + new Point2D(1, 1) + })) + .SetName("Geometry point count"); - [Test] - public void GetHashCode_EqualPhreaticLines_ReturnsSameHashCode() - { - // Setup - MacroStabilityInwardsPhreaticLine phreaticLineX = CreatePhreaticLine(); - MacroStabilityInwardsPhreaticLine phreaticLineY = CreatePhreaticLine(); + yield return new TestCaseData(new MacroStabilityInwardsPhreaticLine(baseLine.Name, new[] + { + new Point2D(0, 0), + new Point2D(2, 2) + })) + .SetName("Geometry coordinates"); + } - // Call - int hashCodeOne = phreaticLineX.GetHashCode(); - int hashCodeTwo = phreaticLineY.GetHashCode(); - - // Assert - Assert.AreEqual(hashCodeOne, hashCodeTwo); + public static MacroStabilityInwardsPhreaticLine CreatePhreaticLine() + { + return new MacroStabilityInwardsPhreaticLine( + "Test", + new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }); + } } - - private static IEnumerable GetPhreaticLineCombinations() - { - yield return new TestCaseData(CreatePhreaticLine(), - new MacroStabilityInwardsPhreaticLine("Other name", new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - })).SetName("Other name"); - - yield return new TestCaseData(CreatePhreaticLine(), - new MacroStabilityInwardsPhreaticLine("Test", new[] - { - new Point2D(0, 0), - new Point2D(1, 1), - new Point2D(1, 1) - })).SetName("Geometry not same length"); - - yield return new TestCaseData(CreatePhreaticLine(), - new MacroStabilityInwardsPhreaticLine("Test", new[] - { - new Point2D(0, 0), - new Point2D(2, 2) - })).SetName("Geometry not same coordinates"); - } - - private static MacroStabilityInwardsPhreaticLine CreatePhreaticLine() - { - return new MacroStabilityInwardsPhreaticLine( - "Test", - new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - }); - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayer2DTest.cs =================================================================== diff -u -reb6d3b69267f3ae2870b25679793bbc0099338cd -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayer2DTest.cs (.../MacroStabilityInwardsSoilLayer2DTest.cs) (revision eb6d3b69267f3ae2870b25679793bbc0099338cd) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayer2DTest.cs (.../MacroStabilityInwardsSoilLayer2DTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -118,206 +118,70 @@ Assert.AreSame(nestedLayers, layer.NestedLayers); } - [Test] - public void GetHashCode_EqualLayers_AreEqual() - { - // Setup - MacroStabilityInwardsSoilLayer2D layerA = CreateRandomLayer(21); - MacroStabilityInwardsSoilLayer2D layerB = CreateRandomLayer(21); - // Precondition - Assert.AreEqual(layerA, layerB); - Assert.AreEqual(layerB, layerA); - - // Call & Assert - Assert.AreEqual(layerA.GetHashCode(), layerB.GetHashCode()); - Assert.AreEqual(layerB.GetHashCode(), layerA.GetHashCode()); - } - - [Test] - public void Equals_DifferentType_ReturnsFalse() + [TestFixture] + private class MacroStabilityInwardsSoilLayer2DEqualsTest + : EqualsGuidelinesTestFixture { - // Setup - MacroStabilityInwardsSoilLayer2D layer = CreateRandomLayer(21); + protected override MacroStabilityInwardsSoilLayer2D CreateObject() + { + return CreateRandomLayer(21); + } - // Call - bool areEqual = layer.Equals(new object()); + protected override DerivedMacroStabilityInwardsSoilLayer2D CreateDerivedObject() + { + return new DerivedMacroStabilityInwardsSoilLayer2D(CreateRandomLayer(21)); + } - // Assert - Assert.IsFalse(areEqual); - } + private static IEnumerable GetUnequalTestCases() + { + MacroStabilityInwardsSoilLayer2D baseLayer = CreateRandomLayer(21); - [Test] - public void Equals_Null_ReturnsFalse() - { - // Setup - MacroStabilityInwardsSoilLayer2D layer = CreateRandomLayer(21); + yield return new TestCaseData(new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(30), + baseLayer.Data, + baseLayer.NestedLayers)) + .SetName("OuterRing"); + yield return new TestCaseData(new MacroStabilityInwardsSoilLayer2D(baseLayer.OuterRing, + new MacroStabilityInwardsSoilLayerData(), + baseLayer.NestedLayers)) + .SetName("Data"); + yield return new TestCaseData(new MacroStabilityInwardsSoilLayer2D(baseLayer.OuterRing, + baseLayer.Data, + new [] + { + baseLayer.NestedLayers.First(), + new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(21)) + })) + .SetName("Different Nested Layer Count"); + yield return new TestCaseData(new MacroStabilityInwardsSoilLayer2D(baseLayer.OuterRing, + baseLayer.Data, + new [] + { + new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(30)) + })) + .SetName("Different Nested Layer"); + } - // Call - bool areEqual = layer.Equals(null); + private static MacroStabilityInwardsSoilLayer2D CreateRandomLayer(int randomSeed) + { + var random = new Random(randomSeed); - // Assert - Assert.IsFalse(areEqual); + return new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(randomSeed), + new MacroStabilityInwardsSoilLayerData + { + Color = Color.FromKnownColor(random.NextEnumValue()) + }, + new[] + { + new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(randomSeed)) + }); + } } - [Test] - [TestCaseSource(nameof(LayerCombinations))] - public void Equals_DifferentScenarios_ReturnsExpectedResult(MacroStabilityInwardsSoilLayer2D layer, MacroStabilityInwardsSoilLayer2D otherLayer, bool expectedEqual) + private class DerivedMacroStabilityInwardsSoilLayer2D : MacroStabilityInwardsSoilLayer2D { - // Call - bool areEqualOne = layer.Equals(otherLayer); - bool areEqualTwo = otherLayer.Equals(layer); - - // Assert - Assert.AreEqual(expectedEqual, areEqualOne); - Assert.AreEqual(expectedEqual, areEqualTwo); + public DerivedMacroStabilityInwardsSoilLayer2D(MacroStabilityInwardsSoilLayer2D layer) + : base(layer.OuterRing, layer.Data, layer.NestedLayers) {} } - - private static TestCaseData[] LayerCombinations() - { - MacroStabilityInwardsSoilLayer2D layerA = CreateRandomLayer(21); - MacroStabilityInwardsSoilLayer2D layerB = CreateRandomLayer(21); - MacroStabilityInwardsSoilLayer2D layerC = CreateRandomLayer(73); - MacroStabilityInwardsSoilLayer2D layerD = CreateRandomLayer(21); - - var layerE = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(21), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Blue - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)) - }); - - var layerF = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(31), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Blue - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)) - }); - - var layerG = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(21), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Gold - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)) - }); - - var layerH = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(21), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Blue - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(32)) - }); - - var layerI = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(21), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Blue - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)), - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)) - }); - - var layerJ = new MacroStabilityInwardsSoilLayer2D( - RingTestFactory.CreateRandomRing(21), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.Blue - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22), - new MacroStabilityInwardsSoilLayerData(), - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(22)) - }) - }); - - return new[] - { - new TestCaseData(layerA, layerA, true) - { - TestName = "Equals_LayerALayerA_True" - }, - new TestCaseData(layerA, layerB, true) - { - TestName = "Equals_LayerALayerB_True" - }, - new TestCaseData(layerB, layerD, true) - { - TestName = "Equals_LayerBLayerD_True" - }, - new TestCaseData(layerA, layerD, true) - { - TestName = "Equals_LayerALayerD_True" - }, - new TestCaseData(layerB, layerC, false) - { - TestName = "Equals_LayerBLayerC_False" - }, - new TestCaseData(layerA, layerC, false) - { - TestName = "Equals_LayerALayerC_False" - }, - new TestCaseData(layerC, layerC, true) - { - TestName = "Equals_LayerCLayerC_True" - }, - new TestCaseData(layerE, layerF, false) - { - TestName = "Equals_DifferentOuterRing_False" - }, - new TestCaseData(layerE, layerG, false) - { - TestName = "Equals_DifferentProperties_False" - }, - new TestCaseData(layerE, layerH, false) - { - TestName = "Equals_DifferentNestedLayers1False" - }, - new TestCaseData(layerE, layerI, false) - { - TestName = "Equals_DifferentNestedLayers2_False" - }, - new TestCaseData(layerE, layerJ, false) - { - TestName = "Equals_DifferentNestedLayers3_False" - } - }; - } - - private static MacroStabilityInwardsSoilLayer2D CreateRandomLayer(int randomSeed) - { - var random = new Random(randomSeed); - - return new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(randomSeed), - new MacroStabilityInwardsSoilLayerData - { - Color = Color.FromKnownColor(random.NextEnumValue()) - }, - new[] - { - new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing(randomSeed)) - }); - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayerDataTest.cs =================================================================== diff -u -rd9005dfa3b398d70ada0cf03cf408f8bcfc384db -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayerDataTest.cs (.../MacroStabilityInwardsSoilLayerDataTest.cs) (revision d9005dfa3b398d70ada0cf03cf408f8bcfc384db) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsSoilLayerDataTest.cs (.../MacroStabilityInwardsSoilLayerDataTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -122,189 +122,136 @@ Assert.AreEqual(materialName, data.MaterialName); } - [Test] - public void GetHashCode_EqualProperties_AreEqual() + [TestFixture] + private class MacroStabilityInwardsSoilLayerDataEqualsTest + : EqualsGuidelinesTestFixture { - // Setup - MacroStabilityInwardsSoilLayerData dataA = CreateRandomData(21); - MacroStabilityInwardsSoilLayerData dataB = CreateRandomData(21); + protected override MacroStabilityInwardsSoilLayerData CreateObject() + { + return CreateRandomData(21); + } - // Precondition - Assert.AreEqual(dataA, dataB); - Assert.AreEqual(dataB, dataA); + protected override DerivedMacroStabilityInwardsSoilLayerData CreateDerivedObject() + { + return new DerivedMacroStabilityInwardsSoilLayerData(CreateRandomData(21)); + } - // Call & Assert - Assert.AreEqual(dataA.GetHashCode(), dataB.GetHashCode()); - Assert.AreEqual(dataB.GetHashCode(), dataA.GetHashCode()); - } + private static MacroStabilityInwardsSoilLayerData CreateRandomData(int randomSeed) + { + var random = new Random(randomSeed); + return new MacroStabilityInwardsSoilLayerData + { + MaterialName = string.Join("", Enumerable.Repeat('x', random.Next(0, 40))), + Color = Color.FromKnownColor(random.NextEnumValue()), + IsAquifer = random.NextBoolean(), + UsePop = random.NextBoolean(), + ShearStrengthModel = random.NextEnumValue(), + AbovePhreaticLevel = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2, + Shift = (RoundedDouble) 1 + }, + BelowPhreaticLevel = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 11, + CoefficientOfVariation = (RoundedDouble) 0.6, + Shift = (RoundedDouble) 1 + }, + Cohesion = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2 + }, + FrictionAngle = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2 + }, + ShearStrengthRatio = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2 + }, + StrengthIncreaseExponent = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2 + }, + Pop = new VariationCoefficientLogNormalDistribution + { + Mean = (RoundedDouble) 10, + CoefficientOfVariation = (RoundedDouble) 0.2 + } + }; + } - [Test] - public void Equals_DifferentType_ReturnsFalse() - { - // Setup - MacroStabilityInwardsSoilLayerData data = CreateRandomData(21); + private static IEnumerable GetUnequalTestCases() + { + foreach (ChangePropertyTestCase changeSingleDataProperty in ChangeSingleDataProperties()) + { + MacroStabilityInwardsSoilLayerData baseData = CreateRandomData(21); + changeSingleDataProperty.ActionToChangeProperty(baseData); + yield return new TestCaseData(baseData).SetName(changeSingleDataProperty.PropertyName); + } + } - // Call - bool areEqual = data.Equals(new object()); + private static IEnumerable ChangeSingleDataProperties() + { + yield return new ChangePropertyTestCase(lp => lp.ShearStrengthModel = (MacroStabilityInwardsShearStrengthModel) 9, "ShearStrengthModel"); + yield return new ChangePropertyTestCase(lp => lp.MaterialName = "interesting", "MaterialName"); + yield return new ChangePropertyTestCase(lp => lp.IsAquifer = !lp.IsAquifer, "IsAquifer"); + yield return new ChangePropertyTestCase(lp => lp.UsePop = !lp.UsePop, "UsePoP"); + yield return new ChangePropertyTestCase(lp => lp.Color = lp.Color.ToArgb().Equals(Color.Aqua.ToArgb()) ? Color.Bisque : Color.Aqua, "Color"); + yield return new ChangePropertyTestCase(lp => lp.AbovePhreaticLevel.Mean = (RoundedDouble) (11.0 - lp.AbovePhreaticLevel.Mean), "AbovePhreaticLevelMean"); + yield return new ChangePropertyTestCase(lp => lp.AbovePhreaticLevel.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.AbovePhreaticLevel.CoefficientOfVariation), "AbovePhreaticLevelCoefficientOfVariation"); + yield return new ChangePropertyTestCase(lp => lp.AbovePhreaticLevel.Shift = (RoundedDouble) (1.0 - lp.AbovePhreaticLevel.Shift), "AbovePhreaticLevelShift"); + yield return new ChangePropertyTestCase(lp => lp.BelowPhreaticLevel.Mean = (RoundedDouble) (12.0 - lp.BelowPhreaticLevel.Mean), "BelowPhreaticLevelMean"); + yield return new ChangePropertyTestCase(lp => lp.BelowPhreaticLevel.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.BelowPhreaticLevel.CoefficientOfVariation), "BelowPhreaticLevelCoefficientOFVariation"); + yield return new ChangePropertyTestCase(lp => lp.BelowPhreaticLevel.Shift = (RoundedDouble) (1.0 - lp.BelowPhreaticLevel.Shift), "BelowPhreaticLevelShift"); + yield return new ChangePropertyTestCase(lp => lp.Cohesion.Mean = (RoundedDouble) (11.0 - lp.Cohesion.Mean), "CohesionMean"); + yield return new ChangePropertyTestCase(lp => lp.Cohesion.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.Cohesion.CoefficientOfVariation), "CohesionCoefficientOfVariation"); + yield return new ChangePropertyTestCase(lp => lp.FrictionAngle.Mean = (RoundedDouble) (11.0 - lp.FrictionAngle.Mean), "FrictionAngleMean"); + yield return new ChangePropertyTestCase(lp => lp.FrictionAngle.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.FrictionAngle.CoefficientOfVariation), "FrictionAngleCoefficientOfVariation"); + yield return new ChangePropertyTestCase(lp => lp.ShearStrengthRatio.Mean = (RoundedDouble) (11.0 - lp.ShearStrengthRatio.Mean), "ShearStrengthRatioMean"); + yield return new ChangePropertyTestCase(lp => lp.ShearStrengthRatio.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.ShearStrengthRatio.CoefficientOfVariation), "ShearStrengthRatioCoefficientOfVariation"); + yield return new ChangePropertyTestCase(lp => lp.StrengthIncreaseExponent.Mean = (RoundedDouble) (11.0 - lp.StrengthIncreaseExponent.Mean), "StrengthIncreaseExponentMean"); + yield return new ChangePropertyTestCase(lp => lp.StrengthIncreaseExponent.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.StrengthIncreaseExponent.CoefficientOfVariation), "StrengthIncreaseExponentCoefficientOfVariation"); + yield return new ChangePropertyTestCase(lp => lp.Pop.Mean = (RoundedDouble) (11.0 - lp.Pop.Mean), "PoMean"); + yield return new ChangePropertyTestCase(lp => lp.Pop.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.Pop.CoefficientOfVariation), "PopCoefficientOfVariation"); + } - // Assert - Assert.IsFalse(areEqual); - } - - [Test] - public void Equals_Null_ReturnsFalse() - { - // Setup - MacroStabilityInwardsSoilLayerData data = CreateRandomData(21); - - // Call - bool areEqual = data.Equals(null); - - // Assert - Assert.IsFalse(areEqual); - } - - [Test] - [TestCaseSource(nameof(ChangeSingleDataProperties))] - public void Equals_ChangeSingleProperty_ReturnsFalse(Action changeProperty) - { - // Setup - MacroStabilityInwardsSoilLayerData data = CreateRandomData(21); - MacroStabilityInwardsSoilLayerData dataToChange = CreateRandomData(21); - - changeProperty(dataToChange); - - // Call - bool areEqualOne = data.Equals(dataToChange); - bool areEqualTwo = dataToChange.Equals(data); - - // Assert - Assert.IsFalse(areEqualOne); - Assert.IsFalse(areEqualTwo); - } - - [Test] - [TestCaseSource(nameof(DataPropertiesCombinations))] - public void Equals_DifferentScenarios_ReturnsExpectedResult(MacroStabilityInwardsSoilLayerData data, MacroStabilityInwardsSoilLayerData otherData, bool expectedEqual) - { - // Call - bool areEqualOne = data.Equals(otherData); - bool areEqualTwo = otherData.Equals(data); - - // Assert - Assert.AreEqual(expectedEqual, areEqualOne); - Assert.AreEqual(expectedEqual, areEqualTwo); - } - - private static IEnumerable ChangeSingleDataProperties() - { - yield return new TestCaseData(new Action(lp => lp.ShearStrengthModel = (MacroStabilityInwardsShearStrengthModel) 9)); - yield return new TestCaseData(new Action(lp => lp.MaterialName = "interesting")); - yield return new TestCaseData(new Action(lp => lp.IsAquifer = !lp.IsAquifer)); - yield return new TestCaseData(new Action(lp => lp.UsePop = !lp.UsePop)); - yield return new TestCaseData(new Action(lp => lp.Color = lp.Color.ToArgb().Equals(Color.Aqua.ToArgb()) ? Color.Bisque : Color.Aqua)); - yield return new TestCaseData(new Action(lp => lp.AbovePhreaticLevel.Mean = (RoundedDouble) (11.0 - lp.AbovePhreaticLevel.Mean))); - yield return new TestCaseData(new Action(lp => lp.AbovePhreaticLevel.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.AbovePhreaticLevel.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.AbovePhreaticLevel.Shift = (RoundedDouble) (1.0 - lp.AbovePhreaticLevel.Shift))); - yield return new TestCaseData(new Action(lp => lp.BelowPhreaticLevel.Mean = (RoundedDouble) (12.0 - lp.BelowPhreaticLevel.Mean))); - yield return new TestCaseData(new Action(lp => lp.BelowPhreaticLevel.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.BelowPhreaticLevel.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.BelowPhreaticLevel.Shift = (RoundedDouble) (1.0 - lp.BelowPhreaticLevel.Shift))); - yield return new TestCaseData(new Action(lp => lp.Cohesion.Mean = (RoundedDouble) (11.0 - lp.Cohesion.Mean))); - yield return new TestCaseData(new Action(lp => lp.Cohesion.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.Cohesion.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.FrictionAngle.Mean = (RoundedDouble) (11.0 - lp.FrictionAngle.Mean))); - yield return new TestCaseData(new Action(lp => lp.FrictionAngle.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.FrictionAngle.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.ShearStrengthRatio.Mean = (RoundedDouble) (11.0 - lp.ShearStrengthRatio.Mean))); - yield return new TestCaseData(new Action(lp => lp.ShearStrengthRatio.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.ShearStrengthRatio.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.StrengthIncreaseExponent.Mean = (RoundedDouble) (11.0 - lp.StrengthIncreaseExponent.Mean))); - yield return new TestCaseData(new Action(lp => lp.StrengthIncreaseExponent.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.StrengthIncreaseExponent.CoefficientOfVariation))); - yield return new TestCaseData(new Action(lp => lp.Pop.Mean = (RoundedDouble) (11.0 - lp.Pop.Mean))); - yield return new TestCaseData(new Action(lp => lp.Pop.CoefficientOfVariation = (RoundedDouble) (1.0 - lp.Pop.CoefficientOfVariation))); - } - - private static TestCaseData[] DataPropertiesCombinations() - { - MacroStabilityInwardsSoilLayerData dataA = CreateRandomData(21); - MacroStabilityInwardsSoilLayerData dataB = CreateRandomData(21); - MacroStabilityInwardsSoilLayerData dataC = CreateRandomData(73); - MacroStabilityInwardsSoilLayerData dataD = CreateRandomData(21); - - return new[] + private class ChangePropertyTestCase { - new TestCaseData(dataA, dataA, true) + public ChangePropertyTestCase(Action actionToChangeProperty, + string propertyName) { - TestName = "Equals_DataADataA_True" - }, - new TestCaseData(dataA, dataB, true) - { - TestName = "Equals_DataADataB_True" - }, - new TestCaseData(dataB, dataD, true) - { - TestName = "Equals_DataBDataD_True" - }, - new TestCaseData(dataA, dataD, true) - { - TestName = "Equals_DataADataD_True" - }, - new TestCaseData(dataB, dataC, false) - { - TestName = "Equals_DataBDataC_False" - }, - new TestCaseData(dataA, dataC, false) - { - TestName = "Equals_DataADataC_False" + ActionToChangeProperty = actionToChangeProperty; + PropertyName = propertyName; } - }; + + public Action ActionToChangeProperty { get; } + public string PropertyName { get; } + } } - private static MacroStabilityInwardsSoilLayerData CreateRandomData(int randomSeed) + private class DerivedMacroStabilityInwardsSoilLayerData : MacroStabilityInwardsSoilLayerData { - var random = new Random(randomSeed); - return new MacroStabilityInwardsSoilLayerData + public DerivedMacroStabilityInwardsSoilLayerData(MacroStabilityInwardsSoilLayerData data) { - MaterialName = string.Join("", Enumerable.Repeat('x', random.Next(0, 40))), - Color = Color.FromKnownColor(random.NextEnumValue()), - IsAquifer = random.NextBoolean(), - UsePop = random.NextBoolean(), - ShearStrengthModel = random.NextEnumValue(), - AbovePhreaticLevel = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2, - Shift = (RoundedDouble) 1 - }, - BelowPhreaticLevel = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 11, - CoefficientOfVariation = (RoundedDouble) 0.6, - Shift = (RoundedDouble) 1 - }, - Cohesion = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2 - }, - FrictionAngle = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2 - }, - ShearStrengthRatio = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2 - }, - StrengthIncreaseExponent = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2 - }, - Pop = new VariationCoefficientLogNormalDistribution - { - Mean = (RoundedDouble) 10, - CoefficientOfVariation = (RoundedDouble) 0.2 - } - }; + MaterialName = data.MaterialName; + Color = data.Color; + IsAquifer = data.IsAquifer; + UsePop = data.UsePop; + ShearStrengthModel = data.ShearStrengthModel; + AbovePhreaticLevel = data.AbovePhreaticLevel; + BelowPhreaticLevel = data.BelowPhreaticLevel; + Cohesion = data.Cohesion; + FrictionAngle = data.FrictionAngle; + ShearStrengthRatio = data.ShearStrengthRatio; + StrengthIncreaseExponent = data.StrengthIncreaseExponent; + Pop = data.Pop; + } } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetLineTest.cs =================================================================== diff -u -r1aa559e52bc5cea607d34b0a4675d2074f808c83 -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetLineTest.cs (.../MacroStabilityInwardsWaternetLineTest.cs) (revision 1aa559e52bc5cea607d34b0a4675d2074f808c83) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetLineTest.cs (.../MacroStabilityInwardsWaternetLineTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; @@ -91,113 +92,74 @@ CollectionAssert.IsEmpty(waternetLine.PhreaticLine.Geometry); } - [Test] - [TestCase(null)] - [TestCase("string")] - public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + private class DerivedMacroStabilityInwardsWaternetLine : MacroStabilityInwardsWaternetLine { - // Setup - MacroStabilityInwardsWaternetLine waternetLine = CreateWaternetLine(); - - // Call - bool isEqualToDifferentObject = waternetLine.Equals(other); - - // Assert - Assert.IsFalse(isEqualToDifferentObject); + public DerivedMacroStabilityInwardsWaternetLine(MacroStabilityInwardsWaternetLine waternetLine) + : base(waternetLine.Name, waternetLine.Geometry, waternetLine.PhreaticLine) {} } - [Test] - public void Equals_AllPropertiesEqual_ReturnsTrue() + [TestFixture] + private class MacroStabilityInwardsWaternetLineEqualsTest + : EqualsGuidelinesTestFixture { - // Setup - MacroStabilityInwardsWaternetLine waternetLineX = CreateWaternetLine(); - MacroStabilityInwardsWaternetLine waternetLineY = CreateWaternetLine(); + protected override MacroStabilityInwardsWaternetLine CreateObject() + { + return CreateWaternetLine(); + } - // Call - bool isXEqualToY = waternetLineX.Equals(waternetLineY); - bool isYEqualToZ = waternetLineY.Equals(waternetLineX); + protected override DerivedMacroStabilityInwardsWaternetLine CreateDerivedObject() + { + return new DerivedMacroStabilityInwardsWaternetLine(CreateWaternetLine()); + } - // Assert - Assert.IsTrue(isXEqualToY); - Assert.IsTrue(isYEqualToZ); - } + private static IEnumerable GetUnequalTestCases() + { + yield return new TestCaseData(new MacroStabilityInwardsWaternetLine("Other name", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }, new TestMacroStabilityInwardsPhreaticLine())) + .SetName("Other name"); - [Test] - [TestCaseSource(nameof(GetWaternetLineCombinations))] - public void Equals_DifferentProperty_ReturnsFalse(MacroStabilityInwardsWaternetLine waternetLine, - MacroStabilityInwardsWaternetLine otherWaternetLine) - { - // Call - bool isWaternetLineEqualToOther = waternetLine.Equals(otherWaternetLine); - bool isOtherEqualToWaternetLine = otherWaternetLine.Equals(waternetLine); + yield return new TestCaseData(new MacroStabilityInwardsWaternetLine("Test", new[] + { + new Point2D(0, 0), + new Point2D(1, 1), + new Point2D(1, 1) + }, new TestMacroStabilityInwardsPhreaticLine())) + .SetName("Geometry other count"); - // Assert - Assert.IsFalse(isWaternetLineEqualToOther); - Assert.IsFalse(isOtherEqualToWaternetLine); - } + yield return new TestCaseData(new MacroStabilityInwardsWaternetLine("Test", new[] + { + new Point2D(0, 0), + new Point2D(2, 2) + }, new TestMacroStabilityInwardsPhreaticLine())) + .SetName("Geometry not same coordinates"); - [Test] - public void GetHashCode_EqualWaternetLines_ReturnsSameHashCode() - { - // Setup - MacroStabilityInwardsWaternetLine waternetLineX = CreateWaternetLine(); - MacroStabilityInwardsWaternetLine waternetLineY = CreateWaternetLine(); + yield return new TestCaseData(new MacroStabilityInwardsWaternetLine("Test", new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }, new MacroStabilityInwardsPhreaticLine( + "Test", + new[] + { + new Point2D(0, 0) + }))) + .SetName("Other phreatic line"); + } - // Call - int hashCodeOne = waternetLineX.GetHashCode(); - int hashCodeTwo = waternetLineY.GetHashCode(); - - // Assert - Assert.AreEqual(hashCodeOne, hashCodeTwo); + private static MacroStabilityInwardsWaternetLine CreateWaternetLine() + { + return new MacroStabilityInwardsWaternetLine( + "Test", + new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }, + new TestMacroStabilityInwardsPhreaticLine()); + } } - - private static IEnumerable GetWaternetLineCombinations() - { - yield return new TestCaseData(CreateWaternetLine(), - new MacroStabilityInwardsWaternetLine("Other name", new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - }, new TestMacroStabilityInwardsPhreaticLine())).SetName("Other name"); - - yield return new TestCaseData(CreateWaternetLine(), - new MacroStabilityInwardsWaternetLine("Test", new[] - { - new Point2D(0, 0), - new Point2D(1, 1), - new Point2D(1, 1) - }, new TestMacroStabilityInwardsPhreaticLine())).SetName("Geometry not same length"); - - yield return new TestCaseData(CreateWaternetLine(), - new MacroStabilityInwardsWaternetLine("Test", new[] - { - new Point2D(0, 0), - new Point2D(2, 2) - }, new TestMacroStabilityInwardsPhreaticLine())).SetName("Geometry not same coordinates"); - - yield return new TestCaseData(CreateWaternetLine(), - new MacroStabilityInwardsWaternetLine("Test", new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - }, new MacroStabilityInwardsPhreaticLine( - "Test", - new[] - { - new Point2D(0, 0) - }))).SetName("Other phreatic line"); - } - - private static MacroStabilityInwardsWaternetLine CreateWaternetLine() - { - return new MacroStabilityInwardsWaternetLine( - "Test", - new[] - { - new Point2D(0, 0), - new Point2D(1, 1) - }, - new TestMacroStabilityInwardsPhreaticLine()); - } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetTest.cs =================================================================== diff -u -rf02088bdf7599aa7b3c974976230c92b5a70c0ed -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetTest.cs (.../MacroStabilityInwardsWaternetTest.cs) (revision f02088bdf7599aa7b3c974976230c92b5a70c0ed) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/MacroStabilityInwardsWaternetTest.cs (.../MacroStabilityInwardsWaternetTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Geometry; +using Core.Common.TestUtil; using NUnit.Framework; using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; @@ -73,130 +74,87 @@ Assert.AreSame(waternetLine, waternet.WaternetLines.Single()); } - [Test] - [TestCase(null)] - [TestCase("string")] - public void Equals_ToDifferentTypeOrNull_ReturnsFalse(object other) + private class DerivedMacroStabilityInwardsWaternet : MacroStabilityInwardsWaternet { - // Setup - MacroStabilityInwardsWaternet waternet = CreateWaternet(); - - // Call - bool isEqualToDifferentObject = waternet.Equals(other); - - // Assert - Assert.IsFalse(isEqualToDifferentObject); + public DerivedMacroStabilityInwardsWaternet(MacroStabilityInwardsWaternet waternet) + : base(waternet.PhreaticLines, waternet.WaternetLines) {} } - [Test] - public void Equals_AllPropertiesEqual_ReturnsTrue() + [TestFixture] + private class MacroStabilityInwardsWaternetEqualsTest + : EqualsGuidelinesTestFixture { - // Setup - MacroStabilityInwardsWaternet waternetX = CreateWaternet(); - MacroStabilityInwardsWaternet waternetY = CreateWaternet(); + protected override MacroStabilityInwardsWaternet CreateObject() + { + return CreateWaternet(); + } - // Call - bool isXEqualToY = waternetX.Equals(waternetY); - bool isYEqualToZ = waternetY.Equals(waternetX); + protected override DerivedMacroStabilityInwardsWaternet CreateDerivedObject() + { + return new DerivedMacroStabilityInwardsWaternet(CreateWaternet()); + } - // Assert - Assert.IsTrue(isXEqualToY); - Assert.IsTrue(isYEqualToZ); - } - - [Test] - [TestCaseSource(nameof(GetWaternetCombinations))] - public void Equals_DifferentProperty_ReturnsFalse(MacroStabilityInwardsWaternet waternet, - MacroStabilityInwardsWaternet otherWaternet) - { - // Call - bool isWaternetEqualToOther = waternet.Equals(otherWaternet); - bool isOtherEqualToWaternet = otherWaternet.Equals(waternet); - - // Assert - Assert.IsFalse(isWaternetEqualToOther); - Assert.IsFalse(isOtherEqualToWaternet); - } - - [Test] - public void GetHashCode_EqualWaternet_ReturnsSameHashCode() - { - // Setup - MacroStabilityInwardsWaternet waternetLineX = CreateWaternet(); - MacroStabilityInwardsWaternet waternetLineY = CreateWaternet(); - - // Call - int hashCodeOne = waternetLineX.GetHashCode(); - int hashCodeTwo = waternetLineY.GetHashCode(); - - // Assert - Assert.AreEqual(hashCodeOne, hashCodeTwo); - } - - private static IEnumerable GetWaternetCombinations() - { - yield return new TestCaseData( - CreateWaternet(), - new MacroStabilityInwardsWaternet( - new[] + public static MacroStabilityInwardsWaternet CreateWaternet() + { + return new MacroStabilityInwardsWaternet( + new MacroStabilityInwardsPhreaticLine[] { - new MacroStabilityInwardsPhreaticLine("Test", new Point2D[0]) - }, - new MacroStabilityInwardsWaternetLine[] - { - new TestMacroStabilityInwardsWaternetLine() - })).SetName("Other phreatic line"); - - yield return new TestCaseData( - CreateWaternet(), - new MacroStabilityInwardsWaternet( - new[] - { - new TestMacroStabilityInwardsPhreaticLine(), new TestMacroStabilityInwardsPhreaticLine() }, new MacroStabilityInwardsWaternetLine[] { new TestMacroStabilityInwardsWaternetLine() - })).SetName("Other phreatic line count"); + }); + } - yield return new TestCaseData( - CreateWaternet(), - new MacroStabilityInwardsWaternet( - new[] - { - new TestMacroStabilityInwardsPhreaticLine() - }, - new[] - { - new MacroStabilityInwardsWaternetLine("Test", new Point2D[0], new TestMacroStabilityInwardsPhreaticLine()) - })).SetName("Other waternet line"); + private static IEnumerable GetUnequalTestCases() + { + yield return new TestCaseData(new MacroStabilityInwardsWaternet( + new[] + { + new MacroStabilityInwardsPhreaticLine("Test", new Point2D[0]) + }, + new MacroStabilityInwardsWaternetLine[] + { + new TestMacroStabilityInwardsWaternetLine() + })) + .SetName("Other phreatic line"); - yield return new TestCaseData( - CreateWaternet(), - new MacroStabilityInwardsWaternet( - new[] - { - new TestMacroStabilityInwardsPhreaticLine() - }, - new MacroStabilityInwardsWaternetLine[] - { - new TestMacroStabilityInwardsWaternetLine(), - new TestMacroStabilityInwardsWaternetLine() - })).SetName("Other waternet line count"); - } + yield return new TestCaseData(new MacroStabilityInwardsWaternet( + new[] + { + new TestMacroStabilityInwardsPhreaticLine(), + new TestMacroStabilityInwardsPhreaticLine() + }, + new MacroStabilityInwardsWaternetLine[] + { + new TestMacroStabilityInwardsWaternetLine() + })) + .SetName("Other phreatic line count"); - private static MacroStabilityInwardsWaternet CreateWaternet() - { - return new MacroStabilityInwardsWaternet( - new MacroStabilityInwardsPhreaticLine[] - { - new TestMacroStabilityInwardsPhreaticLine() - }, - new MacroStabilityInwardsWaternetLine[] - { - new TestMacroStabilityInwardsWaternetLine() - }); + yield return new TestCaseData(new MacroStabilityInwardsWaternet( + new[] + { + new TestMacroStabilityInwardsPhreaticLine() + }, + new[] + { + new MacroStabilityInwardsWaternetLine("Test", new Point2D[0], new TestMacroStabilityInwardsPhreaticLine()) + })) + .SetName("Other waternet line"); + + yield return new TestCaseData(new MacroStabilityInwardsWaternet( + new[] + { + new TestMacroStabilityInwardsPhreaticLine() + }, + new MacroStabilityInwardsWaternetLine[] + { + new TestMacroStabilityInwardsWaternetLine(), + new TestMacroStabilityInwardsWaternetLine() + })) + .SetName("Other waternet line count"); + } } } } \ No newline at end of file Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/RingTest.cs =================================================================== diff -u -r4b323a2ddc3c72d9543815f481202263b5852b91 -r472d38ee5a4169cc628526afb7b72f7f4a1af013 --- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/RingTest.cs (.../RingTest.cs) (revision 4b323a2ddc3c72d9543815f481202263b5852b91) +++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.Primitives.Test/RingTest.cs (.../RingTest.cs) (revision 472d38ee5a4169cc628526afb7b72f7f4a1af013) @@ -25,7 +25,6 @@ using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; -using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; namespace Ringtoets.MacroStabilityInwards.Primitives.Test { @@ -56,64 +55,9 @@ } [Test] - public void Equals_DifferentType_ReturnsFalse() + public void Constructor_WithValidPointsArray_PointSetCopiedToNewCollection() { // Setup - Ring layer = RingTestFactory.CreateRandomRing(); - - // Call - bool areEqual = layer.Equals(new object()); - - // Assert - Assert.IsFalse(areEqual); - } - - [Test] - public void Equals_WithNull_ReturnsFalse() - { - // Setup - Ring ring = RingTestFactory.CreateRandomRing(); - - // Call - bool equal = ring.Equals(null); - - // Assert - Assert.IsFalse(equal); - } - - [Test] - public void GetHashCode_EqualInstances_ReturnEqualHashes() - { - // Setup - Ring ringA = RingTestFactory.CreateRandomRing(21); - Ring ringB = RingTestFactory.CreateRandomRing(21); - - // Precondition - Assert.AreEqual(ringA, ringB); - Assert.AreEqual(ringB, ringA); - - // Call & Assert - Assert.AreEqual(ringA.GetHashCode(), ringB.GetHashCode()); - Assert.AreEqual(ringB.GetHashCode(), ringA.GetHashCode()); - } - - [Test] - [TestCaseSource(nameof(RingCombinations))] - public void Equals_DifferentScenarios_ReturnsExpectedResult(Ring ring, Ring otherRing, bool expectedEqual) - { - // Call - bool areEqualOne = ring.Equals(otherRing); - bool areEqualTwo = otherRing.Equals(ring); - - // Assert - Assert.AreEqual(expectedEqual, areEqualOne); - Assert.AreEqual(expectedEqual, areEqualTwo); - } - - [Test] - public void Points_RingWithPointSet_PointSetCopiedToNewCollection() - { - // Setup var points = new[] { new Point2D(3, 2), @@ -130,40 +74,50 @@ TestHelper.AssertAreEqualButNotSame(points, ringPoints); } - private static TestCaseData[] RingCombinations() + [TestFixture] + private class RingEqualsTest : EqualsGuidelinesTestFixture { - Ring ringA = RingTestFactory.CreateRandomRing(21); - Ring ringB = RingTestFactory.CreateRandomRing(21); - Ring ringC = RingTestFactory.CreateRandomRing(73); - Ring ringD = RingTestFactory.CreateRandomRing(21); + protected override Ring CreateObject() + { + return CreateRing(); + } - return new[] + protected override DerivedRing CreateDerivedObject() { - new TestCaseData(ringA, ringA, true) + return new DerivedRing(CreateRing()); + } + + private static IEnumerable GetUnequalTestCases() + { + Ring baseRing = CreateRing(); + List differentNrOfPoints = baseRing.Points.ToList(); + differentNrOfPoints.RemoveAt(0); + yield return new TestCaseData(new Ring(differentNrOfPoints)) + .SetName("Different Nr of Points"); + + baseRing = CreateRing(); + Point2D[] differentPoints = baseRing.Points.ToArray(); + differentPoints[0] = new Point2D(0, 0); + yield return new TestCaseData(new Ring(differentPoints)) + .SetName("Different Points"); + } + + private static Ring CreateRing() + { + var random = new Random(30); + return new Ring(new[] { - TestName = "Equals_RingARingA_True" - }, - new TestCaseData(ringA, ringB, true) - { - TestName = "Equals_RingARingB_True" - }, - new TestCaseData(ringB, ringD, true) - { - TestName = "Equals_RingBRingD_True" - }, - new TestCaseData(ringA, ringD, true) - { - TestName = "Equals_RingARingD_True" - }, - new TestCaseData(ringB, ringC, false) - { - TestName = "Equals_RingBRingC_False" - }, - new TestCaseData(ringA, ringC, false) - { - TestName = "Equals_RingARingC_False" - } - }; + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()), + new Point2D(random.NextDouble(), random.NextDouble()) + }); + } } + + private class DerivedRing : Ring + { + public DerivedRing(Ring ring) : base(ring.Points) {} + } } } \ No newline at end of file