Index: test/Plugins/Wti/Wti.IO.Test/Builders/SoilLayer2DTest.cs =================================================================== diff -u -r947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa -r2423a70958e7fecfc92afa462c34194cc695a81e --- test/Plugins/Wti/Wti.IO.Test/Builders/SoilLayer2DTest.cs (.../SoilLayer2DTest.cs) (revision 947dc8ecd6e0b674f39bf1a22aef489ec8cc21fa) +++ test/Plugins/Wti/Wti.IO.Test/Builders/SoilLayer2DTest.cs (.../SoilLayer2DTest.cs) (revision 2423a70958e7fecfc92afa462c34194cc695a81e) @@ -3,7 +3,9 @@ using System.Linq; using NUnit.Framework; using Wti.Data; +using Wti.Data.TestUtil; using Wti.IO.Builders; +using Wti.IO.Properties; namespace Wti.IO.Test.Builders { @@ -63,24 +65,352 @@ public void AsPipingSoilLayers_WithOuterLoopIntersectingX_ReturnsBottomAndLayerWithTop() { // Setup + var expectedZ = new Random(22).NextDouble(); var layer = new SoilLayer2D { OuterLoop = new HashSet { new Point3D { - X = 0.1, Z = new Random(22).NextDouble() + X = -0.1, Z = expectedZ + }, + new Point3D + { + X = 0.1, Z = expectedZ } } }; double bottom; // Call - var result = layer.AsPipingSoilLayers(0.0, out bottom); + var result = layer.AsPipingSoilLayers(0.0, out bottom).ToArray(); // Assert - CollectionAssert.IsEmpty(result); - Assert.AreEqual(double.MaxValue, bottom); + Assert.AreEqual(1, result.Length); + Assert.AreEqual(expectedZ, bottom); + Assert.AreEqual(expectedZ, result[0].Top); } + + [Test] + public void AsPipingSoilLayers_OuterLoopComplex_ReturnsTwoLayers() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "..8.7...", + "..5.6...", + "..4..3..", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(2, result.Length); + Assert.AreEqual(1.0, bottom); + CollectionAssert.AreEquivalent(new[] { 5.0, 2.0 }, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopInnerLoopSimple_ReturnsTwoLayers() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + "........", + "..4..3..")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "...12...", + "........", + "........", + "...43...", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop + } + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(2, result.Length); + Assert.AreEqual(0, bottom); + CollectionAssert.AreEquivalent(new [] {5.0, 1.0}, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopInnerLoopComplex_ReturnsThreeLayers() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + "........", + "..4..3..")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "...1.2..", + "...87...", + "...56...", + "...4.3..", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop + } + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(3, result.Length); + Assert.AreEqual(0, bottom); + CollectionAssert.AreEquivalent(new[] { 5.0, 3.0, 1.0 }, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopMultipleInnerLoops_ReturnsThreeLayers() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + "........", + "..4..3..")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "...12...", + "...43...", + "........", + "........", + "........")); + + var innerLoop2 = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "........", + "........", + "........", + "...12...", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop, + innerLoop2 + } + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(3, result.Length); + Assert.AreEqual(0, bottom); + CollectionAssert.AreEquivalent(new[] { 5.0, 3.0, 1.0 }, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopOverlappingInnerLoop_ReturnsOneLayer() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + ".4....3.", + "........")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "........", + "........", + "...12...", + "........", + "...43...")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop + } + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(1, result.Length); + Assert.AreEqual(2.0, bottom); + CollectionAssert.AreEquivalent(new[] { 5.0 }, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopOverlappingInnerLoopsFirstInnerLoopNotOverBottom_ReturnsOneLayer() + { + // Setup + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + ".4....3.", + "........")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "........", + "...12...", + "........", + "........", + "...43...")); + + var innerLoop2 = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "...12...", + "........", + "...43...", + "........", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop2, + innerLoop + } + }; + + // Call + double bottom; + var result = layer.AsPipingSoilLayers(3.5, out bottom).ToArray(); + + // Assert + Assert.AreEqual(1, result.Length); + Assert.AreEqual(4.0, bottom); + CollectionAssert.AreEquivalent(new[] { 5.0 }, result.Select(rl => rl.Top)); + } + + [Test] + public void AsPipingSoilLayers_OuterLoopVerticalAtX_ThrowsException() + { + // Setup + var atX = 2.0; + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + "........", + "..4..3..")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop + }; + + // Call + double bottom; + TestDelegate test = () => layer.AsPipingSoilLayers(atX, out bottom); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(String.Format(Resources.Error_CanNotDetermine1DProfileWithVerticalSegmentsAtX, atX), exception.Message); + } + + [Test] + public void AsPipingSoilLayers_InnerLoopVerticalAtX_ThrowsException() + { + // Setup + var atX = 3.0; + var outerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "..1..2..", + "........", + "........", + "........", + "........", + "..4..3..")); + + var innerLoop = PointCollectionHelper.CreateFromString(String.Join(Environment.NewLine, + "6", + "........", + "...1.2..", + "........", + "........", + "...4.3..", + "........")); + + var layer = new SoilLayer2D + { + OuterLoop = outerLoop, + InnerLoops = + { + innerLoop + } + }; + + // Call + double bottom; + TestDelegate test = () => layer.AsPipingSoilLayers(atX, out bottom); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual(String.Format(Resources.Error_CanNotDetermine1DProfileWithVerticalSegmentsAtX, atX), exception.Message); + } } } \ No newline at end of file