// Copyright (C) Stichting Deltares 2024. 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.Dam.Data; using Deltares.Standard.Language; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class LocationTest { [Test] public void CheckNameValuePairGetSet() { const double cTolerance = 0.00001; using ( var expectedLocation = new Location { Name = "Sand", DampingFactorPL3 = 11.11 }) using (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.TL_DegreeOfConsolidation, 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; Standard.Validation.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(Standard.Validation.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)); }); } } } }