Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/Input/SoilComparerTest.cs
===================================================================
diff -u
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/Input/SoilComparerTest.cs (revision 0)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Test/Kernels/UpliftVan/Input/SoilComparerTest.cs (revision b4ae581ac0d728500cbb4b92ef747de0c6fafb07)
@@ -0,0 +1,198 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Deltares.MacroStability.CSharpWrapper;
+using Deltares.MacroStability.CSharpWrapper.Input;
+using NUnit.Framework;
+using Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels.UpliftVan.Input;
+
+namespace Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Test.Kernels.UpliftVan.Input
+{
+ [TestFixture]
+ public class SoilComparerTest
+ {
+ [Test]
+ public void Constructor_ExpectedValues()
+ {
+ // Call
+ var comparer = new SoilComparer();
+
+ // Assert
+ Assert.IsInstanceOf(comparer);
+ Assert.IsInstanceOf>(comparer);
+ }
+
+ [Test]
+ public void Compare_FirstObjectOfIncorrectType_ThrowArgumentException()
+ {
+ // Setup
+ var firstObject = new object();
+ object secondObject = new Soil();
+
+ var comparer = new SoilComparer();
+
+ // Call
+ void Call() => comparer.Compare(firstObject, secondObject);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual($"Cannot compare objects other than {typeof(Soil)} with this comparer.", exception.Message);
+ }
+
+ [Test]
+ public void Compare_SecondObjectOfIncorrectType_ThrowArgumentException()
+ {
+ // Setup
+ object firstObject = new Soil();
+ var secondObject = new object();
+
+ var comparer = new SoilComparer();
+
+ // Call
+ void Call() => comparer.Compare(firstObject, secondObject);
+
+ // Assert
+ var exception = Assert.Throws(Call);
+ Assert.AreEqual($"Cannot compare objects other than {typeof(Soil)} with this comparer.", exception.Message);
+ }
+
+ [Test]
+ public void Compare_SameInstance_ReturnZero()
+ {
+ // Setup
+ var soil = new Soil();
+
+ // Call
+ int result = new SoilComparer().Compare(soil, soil);
+
+ // Assert
+ Assert.AreEqual(0, result);
+ }
+
+ [Test]
+ public void Compare_EqualProperties_ReturnZero()
+ {
+ // Setup
+ Soil soil1 = CreateSoil();
+ Soil soil2 = CreateSoil();
+
+ // Call
+ int result = new SoilComparer().Compare(soil1, soil2);
+
+ // Assert
+ Assert.AreEqual(0, result);
+ }
+
+ [Test]
+ [TestCaseSource(nameof(GetNotEqualProperties))]
+ public void Compare_NotEqualProperties_ReturnOne(Action setSoil1PropertyAction,
+ Action setSoil2PropertyAction)
+ {
+ // Setup
+ var soil1 = new Soil();
+ var soil2 = new Soil();
+
+ setSoil1PropertyAction(soil1);
+ setSoil2PropertyAction(soil2);
+
+ // Call
+ int result = new SoilComparer().Compare(soil1, soil2);
+
+ // Assert
+ Assert.AreEqual(1, result);
+ }
+
+ private static IEnumerable GetNotEqualProperties()
+ {
+ yield return new TestCaseData(
+ new Action(soil => soil.Name = "Soil 1"),
+ new Action(soil => soil.Name = "Soil 2"));
+ yield return new TestCaseData(
+ new Action(soil => soil.AbovePhreaticLevel = double.NaN),
+ new Action(soil => soil.AbovePhreaticLevel = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.AbovePhreaticLevel = 0.1),
+ new Action(soil => soil.AbovePhreaticLevel = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.BelowPhreaticLevel = double.NaN),
+ new Action(soil => soil.BelowPhreaticLevel = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.BelowPhreaticLevel = 0.1),
+ new Action(soil => soil.BelowPhreaticLevel = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.Dilatancy = double.NaN),
+ new Action(soil => soil.Dilatancy = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.Dilatancy = 0.1),
+ new Action(soil => soil.Dilatancy = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.Cohesion = double.NaN),
+ new Action(soil => soil.Cohesion = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.Cohesion = 0.1),
+ new Action(soil => soil.Cohesion = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.FrictionAngle = double.NaN),
+ new Action(soil => soil.FrictionAngle = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.FrictionAngle = 0.1),
+ new Action(soil => soil.FrictionAngle = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.RatioCuPc = double.NaN),
+ new Action(soil => soil.RatioCuPc = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.RatioCuPc = 0.1),
+ new Action(soil => soil.RatioCuPc = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.StrengthIncreaseExponent = double.NaN),
+ new Action(soil => soil.StrengthIncreaseExponent = 0.1));
+ yield return new TestCaseData(
+ new Action(soil => soil.StrengthIncreaseExponent = 0.1),
+ new Action(soil => soil.StrengthIncreaseExponent = 0.2));
+ yield return new TestCaseData(
+ new Action(soil => soil.ShearStrengthAbovePhreaticLevelModel = ShearStrengthModelType.MohrCoulomb),
+ new Action(soil => soil.ShearStrengthAbovePhreaticLevelModel = ShearStrengthModelType.Shansep));
+ yield return new TestCaseData(
+ new Action(soil => soil.ShearStrengthBelowPhreaticLevelModel = ShearStrengthModelType.MohrCoulomb),
+ new Action(soil => soil.ShearStrengthBelowPhreaticLevelModel = ShearStrengthModelType.Shansep));
+ }
+
+ private static Soil CreateSoil()
+ {
+ return new Soil
+ {
+ Name = "soil",
+ AbovePhreaticLevel = 0.1,
+ BelowPhreaticLevel = 0.2,
+ Dilatancy = 0.3,
+ Cohesion = 0.4,
+ FrictionAngle = 0.5,
+ RatioCuPc = 0.6,
+ StrengthIncreaseExponent = 0.7,
+ ShearStrengthAbovePhreaticLevelModel = ShearStrengthModelType.MohrCoulomb,
+ ShearStrengthBelowPhreaticLevelModel = ShearStrengthModelType.MohrCoulomb
+ };
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/KernelInputAssert.cs
===================================================================
diff -u -rda7dc57d090d50237ce3ed3fd93457defb35a53f -rb4ae581ac0d728500cbb4b92ef747de0c6fafb07
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/KernelInputAssert.cs (.../KernelInputAssert.cs) (revision da7dc57d090d50237ce3ed3fd93457defb35a53f)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/KernelInputAssert.cs (.../KernelInputAssert.cs) (revision b4ae581ac0d728500cbb4b92ef747de0c6fafb07)
@@ -169,7 +169,6 @@
Assert.AreEqual(expected.RatioCuPc, actual.RatioCuPc);
Assert.AreEqual(expected.StrengthIncreaseExponent, actual.StrengthIncreaseExponent);
Assert.AreEqual(expected.Dilatancy, actual.Dilatancy);
- Assert.AreEqual(expected.RatioCuPc, actual.RatioCuPc);
}
///
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/SoilComparer.cs
===================================================================
diff -u
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/SoilComparer.cs (revision 0)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/SoilComparer.cs (revision b4ae581ac0d728500cbb4b92ef747de0c6fafb07)
@@ -0,0 +1,75 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of Riskeer.
+//
+// Riskeer is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using Deltares.MacroStability.CSharpWrapper.Input;
+
+namespace Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil.Kernels.UpliftVan.Input
+{
+ ///
+ /// This class compares the coordinates of two
+ /// instances to determine whether they're equal to each other or not.
+ ///
+ public class SoilComparer : IComparer, IComparer
+ {
+ public int Compare(object x, object y)
+ {
+ if (!(x is Soil) || !(y is Soil))
+ {
+ throw new ArgumentException($"Cannot compare objects other than {typeof(Soil)} with this comparer.");
+ }
+
+ return Compare((Soil) x, (Soil) y);
+ }
+
+ public int Compare(Soil x, Soil y)
+ {
+ if (x.Equals(y))
+ {
+ return 0;
+ }
+
+ if (x.Name == y.Name
+ && CheckDouble(x.AbovePhreaticLevel, y.AbovePhreaticLevel)
+ && CheckDouble(x.BelowPhreaticLevel, y.BelowPhreaticLevel)
+ && CheckDouble(x.Dilatancy, y.Dilatancy)
+ && CheckDouble(x.Cohesion, y.Cohesion)
+ && CheckDouble(x.FrictionAngle, y.FrictionAngle)
+ && CheckDouble(x.RatioCuPc, y.RatioCuPc)
+ && CheckDouble(x.StrengthIncreaseExponent, y.StrengthIncreaseExponent)
+ && x.ShearStrengthAbovePhreaticLevelModel == y.ShearStrengthAbovePhreaticLevelModel
+ && x.ShearStrengthBelowPhreaticLevelModel == y.ShearStrengthBelowPhreaticLevelModel
+ )
+ {
+ return 0;
+ }
+
+ return 1;
+ }
+
+ private static bool CheckDouble(double x, double y)
+ {
+ return double.IsNaN(x) && double.IsNaN(y) || Math.Abs(x - y) < 1e-6;
+ }
+ }
+}
\ No newline at end of file
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/UpliftVanKernelInputAssert.cs
===================================================================
diff -u -r3e96590dbc35797c9eed68f737c44fb94c585071 -rb4ae581ac0d728500cbb4b92ef747de0c6fafb07
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/UpliftVanKernelInputAssert.cs (.../UpliftVanKernelInputAssert.cs) (revision 3e96590dbc35797c9eed68f737c44fb94c585071)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/UpliftVan/Input/UpliftVanKernelInputAssert.cs (.../UpliftVanKernelInputAssert.cs) (revision b4ae581ac0d728500cbb4b92ef747de0c6fafb07)
@@ -1,4 +1,4 @@
-// Copyright (C) Stichting Deltares 2019. All rights reserved.
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
//
// This file is part of Riskeer.
//
@@ -61,7 +61,7 @@
AssertConstructionStages(expected.ConstructionStages, actual.ConstructionStages);
- CollectionAssert.AreEqual(expected.Soils, actual.Soils);
+ CollectionAssert.AreEqual(expected.Soils, actual.Soils, new SoilComparer());
Assert.AreEqual(expected.MoveGrid, actual.MoveGrid);
Assert.AreEqual(expected.MaximumSliceWidth, actual.MaximumSliceWidth);
Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/Input/WaternetKernelInputAssert.cs
===================================================================
diff -u -rda7dc57d090d50237ce3ed3fd93457defb35a53f -rb4ae581ac0d728500cbb4b92ef747de0c6fafb07
--- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/Input/WaternetKernelInputAssert.cs (.../WaternetKernelInputAssert.cs) (revision da7dc57d090d50237ce3ed3fd93457defb35a53f)
+++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.KernelWrapper.TestUtil/Kernels/Waternet/Input/WaternetKernelInputAssert.cs (.../WaternetKernelInputAssert.cs) (revision b4ae581ac0d728500cbb4b92ef747de0c6fafb07)
@@ -43,7 +43,7 @@
KernelInputAssert.AssertSoilProfile(expected.StabilityModel.ConstructionStages.Single().SoilProfile,
actual.StabilityModel.ConstructionStages.Single().SoilProfile);
- CollectionAssert.AreEqual(expected.StabilityModel.Soils, actual.StabilityModel.Soils);
+ CollectionAssert.AreEqual(expected.StabilityModel.Soils, actual.StabilityModel.Soils, new SoilComparer());
PreConstructionStage expectedPreconstructionStage = expected.PreprocessingInput.PreConstructionStages.Single();
PreConstructionStage actualPreconstructionStage = actual.PreprocessingInput.PreConstructionStages.Single();