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