// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - Live. // // DAM - Live is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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.Linq; using Deltares.DamLive.Application; using Deltares.Dam.Data; using Deltares.DamLive.TestHelper; using NUnit.Framework; namespace Deltares.DamLive.Tests; [TestFixture] public class DamLivePulauTekongTests { private const double cTolerance = 0.0005; [Test] [Category("Integration")] public void CalculateStability2DBishopInsideUsingTestFilesHasExpectedResultsInOutputFile() { const string testWorkingFolder = @".\damLivePulauTekongInside"; const string testStabilityDataFolder = @"..\..\..\..\data\PulauTekong\PulauTekong_inside"; SetupStabilityProject(testWorkingFolder, testStabilityDataFolder); GeneralHelper.InitializeRunner(runner, 1); runner.Run(); // Assertions GeneralHelper.AssertNoErrors(runner); List series = runner.OutputTimeSeriesCollection.Series; var seriesCount = 0; var isFirstResultFound = false; var isLastResultFound = false; var isFirstCircleXFound = false; var isFirstCircleZFound = false; var isFirstRadiusFound = false; string[] validParameterIDs = Enum.GetNames(typeof(TimeSerieParameters)); foreach (TimeSerie timeSeries in series) { Assert.Multiple(() => { Assert.That(validParameterIDs.Any(n => n == timeSeries.ParameterId), Is.True); Assert.That(locations.Any(l => l.Name == timeSeries.LocationId), Is.True); }); if (timeSeries.LocationId == "CD CS1 X1") { if (timeSeries.ParameterId == TimeSerieParameters.StabilityInsideFactor.ToString()) { isFirstResultFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.439).Within(cTolerance), "The computed safety factory is not correct"); } if (timeSeries.ParameterId == TimeSerieParameters.BishopCircleCentreX.ToString()) { isFirstCircleXFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(32.875).Within(cTolerance), "The computed bishop circle centre X is not correct"); } if (timeSeries.ParameterId == TimeSerieParameters.BishopCircleCentreZ.ToString()) { isFirstCircleZFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(109.375).Within(cTolerance), "The computed bishop circle centre Z is not correct"); } if (timeSeries.ParameterId == TimeSerieParameters.BishopCircleRadius.ToString()) { isFirstRadiusFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(13.575).Within(cTolerance), "The computed bishop circle radius is not correct"); } } if (timeSeries.LocationId == "SD CS3 10-10") { if (timeSeries.ParameterId == TimeSerieParameters.StabilityInsideFactor.ToString()) { isLastResultFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(0.997).Within(cTolerance), "The computed safety factory is not correct"); } } seriesCount++; } Assert.Multiple(() => { Assert.That(seriesCount, Is.EqualTo(20)); Assert.That(isFirstResultFound, Is.True, "The first location has no output for stability inside"); Assert.That(isLastResultFound, Is.True, "The last location has no output for stability inside"); Assert.That(isFirstCircleXFound, Is.True, "The first location has no output for bishop circle centre X"); Assert.That(isFirstCircleZFound, Is.True, "The first location has no output for bishop circle centre Z"); Assert.That(isFirstRadiusFound, Is.True, "The first location has no output for bishop circle radius"); }); } [Test] [Category("Integration")] public void CalculateStability2DBishopOutsideUsingTestFilesHasExpectedResultsInOutputFile() { const string testWorkingFolder = @".\damLivePulauTekongOutside"; const string testStabilityDataFolder = @"..\..\..\..\data\PulauTekong\PulauTekong_outside"; SetupStabilityProject(testWorkingFolder, testStabilityDataFolder); GeneralHelper.InitializeRunner(runner, 1); runner.Run(); //runner.WriteResultsToFile(outputFile); // Assertions GeneralHelper.AssertNoErrors(runner); List series = runner.OutputTimeSeriesCollection.Series; var seriesCount = 0; var isFirstResultFound = false; var isLastResultFound = false; string[] validParameterIDs = Enum.GetNames(typeof(TimeSerieParameters)); foreach (TimeSerie timeSeries in series) { Assert.Multiple(() => { Assert.That(validParameterIDs.Any(n => n == timeSeries.ParameterId), Is.True); Assert.That(locations.Any(l => l.Name == timeSeries.LocationId), Is.True); }); if (timeSeries.LocationId == "SD CS1 3-3") { if (timeSeries.ParameterId == TimeSerieParameters.StabilityOutsideFactor.ToString()) { isFirstResultFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.222).Within(cTolerance), "The computed safety factory is not correct"); } } if (timeSeries.LocationId == "SD CS3 10-10") { if (timeSeries.ParameterId == TimeSerieParameters.StabilityOutsideFactor.ToString()) { isLastResultFound = true; TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.282).Within(cTolerance), "The computed safety factory is not correct"); } } seriesCount++; } Assert.Multiple(() => { Assert.That(seriesCount, Is.EqualTo(12)); Assert.That(isFirstResultFound, Is.True, "The first location has no output for stability outside"); Assert.That(isLastResultFound, Is.True, "The last location has no output for stability outside"); }); } #region Test Setup private const string projectStabilityFilename = @"PulauTekong.damx"; private List locations; private DamEngineRunner runner; /// /// Sets up the stability project. /// private void SetupStabilityProject(string testWorkingFolder, string testStabilityDataFolder) { IoHelper.RemoveTestWorkingDirectory(testWorkingFolder); // to be sure no test directory exist from previous tests GeneralHelper.SetupIntegrationProject(testWorkingFolder, testStabilityDataFolder, projectStabilityFilename, out runner, out locations); } #endregion }