// Copyright (C) Stichting Deltares 2025. 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.Collections.Generic; using Deltares.Geometry; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard.Language; using Deltares.Standard.Validation; using NUnit.Framework; namespace Deltares.Dam.Data.Tests; [TestFixture] public class LocationTests { [Test] [TestCase(CharacteristicPointType.InsertRiverChannel, true)] [TestCase(CharacteristicPointType.SurfaceLevelOutside, false)] [TestCase(CharacteristicPointType.DikeToeAtRiver, false)] [TestCase(CharacteristicPointType.DikeTopAtRiver, false)] [TestCase(CharacteristicPointType.DikeTopAtPolder, false)] [TestCase(CharacteristicPointType.DikeToeAtPolder, false)] [TestCase(CharacteristicPointType.SurfaceLevelInside, false)] public void GivenSurfaceLine_WhenValidatingTheRequiredCharacteristicPoints_ReturnsExpectedResult(CharacteristicPointType typeNotPresent, bool isValid) { SurfaceLine2 surfaceLine = CreateSurfaceLine(typeNotPresent); var location = new Location(); location.LocalXZSurfaceLine2 = surfaceLine; ValidationResult[] validationResults = location.ValidateRequiredCharacteristicPoints(); if (isValid) { Assert.That(validationResults, Is.Null); } else { Assert.That(validationResults, Has.Length.EqualTo(1)); Assert.Multiple(() => { Assert.That(validationResults[0].Subject, Is.EqualTo(surfaceLine)); Assert.That(validationResults[0].Text, Is.EqualTo("Not all the required characteristic points (see user manual) are available in the surface line.")); }); } } [Test] public void CheckNameValuePairGetSet() { const double cTolerance = 0.00001; var expectedLocation = new Location(); expectedLocation.Name = "Sand"; expectedLocation.DampingFactorPL3 = 11.11; var actualLocation = new Location(); Dictionary nameValuePairs = expectedLocation.GetParametersAsNameValuePairs(); foreach (KeyValuePair soilDetail in nameValuePairs) { actualLocation.SetParameterFromNameValuePair(soilDetail.Key, soilDetail.Value); } Assert.That(actualLocation.DampingFactorPL3, Is.EqualTo(expectedLocation.DampingFactorPL3).Within(cTolerance)); } [Test] public void Location_ConstructNewInstance_HasDefaultValuesSet() { // setup const bool areLocalXzObjectsCreated = false; const double penetrationLength = 0.0; const double trafficLoad = 0.0; const PLLineCreationMethod plLineCreationMethod = PLLineCreationMethod.ExpertKnowledgeRRD; const double stabilityShoulderGrowSlope = 0.3333333333333; const double stabilityShoulderGrowDeltaX = 2.0; const double stabilitySlopeAdaptionDeltaX = 2.0; // call var actualLocation = new Location(); // assert Assert.That(actualLocation.AreLocalXZObjectsCreated, Is.EqualTo(areLocalXzObjectsCreated)); Assert.That(actualLocation.PenetrationLength, Is.EqualTo(penetrationLength)); Assert.That(actualLocation.TrafficLoad, Is.EqualTo(trafficLoad)); Assert.That(actualLocation.TrafficLoadDistributionAngle, Is.EqualTo(null)); Assert.That(actualLocation.PLLineCreationMethod, Is.EqualTo(plLineCreationMethod)); Assert.That(actualLocation.IntrusionVerticalWaterPressure, Is.EqualTo(IntrusionVerticalWaterPressureType.Standard)); Assert.That(actualLocation.StabilityShoulderGrowSlope, Is.EqualTo(stabilityShoulderGrowSlope).Within(1e-12)); Assert.That(actualLocation.StabilityShoulderGrowDeltaX, Is.EqualTo(stabilityShoulderGrowDeltaX)); Assert.That(actualLocation.StabilitySlopeAdaptionDeltaX, Is.EqualTo(stabilitySlopeAdaptionDeltaX)); } [Test] [TestCase(0, IntrusionVerticalWaterPressureType.Standard, "")] [TestCase(0, IntrusionVerticalWaterPressureType.HydroStatic, "")] [TestCase(0, IntrusionVerticalWaterPressureType.FullHydroStatic, "")] [TestCase(0, IntrusionVerticalWaterPressureType.Linear, "")] [TestCase(0, IntrusionVerticalWaterPressureType.SemiTimeDependent, "UseOfSemiTimeDependentModelWithoutPenetrationLength")] [TestCase(1, IntrusionVerticalWaterPressureType.Standard, "UseOfPenetrationLengthWithoutSemiTimeDependentModel")] [TestCase(1, IntrusionVerticalWaterPressureType.HydroStatic, "UseOfPenetrationLengthWithoutSemiTimeDependentModel")] [TestCase(1, IntrusionVerticalWaterPressureType.FullHydroStatic, "UseOfPenetrationLengthWithoutSemiTimeDependentModel")] [TestCase(1, IntrusionVerticalWaterPressureType.Linear, "UseOfPenetrationLengthWithoutSemiTimeDependentModel")] [TestCase(1, IntrusionVerticalWaterPressureType.SemiTimeDependent, "")] public void GivenPenetrationLengthWithIntrusionVerticalWaterPressureType_WhenValidating_ReturnsExpectedWarning(double penetrationLength, IntrusionVerticalWaterPressureType model, string expectedWarning) { var location = new Location(); location.IntrusionVerticalWaterPressure = model; location.PenetrationLength = penetrationLength; ValidationResult[] validationResults = location.ValidateLocationUseOfPenetrationLength(); if (expectedWarning == "") { Assert.That(validationResults, Has.Length.EqualTo(0)); } else { Assert.Multiple(() => { Assert.That(validationResults, Has.Length.EqualTo(1)); Assert.That(validationResults[0].MessageType, Is.EqualTo(ValidationResultType.Warning)); string header = LocalizationManager.GetTranslatedText(typeof(Location), "IntrusionVerticalWaterPressure"); string selectedModel = LocalizationManager.GetTranslatedText(typeof(Location), model.ToString()); string message = string.Format(LocalizationManager.GetTranslatedText(typeof(Location), expectedWarning), header, selectedModel); Assert.That(validationResults[0].Text, Is.EqualTo(message)); }); } } private static SurfaceLine2 CreateSurfaceLine(CharacteristicPointType typeNotPresent) { var gp0 = new GeometryPoint(0.0, 0.0, 0.0); var gp1 = new GeometryPoint(1.0, 0.0, 0.0); var gp2 = new GeometryPoint(2.0, 0.0, 1.0); var gp3 = new GeometryPoint(4.0, 0.0, 1.0); var gp4 = new GeometryPoint(10.0, 0.0, 0.0); var gp5 = new GeometryPoint(12.0, 0.0, 0.0); var line = new LocalizedGeometryPointString(); line.Points.Add(gp0); line.Points.Add(new GeometryPoint(0.1, 0.0, 0.0)); line.Points.Add(new GeometryPoint(0.9, 0.0, 0.0)); line.Points.Add(gp1); line.Points.Add(gp2); line.Points.Add(gp3); line.Points.Add(new GeometryPoint(4.1, 0.0, 1.0)); line.Points.Add(new GeometryPoint(4.1, 0.0, 1.0)); line.Points.Add(gp4); line.Points.Add(gp5); var surfaceLine = new SurfaceLine2 { Geometry = line }; if (typeNotPresent != CharacteristicPointType.SurfaceLevelOutside) { surfaceLine.AddCharacteristicPoint(gp0, CharacteristicPointType.SurfaceLevelOutside); } if (typeNotPresent != CharacteristicPointType.DikeToeAtRiver) { surfaceLine.AddCharacteristicPoint(gp0, CharacteristicPointType.DikeToeAtRiver); } if (typeNotPresent != CharacteristicPointType.DikeTopAtRiver) { surfaceLine.AddCharacteristicPoint(gp2, CharacteristicPointType.DikeTopAtRiver); } if (typeNotPresent != CharacteristicPointType.DikeTopAtPolder) { surfaceLine.AddCharacteristicPoint(gp3, CharacteristicPointType.DikeTopAtPolder); } if (typeNotPresent != CharacteristicPointType.DikeToeAtPolder) { surfaceLine.AddCharacteristicPoint(gp4, CharacteristicPointType.DikeToeAtPolder); } if (typeNotPresent != CharacteristicPointType.SurfaceLevelInside) { surfaceLine.AddCharacteristicPoint(gp5, CharacteristicPointType.SurfaceLevelInside); } return surfaceLine; } }