// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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.Generic;
using System.Drawing;
using System.Linq;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using NUnit.Framework;
using Ringtoets.Common.Data.Probabilistics;
using Ringtoets.Common.Data.TestUtil;
using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
using Ringtoets.Common.IO.TestUtil;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.IO.SoilProfiles;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.IO.Test.SoilProfiles
{
[TestFixture]
public class MacroStabilityInwardsSoilLayerTransformerTest
{
[Test]
public void SoilLayer1DTransform_SoilLayer1DNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform((SoilLayer1D) null);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("soilLayer", exception.ParamName);
}
[Test]
public void SoilLayer1DTransform_PropertiesSetAndValid_ReturnMacroStabilityInwardSoilLayer1D()
{
// Setup
var random = new Random(22);
double isAquifer = random.Next(0, 2);
double top = random.NextDouble();
const string materialName = "materialX";
double color = random.NextDouble();
const double abovePhreaticLevelMean = 0.3;
const double abovePhreaticLevelCoefficientOfVariation = 0.2;
const double abovePhreaticLevelShift = 0.1;
const double belowPhreaticLevelMean = 0.4;
const double belowPhreaticLevelCoefficientOfVariation = 0.3;
const double belowPhreaticLevelShift = 0.2;
double cohesionMean = random.NextDouble();
double cohesionCoefficientOfVariation = random.NextDouble();
double frictionAngleMean = random.NextDouble();
double frictionAngleCoefficientOfVariation = random.NextDouble();
double shearStrengthRatioMean = random.NextDouble();
double shearStrengthRatioCoefficientOfVariation = random.NextDouble();
double strengthIncreaseExponentMean = random.NextDouble();
double strengthIncreaseExponentCoefficientOfVariation = random.NextDouble();
double popMean = random.NextDouble();
double popCoefficientOfVariation = random.NextDouble();
var layer = new SoilLayer1D(top)
{
IsAquifer = isAquifer,
MaterialName = materialName,
Color = color,
AbovePhreaticLevelMean = abovePhreaticLevelMean,
AbovePhreaticLevelCoefficientOfVariation = abovePhreaticLevelCoefficientOfVariation,
AbovePhreaticLevelShift = abovePhreaticLevelShift,
BelowPhreaticLevelMean = belowPhreaticLevelMean,
BelowPhreaticLevelCoefficientOfVariation = belowPhreaticLevelCoefficientOfVariation,
BelowPhreaticLevelShift = belowPhreaticLevelShift,
CohesionMean = cohesionMean,
CohesionCoefficientOfVariation = cohesionCoefficientOfVariation,
FrictionAngleMean = frictionAngleMean,
FrictionAngleCoefficientOfVariation = frictionAngleCoefficientOfVariation,
ShearStrengthRatioMean = shearStrengthRatioMean,
ShearStrengthRatioCoefficientOfVariation = shearStrengthRatioCoefficientOfVariation,
StrengthIncreaseExponentMean = strengthIncreaseExponentMean,
StrengthIncreaseExponentCoefficientOfVariation = strengthIncreaseExponentCoefficientOfVariation,
PopMean = popMean,
PopCoefficientOfVariation = popCoefficientOfVariation
};
// Call
MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(top, soilLayer1D.Top);
MacroStabilityInwardsSoilLayerData data = soilLayer1D.Data;
Assert.AreEqual(materialName, data.MaterialName);
bool expectedIsAquifer = isAquifer.Equals(1.0);
Assert.AreEqual(expectedIsAquifer, data.IsAquifer);
Color expectedColor = Color.FromArgb(Convert.ToInt32(color));
Assert.AreEqual(expectedColor, data.Color);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) abovePhreaticLevelMean,
CoefficientOfVariation = (RoundedDouble) abovePhreaticLevelCoefficientOfVariation,
Shift = (RoundedDouble) abovePhreaticLevelShift
}, data.AbovePhreaticLevel);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) belowPhreaticLevelMean,
CoefficientOfVariation = (RoundedDouble) belowPhreaticLevelCoefficientOfVariation,
Shift = (RoundedDouble) abovePhreaticLevelShift
}, data.BelowPhreaticLevel);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) cohesionMean,
CoefficientOfVariation = (RoundedDouble) cohesionCoefficientOfVariation
}, data.Cohesion);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) frictionAngleMean,
CoefficientOfVariation = (RoundedDouble) frictionAngleCoefficientOfVariation
}, data.FrictionAngle);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) shearStrengthRatioMean,
CoefficientOfVariation = (RoundedDouble) shearStrengthRatioCoefficientOfVariation
}, data.ShearStrengthRatio);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) strengthIncreaseExponentMean,
CoefficientOfVariation = (RoundedDouble) strengthIncreaseExponentCoefficientOfVariation
}, data.StrengthIncreaseExponent);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) popMean,
CoefficientOfVariation = (RoundedDouble) popCoefficientOfVariation
}, data.Pop);
}
[Test]
[TestCase(null, true)]
[TestCase(0, false)]
public void SoilLayer1DTransform_ValidUsePopValue_ReturnMacroStabilityInwardSoilLayer1D(double? usePop, bool transformedUsePopValue)
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.UsePop = usePop;
// Call
MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedUsePopValue, soilLayer1D.Data.UsePop);
}
[Test]
public void SoilLayer1DTransform_InvalidUsePopValue_ThrowsImportedDataTransformationException()
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.UsePop = 1;
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message);
}
[Test]
[TestCase(null, MacroStabilityInwardsShearStrengthModel.CPhi)]
[TestCase(9, MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)]
[TestCase(6, MacroStabilityInwardsShearStrengthModel.SuCalculated)]
public void SoilLayer1DTransform_ValidShearStrengthModelValue_ReturnMacroStabilityInwardSoilLayer1D(double? sheartStrengthModel,
MacroStabilityInwardsShearStrengthModel transformedShearStrengthModel)
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.ShearStrengthModel = sheartStrengthModel;
// Call
MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedShearStrengthModel, soilLayer1D.Data.ShearStrengthModel);
}
[Test]
public void SoilLayer1DTransform_ShearStrengthModelValueNone_ThrowsImportedDataTransformException()
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.ShearStrengthModel = 1;
// Call
TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("Er is geen schuifsterkte model opgegeven.", exception.Message);
}
[Test]
public void SoilLayer1DTransform_InvalidShearStrengthModelValue_ThrowsImportedDataTransformException()
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.ShearStrengthModel = 2;
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message);
}
[Test]
[TestCase(1.0, true)]
[TestCase(0.0, false)]
public void SoilLayer1DTransform_ValidIsAquifer_ReturnsMacroStabilityInwardsSoilLayer1D(double isAquifer, bool transformedIsAquifer)
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.IsAquifer = isAquifer;
// Call
MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedIsAquifer, soilLayer1D.Data.IsAquifer);
}
[Test]
[TestCase(null)]
[TestCase(1.01)]
[TestCase(0.01)]
public void SoilLayer1DTransform_InvalidIsAquifer_ThrowsImportedDataException(double? isAquifer)
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.IsAquifer = isAquifer;
// Call
TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("Ongeldige waarde voor parameter 'Is aquifer'.", exception.Message);
}
[Test]
[TestCaseSource(nameof(GetColorCases))]
public void SoilLayer1DTransform_ValidColors_ReturnsMacroStabilityInwardsSoilLayer1D(double? color, Color transformedColor)
{
// Setup
SoilLayer1D layer = SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer();
layer.Color = color;
// Call
MacroStabilityInwardsSoilLayer1D soilLayer1D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedColor, soilLayer1D.Data.Color);
}
[Test]
[TestCaseSource(nameof(IncorrectShiftedLogNormalDistributionsSoilLayer1D))]
public void SoilLayer1DTransform_IncorrectShiftedLogNormalDistribution_ThrowsImportedDataTransformException(SoilLayer1D layer, string parameter)
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Exception exception = Assert.Throws(test);
Assert.AreEqual($"Parameter '{parameter}' is niet verschoven lognormaal verdeeld.", exception.Message);
}
[Test]
[TestCaseSource(nameof(IncorrectNonShiftedLogNormalDistributionsSoilLayer1D))]
public void SoilLayer1DTransform_IncorrectLogNormalDistribution_ThrowImportedDataTransformException(SoilLayer1D layer, string parameter)
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Exception exception = Assert.Throws(test);
Assert.AreEqual($"Parameter '{parameter}' is niet lognormaal verdeeld.", exception.Message);
}
[Test]
public void SoilLayer2DTransform_SoilLayer2DNull_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform((SoilLayer2D) null);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("soilLayer", exception.ParamName);
}
[Test]
public void SoilLayer2DTransform_PropertiesSetAndValid_ReturnMacroStabilityInwardSoilLayer2D()
{
// Setup
var nestedLayer1 = new SoilLayer2D(CreateRandomLoop(21), Enumerable.Empty());
var nestedLayer2 = new SoilLayer2D(CreateRandomLoop(22), Enumerable.Empty());
var nestedLayer3 = new SoilLayer2D(CreateRandomLoop(22),
new[]
{
nestedLayer2
});
var layer = new SoilLayer2D(CreateRandomLoop(23),
new[]
{
nestedLayer1,
nestedLayer3
});
SetRandomSoilData(nestedLayer1, 21, "Nested sand");
SetRandomSoilData(nestedLayer2, 22, "Nested gold");
SetRandomSoilData(nestedLayer3, 23, "Nested clay");
SetRandomSoilData(layer, 24, "Sand");
// Call
MacroStabilityInwardsSoilLayer2D transformedLayer = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
AssertSoilLayer(layer, transformedLayer);
Assert.AreEqual(2, transformedLayer.NestedLayers.Count());
MacroStabilityInwardsSoilLayer2D transformedNestedLayer1 = transformedLayer.NestedLayers.ElementAt(0);
AssertSoilLayer(nestedLayer1, transformedNestedLayer1);
CollectionAssert.IsEmpty(transformedNestedLayer1.NestedLayers);
MacroStabilityInwardsSoilLayer2D transformedNestedLayer3 = transformedLayer.NestedLayers.ElementAt(1);
AssertSoilLayer(nestedLayer3, transformedNestedLayer3);
Assert.AreEqual(1, transformedNestedLayer3.NestedLayers.Count());
MacroStabilityInwardsSoilLayer2D transformedNestedLayer2 = transformedNestedLayer3.NestedLayers.ElementAt(0);
AssertSoilLayer(nestedLayer2, transformedNestedLayer2);
CollectionAssert.IsEmpty(transformedNestedLayer2.NestedLayers);
}
[Test]
[TestCase(null, true)]
[TestCase(0, false)]
public void SoilLayer2DTransform_ValidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D(double? usePop, bool transformedUsePopValue)
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.UsePop = usePop;
// Call
MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedUsePopValue, soilLayer2D.Data.UsePop);
}
[Test]
public void SoilLayer2DTransform_InvalidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D()
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.UsePop = 1;
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Ongeldige waarde voor parameter 'Gebruik POP'.", exception.Message);
}
[Test]
[TestCase(null, MacroStabilityInwardsShearStrengthModel.CPhi)]
[TestCase(9, MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated)]
[TestCase(6, MacroStabilityInwardsShearStrengthModel.SuCalculated)]
public void SoilLayer2DTransform_ValidShearStrengthModelValue_ReturnMacroStabilityInwardSoilLayer2D(double? shearStrengthModel,
MacroStabilityInwardsShearStrengthModel transformedShearStrengthModel)
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.ShearStrengthModel = shearStrengthModel;
// Call
MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedShearStrengthModel, soilLayer2D.Data.ShearStrengthModel);
}
[Test]
public void SoilLayer2DTransform_ShearStrengthModelValueNone_ThrowsImportedDataTransformException()
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.ShearStrengthModel = 1;
// Call
TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("Er is geen schuifsterkte model opgegeven.", exception.Message);
}
[Test]
public void SoilLayer2DTransform_InvalidShearStrengthModelValue_ThrowsImportedDataTransformException()
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.ShearStrengthModel = 2;
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(test);
Assert.AreEqual("Ongeldige waarde voor parameter 'Schuifsterkte model'.", exception.Message);
}
[Test]
[TestCase(1.0, true)]
[TestCase(0.0, false)]
public void SoilLayer2DTransform_ValidIsAquifer_ReturnsMacroStabilityInwardsSoilLayer2D(double isAquifer, bool transformedIsAquifer)
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.IsAquifer = isAquifer;
// Call
MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedIsAquifer, soilLayer2D.Data.IsAquifer);
}
[Test]
[TestCase(null)]
[TestCase(1.01)]
[TestCase(0.01)]
public void SoilLayer2DTransform_InvalidIsAquifer_ThrowsImportedDataException(double? isAquifer)
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.IsAquifer = isAquifer;
// Call
TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("Ongeldige waarde voor parameter 'Is aquifer'.", exception.Message);
}
[Test]
[TestCaseSource(nameof(GetColorCases))]
public void SoilLayer2DTransform_ValidColors_ReturnsMacroStabilityInwardsSoilLayer2D(double? color, Color transformedColor)
{
// Setup
SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D();
layer.Color = color;
// Call
MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Assert.AreEqual(transformedColor, soilLayer2D.Data.Color);
}
[Test]
[TestCaseSource(nameof(IncorrectShiftedLogNormalDistributionsSoilLayer2D))]
public void SoilLayer2DTransform_IncorrectShiftedLogNormalDistribution_ThrowsImportedDataTransformException(
SoilLayer2D layer, string parameter)
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Exception exception = Assert.Throws(test);
Assert.AreEqual($"Parameter '{parameter}' is niet verschoven lognormaal verdeeld.", exception.Message);
}
[Test]
[TestCaseSource(nameof(IncorrectNonShiftedLogNormalDistributionsSoilLayer2D))]
public void SoilLayer2DTransform_IncorrectLogNormalDistribution_ThrowImportedDataTransformException(SoilLayer2D layer, string parameter)
{
// Call
TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
// Assert
Exception exception = Assert.Throws(test);
Assert.AreEqual($"Parameter '{parameter}' is niet lognormaal verdeeld.", exception.Message);
}
[Test]
[TestCaseSource(nameof(GetSoilLayerWithInvalidGeometry))]
public void SoilLayer2DTransform_SoilLayer2DWithInvalidLoops_ThrowsImportedDataException(SoilLayer2D soilLayer)
{
// Call
TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(soilLayer);
// Assert
var exception = Assert.Throws(call);
Assert.AreEqual("De laag bevat een ongeldige geometrie.", exception.Message);
Assert.IsInstanceOf(exception.InnerException);
}
private static SoilLayer2DLoop CreateRandomLoop(int seed)
{
var random = new Random(seed);
var pointA = new Point2D(random.NextDouble(), random.NextDouble());
var pointB = new Point2D(random.NextDouble(), random.NextDouble());
var pointC = new Point2D(random.NextDouble(), random.NextDouble());
return new SoilLayer2DLoop(new[]
{
new Segment2D(pointA, pointB),
new Segment2D(pointB, pointC),
new Segment2D(pointC, pointA)
});
}
private static void SetRandomSoilData(SoilLayer2D layer, int seed, string materialName)
{
var random = new Random(seed);
layer.MaterialName = materialName;
layer.IsAquifer = random.Next(0, 2);
layer.Color = random.NextDouble();
layer.AbovePhreaticLevelMean = random.NextDouble() + 1;
layer.AbovePhreaticLevelCoefficientOfVariation = random.NextDouble();
layer.AbovePhreaticLevelShift = random.NextDouble();
layer.BelowPhreaticLevelMean = random.NextDouble() + 1;
layer.BelowPhreaticLevelCoefficientOfVariation = random.NextDouble();
layer.BelowPhreaticLevelShift = random.NextDouble();
layer.CohesionMean = random.NextDouble();
layer.CohesionCoefficientOfVariation = random.NextDouble();
layer.FrictionAngleMean = random.NextDouble();
layer.FrictionAngleCoefficientOfVariation = random.NextDouble();
layer.ShearStrengthRatioMean = random.NextDouble();
layer.ShearStrengthRatioCoefficientOfVariation = random.NextDouble();
layer.StrengthIncreaseExponentMean = random.NextDouble();
layer.StrengthIncreaseExponentCoefficientOfVariation = random.NextDouble();
layer.PopMean = random.NextDouble();
layer.PopCoefficientOfVariation = random.NextDouble();
}
private static void AssertSoilLayer(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual)
{
AssertOuterRing(original, actual);
AssertSoilData(original, actual);
}
private static void AssertOuterRing(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual)
{
Assert.AreEqual(GetRingFromSegments(original.OuterLoop.Segments), actual.OuterRing);
}
private static Ring GetRingFromSegments(IEnumerable loop)
{
var points = new List();
foreach (Segment2D segment in loop)
{
points.AddRange(new[]
{
segment.FirstPoint,
segment.SecondPoint
});
}
return new Ring(points.Distinct());
}
private static void AssertSoilData(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual)
{
Assert.AreEqual(original.MaterialName, actual.Data.MaterialName);
Assert.AreEqual(original.IsAquifer.Equals(1.0), actual.Data.IsAquifer);
Assert.AreEqual(Color.FromArgb(Convert.ToInt32(original.Color)), actual.Data.Color);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.AbovePhreaticLevelMean,
CoefficientOfVariation = (RoundedDouble) original.AbovePhreaticLevelCoefficientOfVariation,
Shift = (RoundedDouble) original.AbovePhreaticLevelShift
}, actual.Data.AbovePhreaticLevel);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.BelowPhreaticLevelMean,
CoefficientOfVariation = (RoundedDouble) original.BelowPhreaticLevelCoefficientOfVariation,
Shift = (RoundedDouble) original.BelowPhreaticLevelShift
}, actual.Data.BelowPhreaticLevel);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.CohesionMean,
CoefficientOfVariation = (RoundedDouble) original.CohesionCoefficientOfVariation
}, actual.Data.Cohesion);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.FrictionAngleMean,
CoefficientOfVariation = (RoundedDouble) original.FrictionAngleCoefficientOfVariation
}, actual.Data.FrictionAngle);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.ShearStrengthRatioMean,
CoefficientOfVariation = (RoundedDouble) original.ShearStrengthRatioCoefficientOfVariation
}, actual.Data.ShearStrengthRatio);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.StrengthIncreaseExponentMean,
CoefficientOfVariation = (RoundedDouble) original.StrengthIncreaseExponentCoefficientOfVariation
}, actual.Data.StrengthIncreaseExponent);
DistributionAssert.AreEqual(new VariationCoefficientLogNormalDistribution(2)
{
Mean = (RoundedDouble) original.PopMean,
CoefficientOfVariation = (RoundedDouble) original.PopCoefficientOfVariation
}, actual.Data.Pop);
}
#region Test Data: Color test cases
private static IEnumerable GetColorCases()
{
yield return new TestCaseData(null, Color.Empty)
.SetName("Color result Empty");
yield return new TestCaseData((double) -12156236, Color.FromArgb(70, 130, 180))
.SetName("Color result Purple");
yield return new TestCaseData((double) -65281, Color.FromArgb(255, 0, 255))
.SetName("Color result Pink");
}
#endregion
#region Test Data: Invalid 2D SoilLayer geometries
private static IEnumerable GetSoilLayerWithInvalidGeometry()
{
var pointA = new Point2D(0.0, 0.0);
var pointB = new Point2D(1.0, 0.0);
var segmentOne = new Segment2D(pointA, pointB);
var segmentTwo = new Segment2D(pointB, pointA);
var validGeometry = new[]
{
segmentOne,
segmentTwo
};
yield return new TestCaseData(SoilLayer2DTestFactory.CreateSoilLayer2D(new IEnumerable[0],
Enumerable.Empty()))
.SetName("OuterLoop_ContainsNoSegments");
yield return new TestCaseData(SoilLayer2DTestFactory.CreateSoilLayer2D(new[]
{
Enumerable.Empty()
},
validGeometry))
.SetName("Innerloop_ContainsCollectionWithElementWithNoSegments");
}
#endregion
#region Test Data: Shifted Log Normal Distributions
private static IEnumerable IncorrectShiftedLogNormalDistributionsSoilLayer1D()
{
return IncorrectShiftedLogNormalDistributions(() => new SoilLayer1D(0.0), nameof(SoilLayer1D));
}
private static IEnumerable IncorrectShiftedLogNormalDistributionsSoilLayer2D()
{
return IncorrectShiftedLogNormalDistributions(SoilLayer2DTestFactory.CreateSoilLayer2D, nameof(SoilLayer2D));
}
private static IEnumerable IncorrectShiftedLogNormalDistributions(Func soilLayer, string typeName)
{
const string testNameFormat = "{0}Transform_Incorrect{1}{{1}}_ThrowsImportedDataTransformException";
SoilLayerBase invalidBelowPhreaticLevel = soilLayer();
invalidBelowPhreaticLevel.BelowPhreaticLevelDistributionType = -1;
yield return new TestCaseData(invalidBelowPhreaticLevel, "Verzadigd gewicht")
.SetName(string.Format(testNameFormat, typeName, "Distribution"));
SoilLayerBase invalidAbovePhreaticLevel = soilLayer();
invalidAbovePhreaticLevel.AbovePhreaticLevelDistributionType = -1;
yield return new TestCaseData(invalidAbovePhreaticLevel, "Onverzadigd gewicht")
.SetName(string.Format(testNameFormat, typeName, "Distribution"));
}
#endregion
#region Test Data: NonShifted Log Normal Distributions
private static IEnumerable IncorrectNonShiftedLogNormalDistributionsSoilLayer1D()
{
return IncorrectNonShiftedLogNormalDistributions(() => new SoilLayer1D(0.0), nameof(SoilLayer1D));
}
private static IEnumerable IncorrectNonShiftedLogNormalDistributionsSoilLayer2D()
{
return IncorrectNonShiftedLogNormalDistributions(SoilLayer2DTestFactory.CreateSoilLayer2D, nameof(SoilLayer2D));
}
private static IEnumerable IncorrectNonShiftedLogNormalDistributions(Func soilLayer, string typeName)
{
const string testNameFormat = "{0}Transform_Incorrect{1}{{1}}_ThrowsImportedDataTransformException";
const long validDistributionType = SoilLayerConstants.LogNormalDistributionValue;
const double validShift = 0.0;
SoilLayerBase invalidCohesionShift = soilLayer();
invalidCohesionShift.CohesionDistributionType = validDistributionType;
invalidCohesionShift.CohesionShift = -1;
yield return new TestCaseData(invalidCohesionShift, "Cohesie"
).SetName(string.Format(testNameFormat, typeName, "Shift"));
SoilLayerBase invalidCohesionDistribution = soilLayer();
invalidCohesionDistribution.CohesionDistributionType = -1;
invalidCohesionDistribution.CohesionShift = validShift;
yield return new TestCaseData(invalidCohesionDistribution, "Cohesie"
).SetName(string.Format(testNameFormat, typeName, "Distribution"));
SoilLayerBase invalidFrictionAngleShift = soilLayer();
invalidFrictionAngleShift.FrictionAngleDistributionType = validDistributionType;
invalidFrictionAngleShift.FrictionAngleShift = -1;
yield return new TestCaseData(invalidFrictionAngleShift, "Wrijvingshoek"
).SetName(string.Format(testNameFormat, typeName, "Shift"));
SoilLayerBase invalidFrictionAngleDistribution = soilLayer();
invalidFrictionAngleDistribution.FrictionAngleDistributionType = -1;
invalidFrictionAngleDistribution.FrictionAngleShift = validShift;
yield return new TestCaseData(invalidFrictionAngleDistribution, "Wrijvingshoek"
).SetName(string.Format(testNameFormat, typeName, "Distribution"));
SoilLayerBase invalidShearStrengthRatioShift = soilLayer();
invalidShearStrengthRatioShift.ShearStrengthRatioDistributionType = validDistributionType;
invalidShearStrengthRatioShift.ShearStrengthRatioShift = -1;
yield return new TestCaseData(invalidShearStrengthRatioShift, "Schuifsterkte ratio (S)"
).SetName(string.Format(testNameFormat, typeName, "Shift"));
SoilLayerBase invalidShearStrengthRatioDistribution = soilLayer();
invalidShearStrengthRatioDistribution.ShearStrengthRatioDistributionType = -1;
invalidShearStrengthRatioDistribution.ShearStrengthRatioShift = validShift;
yield return new TestCaseData(invalidShearStrengthRatioDistribution, "Schuifsterkte ratio (S)"
).SetName(string.Format(testNameFormat, typeName, "Distribution"));
SoilLayerBase invalidStrengthIncreaseExponentShift = soilLayer();
invalidStrengthIncreaseExponentShift.StrengthIncreaseExponentDistributionType = validDistributionType;
invalidStrengthIncreaseExponentShift.StrengthIncreaseExponentShift = -1;
yield return new TestCaseData(invalidStrengthIncreaseExponentShift, "Sterkte toename exp (m)"
).SetName(string.Format(testNameFormat, typeName, "Shift"));
SoilLayerBase invalidStrengthIncreaseExponentDistribution = soilLayer();
invalidStrengthIncreaseExponentDistribution.StrengthIncreaseExponentDistributionType = -1;
invalidStrengthIncreaseExponentDistribution.StrengthIncreaseExponentShift = validShift;
yield return new TestCaseData(invalidStrengthIncreaseExponentDistribution, "Sterkte toename exp (m)"
).SetName(string.Format(testNameFormat, typeName, "Distribution"));
SoilLayerBase invalidPopShift = soilLayer();
invalidPopShift.PopDistributionType = validDistributionType;
invalidPopShift.PopShift = -1;
yield return new TestCaseData(invalidPopShift, "POP"
).SetName(string.Format(testNameFormat, typeName, "Shift"));
SoilLayerBase invalidPopDistribution = soilLayer();
invalidPopDistribution.PopDistributionType = -1;
invalidPopDistribution.PopShift = validShift;
yield return new TestCaseData(invalidPopDistribution, "POP"
).SetName(string.Format(testNameFormat, typeName, "Distribution"));
}
#endregion
}
}