Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u -rc5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision c5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -1865,16 +1865,6 @@
}
///
- /// Looks up a localized string similar to Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel '{0}'..
- ///
- public static string StochasticSoilModelReader_ReadStochasticSoilProfiles_No_profiles_found_in_stochastic_soil_model_Name_0_ {
- get {
- return ResourceManager.GetString("StochasticSoilModelReader_ReadStochasticSoilProfiles_No_profiles_found_in_stochas" +
- "tic_soil_model_Name_0_", resourceCulture);
- }
- }
-
- ///
/// Looks up a localized string similar to Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel moet in het bereik {0} liggen..
///
public static string StochasticSoilProfile_Probability_Should_be_in_range_0_ {
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u -rc5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision c5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (.../Resources.resx) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -836,9 +836,6 @@
..\Resources\XmlGeometrySchema.xsd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
- Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel '{0}'.
-
Het stochastische ondergrondmodel '{0}' moet een geometrie bevatten.
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs
===================================================================
diff -u -rda4a311b2ac60defe1a27a61c8d151f47268a941 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision da4a311b2ac60defe1a27a61c8d151f47268a941)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -264,10 +264,8 @@
if (!probability.HasValue)
{
- string soilModelName = ReadStochasticSoilModelName();
- throw new StochasticSoilModelException(
- string.Format(Resources.StochasticSoilModelReader_ReadStochasticSoilProfiles_No_profiles_found_in_stochastic_soil_model_Name_0_,
- soilModelName));
+ MoveNext();
+ yield break;
}
long? soilProfile1D = ReadSoilProfile1DId();
Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs
===================================================================
diff -u -r76aba900dac58a4328145a2946b774ebd4a37aa5 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 76aba900dac58a4328145a2946b774ebd4a37aa5)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -32,17 +32,13 @@
///
public class StochasticSoilProfile
{
- private static readonly Range probabilityValidityRange = new Range(0, 1);
- private double probability;
-
+
///
/// Creates a new instance of .
///
/// Probability of the stochastic soil profile.
/// The soil profile.
/// Thrown when is null.
- /// Thrown when the
- /// is outside the range [0, 1].
public StochasticSoilProfile(double probability, ISoilProfile soilProfile)
{
if (soilProfile == null)
@@ -61,39 +57,6 @@
///
/// Gets the probability of the stochastic soil profile.
///
- /// Thrown when the
- /// is outside the range [0, 1].
- public double Probability
- {
- get
- {
- return probability;
- }
- private set
- {
- if (!probabilityValidityRange.InRange(value))
- {
- throw new ArgumentOutOfRangeException(
- null,
- string.Format(
- Resources.StochasticSoilProfile_Probability_Should_be_in_range_0_,
- probabilityValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)));
- }
- probability = value;
- }
- }
-
- ///
- /// Updates the probability of the
- /// by adding .
- ///
- /// The amount to increase the
- /// with.
- /// Thrown when the
- /// is outside the range [0, 1].
- public void AddProbability(double probabilityToAdd)
- {
- Probability += probabilityToAdd;
- }
+ public double Probability { get; }
}
}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelImporterTest.cs
===================================================================
diff -u -r1ca15d28d72589c9f5522f91e57dd7dca9189b71 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelImporterTest.cs (.../StochasticSoilModelImporterTest.cs) (revision 1ca15d28d72589c9f5522f91e57dd7dca9189b71)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelImporterTest.cs (.../StochasticSoilModelImporterTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -594,50 +594,6 @@
}
[Test]
- public void Import_StochasticSoilModelWithoutStochasticSoilProfiles_StopsImportAndLogs()
- {
- // Setup
- var messageProvider = mocks.StrictMock();
- var updateStrategy = mocks.StrictMock>();
- var filter = mocks.StrictMock();
- mocks.ReplayAll();
-
- string validFilePath = Path.Combine(testDataPath, "modelWithoutProfile.soil");
-
- var importer = new StochasticSoilModelImporter(
- new TestStochasticSoilModelCollection(),
- validFilePath,
- messageProvider,
- new StochasticSoilModelImporterConfiguration(
- transformer,
- filter,
- updateStrategy));
-
- var importResult = true;
-
- // Call
- Action call = () => importResult = importer.Import();
-
- // Assert
- TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, tuples =>
- {
- Tuple[] tupleArray = tuples.ToArray();
- Assert.AreEqual(1, tupleArray.Length);
-
- Tuple actualLog = tupleArray[0];
-
- string expectedMessage = "Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel '36006_Piping'. " +
- $"{Environment.NewLine}Het bestand wordt overgeslagen.";
-
- Assert.AreEqual(expectedMessage, actualLog.Item1);
- Assert.AreEqual(Level.Error, actualLog.Item2);
- Assert.IsInstanceOf(actualLog.Item3);
- });
-
- Assert.IsFalse(importResult);
- }
-
- [Test]
public void Import_IncorrectProbability_LogAndImportSoilModelToCollection()
{
// Setup
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs
===================================================================
diff -u -rda4a311b2ac60defe1a27a61c8d151f47268a941 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision da4a311b2ac60defe1a27a61c8d151f47268a941)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilModelReaderTest.cs (.../StochasticSoilModelReaderTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -282,6 +282,7 @@
[Test]
public void ReadStochasticSoilModel_EmptySoilModelAndNoGeometry_ReturnsSoilModelWithoutGeometry()
{
+ // Setup
string dbFile = Path.Combine(testDataPath, "modelWithoutGeometry.soil");
using (var reader = new StochasticSoilModelReader(dbFile))
@@ -304,7 +305,7 @@
public void GivenDatabaseWithStochasticSoilModelWithAndWithoutGeometry_WhenReading_ThenReturnsAllModels()
{
// Setup
- string dbFile = Path.Combine(testDataPath, "skippedStochasticSoilModel.soil");
+ string dbFile = Path.Combine(testDataPath, "modelsWithAndWithoutGeometry.soil");
var readModels = new List();
using (var reader = new StochasticSoilModelReader(dbFile))
@@ -367,91 +368,154 @@
}
[Test]
- public void ReadStochasticSoilModel_OtherFailureMechanism_ThrowsStochasticSoilModelException()
+ public void ReadStochasticSoilModel_SoilModelWithoutStochasticSoilProfiles_ReturnsSoilModelWithoutLayers()
{
// Setup
- string dbFile = Path.Combine(testDataPath, "otherFailureMechanism.soil");
+ string dbFile = Path.Combine(testDataPath, "modelWithoutStochasticSoilProfiles.soil");
using (var reader = new StochasticSoilModelReader(dbFile))
{
reader.Validate();
// Call
- TestDelegate test = () => reader.ReadStochasticSoilModel();
+ StochasticSoilModel model = reader.ReadStochasticSoilModel();
// Assert
- var exception = Assert.Throws(test);
-
- const string expectedMessage = "Het faalmechanisme 'UNKNOWN' wordt niet ondersteund.";
- Assert.AreEqual(expectedMessage, exception.Message);
+ Assert.AreEqual("SoilModel", model.Name);
+ Assert.AreEqual(FailureMechanismType.Piping, model.FailureMechanismType);
+ CollectionAssert.IsEmpty(model.StochasticSoilProfiles);
}
Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
}
[Test]
- public void ReadStochasticSoilModel_SoilModelWithoutStochasticSoilProfile_ThrowsStochasticSoilModelExceptionAndCanContinueReading()
+ public void GivenDatabaseWithStochasticSoilModelWithAndWithoutSoilProfiles_WhenReading_ReturnsAllModels()
{
// Setup
- string dbFile = Path.Combine(testDataPath, "modelWithoutProfile.soil");
+ string dbFile = Path.Combine(testDataPath, "modelsWithAndWithoutStochasticSoilProfiles.soil");
- StochasticSoilModelException expectedException = null;
var readModels = new List();
using (var reader = new StochasticSoilModelReader(dbFile))
{
reader.Validate();
+ // Call
while (reader.HasNext)
{
- try
- {
- // Call
- readModels.Add(reader.ReadStochasticSoilModel());
- }
- catch (StochasticSoilModelException e)
- {
- expectedException = e;
- reader.MoveNext();
- }
+ readModels.Add(reader.ReadStochasticSoilModel());
}
+ // Assert
Assert.IsFalse(reader.HasNext);
+
+ CollectionAssert.AreEqual(new[]
+ {
+ "36005_Stability",
+ "36005_Piping",
+ "36006_Stability",
+ "36006_Piping",
+ "36007_Stability",
+ "36007_Piping"
+ }, readModels.Select(m => m.Name));
+ CollectionAssert.AreEqual(new[]
+ {
+ 10,
+ 0,
+ 6,
+ 0,
+ 8,
+ 0
+ }, readModels.Select(m => m.StochasticSoilProfiles.Count));
}
- // Assert
- var expectedSegmentAndModelNames = new[]
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
+ public void ReadStochasticSoilModel_ModelWithStochasticSoilProfilesWith1DProfiles_ReturnsModelWithStochasticProfiles()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "modelWithStochasticSoilProfile1D.soil");
+
+ using (var reader = new StochasticSoilModelReader(dbFile))
{
- "36005_Stability",
- "36005_Piping",
- "36006_Stability",
- "36007_Stability",
- "36007_Piping"
- };
- var expectedSegmentPointCount = new[]
+ reader.Validate();
+
+ // Call
+ StochasticSoilModel model = reader.ReadStochasticSoilModel();
+
+ // Assert
+ Assert.AreEqual("SoilModel", model.Name);
+ Assert.AreEqual(FailureMechanismType.Stability, model.FailureMechanismType);
+ CollectionAssert.AreEqual(new[]
+ {
+ 0.1,
+ 0.35,
+ 0.05,
+ 0.1,
+ 0.35,
+ 0.05
+ }.OrderBy(p => p), model.StochasticSoilProfiles.Select(profile => profile.Probability));
+ CollectionAssert.AllItemsAreInstancesOfType(model.StochasticSoilProfiles.Select(profile => profile.SoilProfile), typeof(SoilProfile1D));
+ }
+ }
+
+ [Test]
+ public void ReadStochasticSoilModel_ModelWithStochasticProfilesWith2DProfiles_ReturnsModelWithStochasticProfiles()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "modelWithStochasticSoilProfile2D.soil");
+
+ using (var reader = new StochasticSoilModelReader(dbFile))
{
- 1797,
- 1797,
- 144,
- 606,
- 606
- };
- var expectedProfileCount = new[]
+ reader.Validate();
+
+ // Call
+ StochasticSoilModel model = reader.ReadStochasticSoilModel();
+
+ // Assert
+ Assert.AreEqual("SoilModel", model.Name);
+ Assert.AreEqual(FailureMechanismType.Stability, model.FailureMechanismType);
+ CollectionAssert.AreEqual(new[]
+ {
+ 0.15,
+ 0.175,
+ 0.075,
+ 0.05,
+ 0.05,
+ 0.15,
+ 0.175,
+ 0.075,
+ 0.05,
+ 0.05
+ }.OrderBy(p => p), model.StochasticSoilProfiles.Select(profile => profile.Probability));
+ CollectionAssert.AllItemsAreInstancesOfType(model.StochasticSoilProfiles.Select(profile => profile.SoilProfile), typeof(SoilProfile2D));
+ }
+
+ Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
+ }
+
+ [Test]
+ public void ReadStochasticSoilModel_OtherFailureMechanism_ThrowsStochasticSoilModelException()
+ {
+ // Setup
+ string dbFile = Path.Combine(testDataPath, "otherFailureMechanism.soil");
+
+ using (var reader = new StochasticSoilModelReader(dbFile))
{
- 10,
- 10,
- 6,
- 8,
- 8
- };
+ reader.Validate();
- CollectionAssert.AreEqual(expectedSegmentAndModelNames, readModels.Select(m => m.Name));
- CollectionAssert.AreEqual(expectedSegmentPointCount, readModels.Select(m => m.Geometry.Count));
- CollectionAssert.AreEqual(expectedProfileCount, readModels.Select(m => m.StochasticSoilProfiles.Count));
+ // Call
+ TestDelegate test = () => reader.ReadStochasticSoilModel();
- Assert.IsNotNull(expectedException);
- Assert.AreEqual("Er zijn geen ondergrondschematisaties gevonden in het stochastische ondergrondmodel '36006_Piping'.",
- expectedException.Message);
+ // Assert
+ var exception = Assert.Throws(test);
+ const string expectedMessage = "Het faalmechanisme 'UNKNOWN' wordt niet ondersteund.";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile));
}
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs
===================================================================
diff -u -rec201316303aa676976655dcdfd9285dcc3ec4f1 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision ec201316303aa676976655dcdfd9285dcc3ec4f1)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/SoilProfile/StochasticSoilProfileTest.cs (.../StochasticSoilProfileTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -20,7 +20,6 @@
// All rights reserved.
using System;
-using Core.Common.TestUtil;
using NUnit.Framework;
using Rhino.Mocks;
using Ringtoets.Common.IO.SoilProfile;
@@ -30,89 +29,16 @@
[TestFixture]
public class StochasticSoilProfileTest
{
- [Test]
- [SetCulture("nl-NL")]
- [TestCase(12.5)]
- [TestCase(1 + 1e-6)]
- [TestCase(0 - 1e-6)]
- [TestCase(-28.5)]
- [TestCase(double.NaN)]
- public void Constructor_WithInvalidProbabilities_ThrowsArgumentOutOfRangeException(double probability)
+ [TestCase]
+ public void Constructor_SoilProfileNull_ThrowsArgumentNullException()
{
// Setup
- var mockRepository = new MockRepository();
- var soilProfile = mockRepository.Stub();
- mockRepository.ReplayAll();
+ var random = new Random(21);
// Call
- TestDelegate test = () => new StochasticSoilProfile(probability, soilProfile);
+ TestDelegate test = () => new StochasticSoilProfile(random.NextDouble(), null);
// Assert
- const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel moet in het bereik [0,0, 1,0] liggen.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(test, expectedMessage);
-
- mockRepository.VerifyAll();
- }
-
- [Test]
- [SetCulture("nl-NL")]
- [TestCase(-1)]
- [TestCase(1)]
- [TestCase(-0.51)]
- [TestCase(0.51)]
- [TestCase(double.NaN)]
- public void AddProbability_ProbabilityToAddResultsInInvalidProbability_ThrowsArgumentOutOfRangeException(double probabilityToAdd)
- {
- // Setup
- const double probability = 0.5;
-
- var mockRepository = new MockRepository();
- var soilProfile = mockRepository.Stub();
- mockRepository.ReplayAll();
-
- var stochasticSoilProfile = new StochasticSoilProfile(probability, soilProfile);
-
- // Call
- TestDelegate call = () => stochasticSoilProfile.AddProbability(probabilityToAdd);
-
- // Assert
- const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel moet in het bereik [0,0, 1,0] liggen.";
- TestHelper.AssertThrowsArgumentExceptionAndTestMessage(call, expectedMessage);
-
- mockRepository.VerifyAll();
- }
-
- [Test]
- [TestCase(0.5)]
- [TestCase(-0.5)]
- [TestCase(-0.2)]
- [TestCase(0.2)]
- public void AddProbability_ProbabilityToAddResultsInValidProbability_ReturnsExpectedProbability(double probabilityToAdd)
- {
- // Setup
- const double probability = 0.5;
-
- var mockRepository = new MockRepository();
- var soilProfile = mockRepository.Stub();
- mockRepository.ReplayAll();
-
- var stochasticSoilProfile = new StochasticSoilProfile(probability, soilProfile);
-
- // Call
- stochasticSoilProfile.AddProbability(probabilityToAdd);
-
- // Assert
- double expectedProbability = probability + probabilityToAdd;
- Assert.AreEqual(expectedProbability, stochasticSoilProfile.Probability, 1e-6);
- }
-
- [TestCase]
- public void Constructor_SoilProfileNull_ThrowsArgumentNullException()
- {
- // Call
- TestDelegate test = () => new StochasticSoilProfile(0.5, null);
-
- // Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("soilProfile", paramName);
}
@@ -121,13 +47,13 @@
public void Constructor_WithValidArguments_ExpectedValues()
{
// Setup
+ var random = new Random(21);
+ double probability = random.NextDouble();
+
var mockRepository = new MockRepository();
var soilProfile = mockRepository.Stub();
mockRepository.ReplayAll();
- var random = new Random(9);
- double probability = random.NextDouble();
-
// Call
var profile = new StochasticSoilProfile(probability, soilProfile);
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/modelWithStochasticSoilProfile1D.soil
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/modelWithStochasticSoilProfile2D.soil
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/modelWithoutStochasticSoilProfiles.soil
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/modelsWithAndWithoutStochasticSoilProfiles.soil
===================================================================
diff -u
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/StochasticSoilModelReader/skippedStochasticSoilModel.soil
===================================================================
diff -u -rda4a311b2ac60defe1a27a61c8d151f47268a941 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
Binary files differ
Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/Ringtoets.Common.IO.TestUtil.Test.csproj
===================================================================
diff -u -ra20f5008f39cfa4fd6f94572fd07a011f76609f4 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/Ringtoets.Common.IO.TestUtil.Test.csproj (.../Ringtoets.Common.IO.TestUtil.Test.csproj) (revision a20f5008f39cfa4fd6f94572fd07a011f76609f4)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/Ringtoets.Common.IO.TestUtil.Test.csproj (.../Ringtoets.Common.IO.TestUtil.Test.csproj) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -54,6 +54,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilModelTestFactoryTest.cs
===================================================================
diff -u -ra20f5008f39cfa4fd6f94572fd07a011f76609f4 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilModelTestFactoryTest.cs (.../StochasticSoilModelTestFactoryTest.cs) (revision a20f5008f39cfa4fd6f94572fd07a011f76609f4)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilModelTestFactoryTest.cs (.../StochasticSoilModelTestFactoryTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -20,7 +20,6 @@
// All rights reserved.
using System;
-using System.Linq;
using Core.Common.Base.Geometry;
using Core.Common.TestUtil;
using NUnit.Framework;
@@ -63,7 +62,7 @@
CollectionAssert.AreEqual(new[]
{
new Point2D(1, 2),
- new Point2D(3, 4)
+ new Point2D(3, 4)
}, model.Geometry);
}
}
Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilProfileTestFactoryTest.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilProfileTestFactoryTest.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil.Test/StochasticSoilProfileTestFactoryTest.cs (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -0,0 +1,47 @@
+// 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 NUnit.Framework;
+using Rhino.Mocks;
+using Ringtoets.Common.IO.SoilProfile;
+
+namespace Ringtoets.Common.IO.TestUtil.Test
+{
+ [TestFixture]
+ public class StochasticSoilProfileTestFactoryTest
+ {
+ [Test]
+ public void CreateStochasticSoilProfileWithValidProbability_WithSoilProfile_ExpectedPropertiesSet()
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var soilProfile = mocks.Stub();
+ mocks.ReplayAll();
+
+ // Call
+ StochasticSoilProfile stochasticSoilProfile = StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(soilProfile);
+
+ // Assert
+ Assert.AreEqual(0.5, stochasticSoilProfile.Probability);
+ Assert.AreSame(soilProfile, stochasticSoilProfile.SoilProfile);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj
===================================================================
diff -u -ra20f5008f39cfa4fd6f94572fd07a011f76609f4 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision a20f5008f39cfa4fd6f94572fd07a011f76609f4)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/Ringtoets.Common.IO.TestUtil.csproj (.../Ringtoets.Common.IO.TestUtil.csproj) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -58,6 +58,7 @@
+
Index: Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/StochasticSoilProfileTestFactory.cs
===================================================================
diff -u
--- Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/StochasticSoilProfileTestFactory.cs (revision 0)
+++ Ringtoets/Common/test/Ringtoets.Common.IO.TestUtil/StochasticSoilProfileTestFactory.cs (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -0,0 +1,44 @@
+// 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 Ringtoets.Common.IO.SoilProfile;
+
+namespace Ringtoets.Common.IO.TestUtil
+{
+ ///
+ /// Factory which creates simple instance of
+ /// that can be used for testing.
+ ///
+ public static class StochasticSoilProfileTestFactory
+ {
+ ///
+ /// Creates a with a valid probability.
+ ///
+ /// The soil profile.
+ /// A with the specified .
+ /// Thrown when is null.
+ public static StochasticSoilProfile CreateStochasticSoilProfileWithValidProbability(ISoilProfile soilProfile)
+ {
+ return new StochasticSoilProfile(0.5, soilProfile);
+ }
+ }
+}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformer.cs
===================================================================
diff -u -rec201316303aa676976655dcdfd9285dcc3ec4f1 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformer.cs (.../MacroStabilityInwardsStochasticSoilProfileTransformer.cs) (revision ec201316303aa676976655dcdfd9285dcc3ec4f1)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformer.cs (.../MacroStabilityInwardsStochasticSoilProfileTransformer.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -20,9 +20,9 @@
// All rights reserved.
using System;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
-using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.IO.SoilProfiles
{
@@ -41,6 +41,8 @@
/// The transformed soil profile.
/// A new based on the given data.
/// Thrown when any parameter is null.
+ /// Thrown when
+ /// could not be transformed.
public static MacroStabilityInwardsStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile,
IMacroStabilityInwardsSoilProfile soilProfile)
{
@@ -53,7 +55,14 @@
throw new ArgumentNullException(nameof(soilProfile));
}
- return new MacroStabilityInwardsStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile);
+ try
+ {
+ return new MacroStabilityInwardsStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile);
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ throw new ImportedDataTransformException(e.Message, e);
+ }
}
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs
===================================================================
diff -u -rc5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilModelTransformerTest.cs) (revision c5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilModelTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilModelTransformerTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -25,7 +25,6 @@
using Core.Common.Base.Geometry;
using Core.Common.TestUtil;
using NUnit.Framework;
-using Rhino.Mocks;
using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
using Ringtoets.Common.IO.SoilProfile.Schema;
@@ -104,14 +103,16 @@
public void Transform_ValidStochasticSoilModelWithSoilProfile1D_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel()
{
// Setup
+ var random = new Random(21);
+ double probability = random.NextDouble();
const double top = 4;
var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry("some name",
FailureMechanismType.Stability,
new[]
{
- new StochasticSoilProfile(1, new SoilProfile1D(2, "test", 3, new[]
+ new StochasticSoilProfile(probability, new SoilProfile1D(2, "test", 3, new[]
{
SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer(top)
}))
@@ -125,7 +126,7 @@
CollectionAssert.AreEqual(soilModel.Geometry, transformedModel.Geometry);
Assert.AreEqual(1, transformedModel.StochasticSoilProfiles.Count);
- var expectedStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(1, new MacroStabilityInwardsSoilProfile1D("test", 3, new[]
+ var expectedStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(probability, new MacroStabilityInwardsSoilProfile1D("test", 3, new[]
{
new MacroStabilityInwardsSoilLayer1D(top)
{
@@ -144,11 +145,14 @@
public void Transform_ValidStochasticSoilModelWithSoilProfile2D_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel()
{
// Setup
+ var random = new Random(21);
+ double probability = random.NextDouble();
+
var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry("some name",
FailureMechanismType.Stability, new[]
{
- new StochasticSoilProfile(1, new SoilProfile2D(2, "test", new[]
+ new StochasticSoilProfile(probability, new SoilProfile2D(2, "test", new[]
{
SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
}, Enumerable.Empty()))
@@ -162,7 +166,7 @@
CollectionAssert.AreEqual(soilModel.Geometry, transformedModel.Geometry);
Assert.AreEqual(1, transformedModel.StochasticSoilProfiles.Count);
- var expectedStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(1, new MacroStabilityInwardsSoilProfile2D("test", new[]
+ var expectedStochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(probability, new MacroStabilityInwardsSoilProfile2D("test", new[]
{
new MacroStabilityInwardsSoilLayer2D(new Ring(new[]
{
@@ -200,13 +204,13 @@
StochasticSoilModel soilModel1 = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry("some name",
FailureMechanismType.Stability, new[]
{
- new StochasticSoilProfile(1.0, profile)
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile)
});
StochasticSoilModel soilModel2 = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry("some name",
FailureMechanismType.Stability, new[]
{
- new StochasticSoilProfile(1.0, profile)
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile)
});
var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
@@ -227,29 +231,19 @@
}
[Test]
- public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfiles_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel()
+ [TestCaseSource(nameof(GetValidConfiguredAndSupportedSoilProfiles))]
+ public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfiles_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel(ISoilProfile soilProfile)
{
// Setup
const string soilModelName = "name";
- const string soilProfileName = "SoilProfile";
- const double intersectionX = 1.0;
-
- SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer();
- var profile = new SoilProfile2D(0, soilProfileName, new[]
- {
- layer
- }, Enumerable.Empty())
- {
- IntersectionX = intersectionX
- };
-
const double originalProfileOneProbability = 0.2;
const double originalProfileTwoProbability = 0.7;
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName,
- FailureMechanismType.Stability, new[]
+ FailureMechanismType.Stability,
+ new[]
{
- new StochasticSoilProfile(originalProfileOneProbability, profile),
- new StochasticSoilProfile(originalProfileTwoProbability, profile)
+ new StochasticSoilProfile(originalProfileOneProbability, soilProfile),
+ new StochasticSoilProfile(originalProfileTwoProbability, soilProfile)
});
var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
@@ -259,7 +253,7 @@
Action call = () => transformed = transformer.Transform(soilModel);
// Assert
- string expectedMessage = $"Ondergrondschematisatie '{soilProfileName}' is meerdere keren gevonden in ondergrondmodel '{soilModelName}'. " +
+ string expectedMessage = $"Ondergrondschematisatie '{soilProfile.Name}' is meerdere keren gevonden in ondergrondmodel '{soilModelName}'. " +
"Kansen van voorkomen worden opgeteld.";
TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn));
@@ -272,16 +266,43 @@
[Test]
[SetCulture("nl-NL")]
[TestCaseSource(nameof(GetValidConfiguredAndSupportedSoilProfiles))]
- public void Transform_ValidStochasticSoilModelWithSameProfileProbabilityExceedingValidRange_ThrowsImportedDataException(ISoilProfile profile)
+ public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfilesAndSumOfProbabilitiesInvalid_ThrowsImportedDataException(ISoilProfile soilProfile)
{
// Setup
const string soilModelName = "name";
+ var stochasticSoilProfiles = new[]
+ {
+ new StochasticSoilProfile(0.9, soilProfile),
+ new StochasticSoilProfile(0.9, soilProfile)
+ };
+ StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName,
+ FailureMechanismType.Stability,
+ stochasticSoilProfiles);
+ var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
+
+ // Call
+ TestDelegate call = () => transformer.Transform(soilModel);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel " +
+ "moet in het bereik [0,0, 1,0] liggen.";
+ StringAssert.StartsWith(expectedMessage, exception.Message);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
+ [TestCaseSource(nameof(GetSupportedStochasticSoilProfilesWithInvalidProbabilities))]
+ public void Transform_ValidStochasticSoilModelWithProfileInvalidProbability_ThrowsImportedDataException(StochasticSoilProfile profile)
+ {
+ // Setup
+ const string soilModelName = "name";
+
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName,
FailureMechanismType.Stability, new[]
{
- new StochasticSoilProfile(0.9, profile),
- new StochasticSoilProfile(0.9, profile)
+ profile
});
var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer();
@@ -300,6 +321,7 @@
public void Transform_ValidStochasticSoilModelWithSimilarProfileInTwoStochasticSoilProfiles_ReturnsExpectedMacroStabilityInwardsStochasticSoilModel()
{
// Setup
+ var random = new Random(21);
const string soilModelName = "name";
const string soilProfileName = "SoilProfile";
const double intersectionX = 1.0;
@@ -311,13 +333,13 @@
{
IntersectionX = intersectionX
};
- var stochasticSoilProfile2D = new StochasticSoilProfile(0.2, soilProfile2D);
+ var stochasticSoilProfile2D = new StochasticSoilProfile(random.NextDouble(), soilProfile2D);
var soilProfile1D = new SoilProfile1D(0, soilProfileName, 0, new[]
{
SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
});
- var stochasticSoilProfile1D = new StochasticSoilProfile(0.7, soilProfile1D);
+ var stochasticSoilProfile1D = new StochasticSoilProfile(random.NextDouble(), soilProfile1D);
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName,
FailureMechanismType.Stability, new[]
@@ -352,22 +374,67 @@
.Where(t => t != FailureMechanismType.Stability);
}
- private static IEnumerable GetValidConfiguredAndSupportedSoilProfiles()
+ private static IEnumerable GetSupportedStochasticSoilProfilesWithInvalidProbabilities()
{
+ var invalidProbabilities = new[]
+ {
+ double.NaN,
+ double.NegativeInfinity,
+ double.PositiveInfinity,
+ 1.1,
+ -0.1,
+ 5,
+ -5
+ };
+
+ const long id = 1;
+ const string name = "test";
+ foreach (double invalidProbability in invalidProbabilities)
+ {
+ yield return new TestCaseData(new StochasticSoilProfile(invalidProbability,
+ new SoilProfile2D(id,
+ name,
+ new[]
+ {
+ SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
+ }, Enumerable.Empty())))
+ .SetName($"2D Soil Profile - {invalidProbability}");
+ yield return new TestCaseData(new StochasticSoilProfile(invalidProbability,
+ new SoilProfile1D(id,
+ name,
+ 1,
+ new[]
+ {
+ SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
+ })))
+ .SetName($"1D Soil Profile - {invalidProbability}");
+ }
+ }
+
+ private static IEnumerable GetValidConfiguredAndSupportedSoilProfiles()
+ {
var random = new Random(21);
const long id = 1;
const string name = "test";
- yield return new SoilProfile2D(id, name, new[]
- {
- SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
- }, Enumerable.Empty());
+ yield return new TestCaseData(new SoilProfile2D(id,
+ name,
+ new[]
+ {
+ SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
+ },
+ Enumerable.Empty()))
+ .SetName("2D Soil Profile");
- yield return new SoilProfile1D(id, name, random.NextDouble(), new []
- {
- SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
- });
+ yield return new TestCaseData(new SoilProfile1D(id,
+ name,
+ random.NextDouble(),
+ new[]
+ {
+ SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
+ }))
+ .SetName("1D Soil Profile");
}
}
}
\ No newline at end of file
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformerTest.cs
===================================================================
diff -u -r74be63b9f6ac8bc60a6754667a3bcee0485853a0 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilProfileTransformerTest.cs) (revision 74be63b9f6ac8bc60a6754667a3bcee0485853a0)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsStochasticSoilProfileTransformerTest.cs (.../MacroStabilityInwardsStochasticSoilProfileTransformerTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -22,10 +22,11 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
+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
{
@@ -57,7 +58,7 @@
var soilProfile = mocks.Stub();
mocks.ReplayAll();
- var stochasticSoilProfile = new StochasticSoilProfile(0, soilProfile);
+ StochasticSoilProfile stochasticSoilProfile = StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(soilProfile);
// Call
TestDelegate call = () => MacroStabilityInwardsStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, null);
@@ -68,17 +69,43 @@
mocks.VerifyAll();
}
+ [Test]
+ [TestCase(double.NaN)]
+ [TestCase(1.1)]
+ [TestCase(-0.1)]
+ public void Transform_StochasticSoilProfileWithInvalidProbability_ThrowsImportedDataTransformException(double probability)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var soilProfile = mocks.Stub();
+ var macroStabilityInwardsSoilProfile = mocks.Stub();
+ mocks.ReplayAll();
+ var stochasticSoilProfile = new StochasticSoilProfile(probability, soilProfile);
+
+ // Call
+ TestDelegate call = () => MacroStabilityInwardsStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, macroStabilityInwardsSoilProfile);
+
+ // Assert
+ var exception = Assert.Throws(call);
+
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+
[Test]
public void Transform_ValidData_ReturnExpectedMacroStabilityInwardsStochasticSoilProfile()
{
// Setup
+ var random = new Random(21);
+
var mocks = new MockRepository();
var soilProfile = mocks.Stub();
var macroStabilityInwardsSoilProfile = mocks.Stub();
mocks.ReplayAll();
- var stochasticSoilProfile = new StochasticSoilProfile(new Random(9).NextDouble(), soilProfile);
+ var stochasticSoilProfile = new StochasticSoilProfile(random.NextDouble(), soilProfile);
// Call
MacroStabilityInwardsStochasticSoilProfile macroStabilityInwardsStochasticSoilProfile
Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingStochasticSoilProfileTransformer.cs
===================================================================
diff -u -r74be63b9f6ac8bc60a6754667a3bcee0485853a0 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingStochasticSoilProfileTransformer.cs (.../PipingStochasticSoilProfileTransformer.cs) (revision 74be63b9f6ac8bc60a6754667a3bcee0485853a0)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/SoilProfiles/PipingStochasticSoilProfileTransformer.cs (.../PipingStochasticSoilProfileTransformer.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -20,6 +20,7 @@
// All rights reserved.
using System;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.Primitives;
@@ -38,6 +39,8 @@
/// The transformed piping soil profile.
/// A new based on the given data.
/// Thrown when any parameter is null.
+ /// Thrown when
+ /// could not be transformed.
public static PipingStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile, PipingSoilProfile soilProfile)
{
if (stochasticSoilProfile == null)
@@ -49,7 +52,14 @@
throw new ArgumentNullException(nameof(soilProfile));
}
- return new PipingStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile);
+ try
+ {
+ return new PipingStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile);
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ throw new ImportedDataTransformException(e.Message, e);
+ }
}
}
}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj
===================================================================
diff -u -ra1fa1538918813373bcc864f0bce092bf28fd0ce -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision a1fa1538918813373bcc864f0bce092bf28fd0ce)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Ringtoets.Piping.IO.Test.csproj (.../Ringtoets.Piping.IO.Test.csproj) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -100,6 +100,10 @@
{4843D6E5-066F-4795-94F5-1D53932DD03C}
Ringtoets.Common.Data.TestUtil
+
+ {516E7E2A-83F6-43EB-895A-A1F4F90FA531}
+ Ringtoets.Common.IO.TestUtil.Test
+
{33508D7C-1602-4C0D-8503-73AAE98C19E5}
Ringtoets.Common.IO.TestUtil
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilModelTransformerTest.cs
===================================================================
diff -u -rc5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilModelTransformerTest.cs (.../PipingStochasticSoilModelTransformerTest.cs) (revision c5c91f8ca724aef52a6cd9055a2a32bcd6bc0c03)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilModelTransformerTest.cs (.../PipingStochasticSoilModelTransformerTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -85,7 +85,7 @@
var transformer = new PipingStochasticSoilModelTransformer();
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry("some name", FailureMechanismType.Piping, new[]
{
- new StochasticSoilProfile(1.0, new TestSoilProfile())
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(new TestSoilProfile())
});
// Call
@@ -106,7 +106,7 @@
var transformer = new PipingStochasticSoilModelTransformer();
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(name, FailureMechanismType.Piping, new[]
{
- new StochasticSoilProfile(1.0, new SoilProfile2D(0, name, new[]
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(new SoilProfile2D(0, name, new[]
{
new SoilLayer2D()
}, Enumerable.Empty()))
@@ -145,6 +145,7 @@
public void Transform_ValidStochasticSoilModelWithSoilProfile2D_ReturnsExpectedPipingStochasticSoilModel()
{
// Setup
+ var random = new Random(21);
const string name = "name";
const double intersectionX = 1.0;
@@ -158,11 +159,12 @@
};
var transformer = new PipingStochasticSoilModelTransformer();
+ double probability = random.NextDouble();
var soilModel = new StochasticSoilModel(name, FailureMechanismType.Piping)
{
StochasticSoilProfiles =
{
- new StochasticSoilProfile(1.0, profile)
+ new StochasticSoilProfile(probability, profile)
},
Geometry =
{
@@ -181,7 +183,7 @@
var expectedPipingSoilProfile = new List
{
- new PipingStochasticSoilProfile(1.0, PipingSoilProfileTransformer.Transform(profile))
+ new PipingStochasticSoilProfile(probability, PipingSoilProfileTransformer.Transform(profile))
};
AssertPipingStochasticSoilProfiles(expectedPipingSoilProfile, transformed.StochasticSoilProfiles);
}
@@ -205,12 +207,12 @@
var transformer = new PipingStochasticSoilModelTransformer();
StochasticSoilModel soilModel1 = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(name, FailureMechanismType.Piping, new[]
{
- new StochasticSoilProfile(1.0, profile)
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile)
});
StochasticSoilModel soilModel2 = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(name, FailureMechanismType.Piping, new[]
{
- new StochasticSoilProfile(1.0, profile)
+ StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile)
});
// Call
@@ -272,6 +274,31 @@
[Test]
[SetCulture("nl-NL")]
+ [TestCaseSource(nameof(GetSupportedStochasticSoilProfilesWithInvalidProbabilities))]
+ public void Transform_ValidStochasticSoilModelWithStochasticProfileInvalidProbability_ThrowsImportedDataException(StochasticSoilProfile profile)
+ {
+ const string soilModelName = "name";
+
+ StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName,
+ FailureMechanismType.Piping, new[]
+ {
+ profile
+ });
+
+ var transformer = new PipingStochasticSoilModelTransformer();
+
+ // Call
+ TestDelegate call = () => transformer.Transform(soilModel);
+
+ // Assert
+ var exception = Assert.Throws(call);
+ const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel " +
+ "moet in het bereik [0,0, 1,0] liggen.";
+ StringAssert.StartsWith(expectedMessage, exception.Message);
+ }
+
+ [Test]
+ [SetCulture("nl-NL")]
[TestCaseSource(nameof(GetValidConfiguredAndSupportedSoilProfiles))]
public void Transform_ValidStochasticSoilModelWithSameProfileProbabilityExceedingValidRange_ThrowsImportedDataException(ISoilProfile profile)
{
@@ -300,6 +327,8 @@
public void Transform_ValidStochasticSoilModelWithSimilarProfileInTwoStochasticSoilProfiles_ReturnsExpectedPipingStochasticSoilModel()
{
// Setup
+ var random = new Random(21);
+
const string soilModelName = "name";
const string soilProfileName = "SoilProfile";
const double intersectionX = 1.0;
@@ -311,13 +340,13 @@
{
IntersectionX = intersectionX
};
- var stochasticSoilProfile2D = new StochasticSoilProfile(0.2, soilProfile2D);
+ var stochasticSoilProfile2D = new StochasticSoilProfile(random.NextDouble(), soilProfile2D);
var soilProfile1D = new SoilProfile1D(0, soilProfileName, 0, new[]
{
SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
});
- var stochasticSoilProfile1D = new StochasticSoilProfile(0.2, soilProfile1D);
+ var stochasticSoilProfile1D = new StochasticSoilProfile(random.NextDouble(), soilProfile1D);
var transformer = new PipingStochasticSoilModelTransformer();
StochasticSoilModel soilModel = StochasticSoilModelTestFactory.CreateStochasticSoilModelWithGeometry(soilModelName, FailureMechanismType.Piping, new[]
@@ -365,25 +394,68 @@
.Where(t => t != FailureMechanismType.Piping);
}
- private static IEnumerable GetValidConfiguredAndSupportedSoilProfiles()
+ private static IEnumerable GetSupportedStochasticSoilProfilesWithInvalidProbabilities()
{
+ var invalidProbabilities = new[]
+ {
+ double.NaN,
+ double.NegativeInfinity,
+ double.PositiveInfinity,
+ 1.1,
+ -0.1,
+ 5,
+ -5
+ };
+
+ const long id = 1;
+ const string name = "test";
+ foreach (double invalidProbability in invalidProbabilities)
+ {
+ yield return new TestCaseData(new StochasticSoilProfile(invalidProbability,
+ new SoilProfile2D(id,
+ name,
+ new[]
+ {
+ SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
+ }, Enumerable.Empty())
+ {
+ IntersectionX = 1.0
+ }))
+ .SetName($"2D Soil Profile - {invalidProbability}");
+ yield return new TestCaseData(new StochasticSoilProfile(invalidProbability,
+ new SoilProfile1D(id,
+ name,
+ 1,
+ new[]
+ {
+ SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
+ })))
+ .SetName($"1D Soil Profile - {invalidProbability}");
+ }
+ }
+
+ private static IEnumerable GetValidConfiguredAndSupportedSoilProfiles()
+ {
var random = new Random(21);
const long id = 1;
const string name = "test";
- yield return new SoilProfile2D(id, name, new[]
- {
- SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
- }, Enumerable.Empty())
- {
- IntersectionX = random.NextDouble()
- };
+ yield return new TestCaseData(new SoilProfile2D(id, name, new[]
+ {
+ SoilLayer2DTestFactory.CreateSoilLayer2DWithValidAquifer()
+ }, Enumerable.Empty())
+ {
+ IntersectionX = random.NextDouble()
+ })
+ .SetName("2D Profile");
- yield return new SoilProfile1D(id, name, random.NextDouble(), new[]
- {
- SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
- });
+ yield return new TestCaseData(new SoilProfile1D(id, name, random.NextDouble(),
+ new[]
+ {
+ SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
+ }))
+ .SetName("1D Profile");
}
}
}
\ No newline at end of file
Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilProfileTransformerTest.cs
===================================================================
diff -u -r6cf604a94300560817de70fd42d09baa5b22c3a6 -r30baf70ea42def18e66d1ec3c71aa0e54a89229a
--- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilProfileTransformerTest.cs (.../PipingStochasticSoilProfileTransformerTest.cs) (revision 6cf604a94300560817de70fd42d09baa5b22c3a6)
+++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/SoilProfiles/PipingStochasticSoilProfileTransformerTest.cs (.../PipingStochasticSoilProfileTransformerTest.cs) (revision 30baf70ea42def18e66d1ec3c71aa0e54a89229a)
@@ -22,7 +22,9 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
+using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SoilProfile;
+using Ringtoets.Common.IO.TestUtil;
using Ringtoets.Piping.Data.SoilProfile;
using Ringtoets.Piping.IO.SoilProfiles;
using Ringtoets.Piping.Primitives;
@@ -55,7 +57,7 @@
var soilProfile = mockRepository.Stub();
mockRepository.ReplayAll();
- var stochasticSoilProfile = new StochasticSoilProfile(0, soilProfile);
+ var stochasticSoilProfile = StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(soilProfile);
// Call
TestDelegate test = () => PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, null);
@@ -67,16 +69,44 @@
}
[Test]
+ [TestCase(double.NaN)]
+ [TestCase(1.1)]
+ [TestCase(-0.1)]
+ public void Transform_StochasticSoilProfileWithInvalidProbability_ThrowsImportedDataTransformException(double probability)
+ {
+ // Setup
+ var mocks = new MockRepository();
+ var soilProfile = mocks.Stub();
+ mocks.ReplayAll();
+
+ PipingSoilProfile pipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
+
+ var stochasticSoilProfile = new StochasticSoilProfile(probability, soilProfile);
+
+ // Call
+ TestDelegate call = () => PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, pipingSoilProfile);
+
+ // Assert
+ var exception = Assert.Throws(call);
+
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ Assert.AreEqual(innerException.Message, exception.Message);
+ }
+
+ [Test]
public void Transform_ValidStochasticSoilProfile_ReturnsExpectedPipingStochasticSoilProfile()
{
// Setup
+ var random = new Random(21);
+
var mockRepository = new MockRepository();
var soilProfile = mockRepository.Stub();
mockRepository.ReplayAll();
PipingSoilProfile pipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
- var stochasticSoilProfile = new StochasticSoilProfile(new Random(9).NextDouble(), soilProfile);
+ var stochasticSoilProfile = new StochasticSoilProfile(random.NextDouble(), soilProfile);
// Call
PipingStochasticSoilProfile pipingStochasticSoilProfile = PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, pipingSoilProfile);