// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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 Deltares.Dam.Data; using Deltares.Dam.Data.CsvImporters; using Deltares.Geometry; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DikeTest { private Dike dike; private Segment segment1; private Location location1; private SurfaceLine2 surfaceLine1; private SoilProfile1D soilProfile; [TearDown] public void TearDown() { dike.Dispose(); } [SetUp] public void TestFixtureSetup() {} [SetUp] public void TestSetup() { // Dike dike = new Dike(); dike.Name = "Dike"; // Segments segment1 = new Segment { Name = "Segment1" }; // this.dike.Segments.Add(this.segment1); // Locations location1 = new Location(); location1.Name = "Location1"; location1.Segment = segment1; dike.Locations.Add(location1); // Surface lines surfaceLine1 = new SurfaceLine2 { Geometry = new LocalizedGeometryPointString(), CharacteristicPoints = { GeometryMustContainPoint = true }, Name = "SurfaceLine1" }; dike.SurfaceLines2.Add(surfaceLine1); // Soil profiles soilProfile = new SoilProfile1D { Name = "SoilProfile1" }; dike.SoilProfiles.Add(soilProfile); // Locations' Segments location1.Segment = segment1; // Locations' surface lines location1.SurfaceLine2 = surfaceLine1; // Segments' Soil profile probabilities segment1.AddSoilProfileProbability(soilProfile, 100.0, FailureMechanismSystemType.StabilityInside); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(15.3, 0.0, -3.52)); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(19.4, 0.0, -1.46), CharacteristicPointType.DikeToeAtRiver); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(27.4, 0.0, 8.56), CharacteristicPointType.DikeTopAtRiver); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(35.2, 0.0, 8.62), CharacteristicPointType.DikeTopAtPolder); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(41.5, 0.0, -3.76), CharacteristicPointType.DikeToeAtPolder); surfaceLine1.AddCharacteristicPoint(new GeometryPoint(85.4, 0.0, -3.61)); } [Test] public void DefaultConstructor_ExpectedValues() { // setup // call using (var newDike = new Dike()) { // assert Assert.AreEqual(0, newDike.SurfaceLines2.Count); Assert.AreEqual(0, newDike.Locations.Count); } } [Test] public void TestDikeIntegrity() { Assert.IsNotNull(dike); Assert.AreEqual("Dike", dike.Name); //Assert.IsNotNull(this.dike.Segments); Assert.IsNotNull(dike.Locations); Assert.IsNotNull(dike.SurfaceLines2); Assert.IsNotNull(dike.SoilProfiles); } // [Test] // public void TestDikeSegments() // { // Assert.IsNotNull(this.segment1); // // Assert.AreEqual(1, this.dike.Segments.Count); // Assert.AreEqual(this.segment1, this.dike.Segments[0]); // Assert.AreEqual("Segment1", this.segment1.Name); // Assert.IsNotNull(this.segment1.GetMostProbableProfile(SegmentFailureMechanismType.Stability)); // } [Test] public void TestDikeLocations() { Assert.IsNotNull(location1); Assert.AreEqual(1, dike.Locations.Count); Assert.AreEqual(location1, dike.Locations[0]); Assert.AreEqual("Location1", location1.Name); } [Test] public void TestDikeSurfaceLines() { Assert.IsNotNull(surfaceLine1); Assert.IsNotNull(surfaceLine1.Geometry.Points); Assert.AreEqual(1, dike.SurfaceLines2.Count); Assert.AreEqual(surfaceLine1, dike.SurfaceLines2[0]); Assert.AreEqual("SurfaceLine1", surfaceLine1.Name); } [Test] public void TestDikeSoilProfiles() { Assert.IsNotNull(soilProfile); Assert.AreEqual(1, dike.SoilProfiles.Count); Assert.AreEqual(soilProfile, dike.SoilProfiles[0]); Assert.AreEqual("SoilProfile1", soilProfile.Name); } [Test] public void TestDikeLocationSegments() { Assert.IsNotNull(location1.Segment); Assert.AreEqual(segment1, location1.Segment); } [Test] public void TestDikeLocationSurfaceLines() { Assert.IsNotNull(location1.SurfaceLine2); Assert.AreEqual(surfaceLine1, location1.SurfaceLine2); } [Test] public void TestDikeSegmentsSoilProfileProbabilities() { Assert.AreEqual(100, segment1.GetSoilProfileProbability(soilProfile, FailureMechanismSystemType.StabilityInside)); } [Test] public void TestDikeSegmentsSurfaceLinePoints() { IList points = surfaceLine1.Geometry.Points; Assert.AreEqual(6, points.Count); Assert.AreEqual(15.3, points[0].X); Assert.AreEqual(-3.52, points[0].Z); Assert.AreEqual(19.4, points[1].X); Assert.AreEqual(-1.46, points[1].Z); Assert.AreEqual(points[1], surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtRiver)); Assert.AreEqual(points[2], surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtRiver)); Assert.AreEqual(points[3], surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder)); Assert.AreEqual(points[4], surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder)); Assert.AreEqual(0, surfaceLine1.GetCharacteristicPoints(points[0]).Count(cpt => cpt != CharacteristicPointType.None)); Assert.AreEqual(CharacteristicPointType.DikeToeAtRiver, surfaceLine1.GetCharacteristicPoints(points[1]).First()); Assert.IsTrue(surfaceLine1.HasDike()); } [Test] public void TestFillDataBaseSoilListFromCsvFileWithoutSoilRecords_ThenNoDataBaseSoilsArePresent() { var newDike = new Dike(); newDike.FillImportedCsvSoilsFromCsvFile(new List()); Assert.That(newDike.ImportedCsvSoils.Count, Is.Zero); } [Test] public void TestFillDataBaseSoilListFromCsvFileWithSoilRecords_ThenDataBaseSoilsAreFilled() { var newDike = new Dike(); var random = new Random(21); var soilRecords = new List { new() { SoilName = "Soil_1", SoilColor = Color.Black, SoilType = SoilType.Sand, SaturatedUnitWeight = random.NextDouble(), UnsaturatedUnitWeight = random.NextDouble(), Cohesion = random.NextDouble(), FrictionAngle = random.NextDouble(), DiameterD70 = random.NextDouble(), PermeabilityX = random.NextDouble(), ShearStrengthModel = ShearStrengthModel.CPhi, StrengthIncreaseExponent = random.NextDouble(), RatioSuPc = random.NextDouble(), UsePop = true, Pop = random.NextDouble() }, new() { SoilName = "Soil_2", SoilColor = Color.White, SoilType = SoilType.Clay, SaturatedUnitWeight = random.NextDouble(), UnsaturatedUnitWeight = random.NextDouble(), Cohesion = random.NextDouble(), FrictionAngle = random.NextDouble(), DiameterD70 = random.NextDouble(), PermeabilityX = random.NextDouble(), ShearStrengthModel = ShearStrengthModel.CuCalculated, StrengthIncreaseExponent = random.NextDouble(), RatioSuPc = random.NextDouble(), UsePop = false, Pop = random.NextDouble() } }; newDike.FillImportedCsvSoilsFromCsvFile(soilRecords); Assert.That(newDike.ImportedCsvSoils.Count, Is.EqualTo(2)); for (var i = 0; i < newDike.ImportedCsvSoils.Count; i++) { Soil soil = newDike.ImportedCsvSoils[i]; CsvImporterSoils.SoilRecord soilRecord = soilRecords[i]; Assert.That(soil.Name, Is.EqualTo(soilRecord.SoilName)); Assert.That(soil.Color, Is.EqualTo(soilRecord.SoilColor)); Assert.That(soil.SoilType, Is.EqualTo(soilRecord.SoilType)); Assert.That(soil.AbovePhreaticLevel, Is.EqualTo(soilRecord.UnsaturatedUnitWeight)); Assert.That(soil.BelowPhreaticLevel, Is.EqualTo(soilRecord.SaturatedUnitWeight)); Assert.That(soil.Cohesion, Is.EqualTo(soilRecord.Cohesion)); Assert.That(soil.FrictionAngle, Is.EqualTo(soilRecord.FrictionAngle)); Assert.That(soil.DiameterD70, Is.EqualTo(soilRecord.DiameterD70)); Assert.That(soil.PermeabKx, Is.EqualTo(soilRecord.PermeabilityX)); Assert.That(soil.ShearStrengthModel, Is.EqualTo(soilRecord.ShearStrengthModel)); Assert.That(soil.StrengthIncreaseExponent, Is.EqualTo(soilRecord.StrengthIncreaseExponent)); Assert.That(soil.RatioCuPc, Is.EqualTo(soilRecord.RatioSuPc)); switch (i) { case 0: Assert.That(soil.POP, Is.EqualTo(soilRecord.Pop)); break; case 1: Assert.That(soil.POP, Is.NaN); break; } } } } }