Index: DamClients/DamLive/trunk/src/Deltares.DamLive.Tests/StabilityInsideUpliftVanBeeSwarmTest.cs =================================================================== diff -u --- DamClients/DamLive/trunk/src/Deltares.DamLive.Tests/StabilityInsideUpliftVanBeeSwarmTest.cs (revision 0) +++ DamClients/DamLive/trunk/src/Deltares.DamLive.Tests/StabilityInsideUpliftVanBeeSwarmTest.cs (revision 4131) @@ -0,0 +1,140 @@ +// 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.Dam.Application.Live; +using Deltares.Dam.Data; +using Deltares.DamLive.TestHelper; +using NUnit.Framework; + +namespace Deltares.DamLive.Tests; + +public class StabilityInsideUpliftVanBeeSwarmTest +{ + const string projectIntegrationFilename = @"DAMLive.damx"; + const string input1AFilename = @"live.InputTimeSeriesMHW.xml"; + const string output1AFilename = @"live.OutputTimeSeriesMHW.xml"; + const string calculationParametersIntegrationFilename = @"live.ParametersFile.xml"; + + const string testWorkingFolder = @".\damLiveUpliftVanBeeSwarmWork"; + private const string testIntegrationDataFolder = @"..\..\..\data\IntegerationTests\StabilityInsideUpliftVanBeeSwarm"; + private List locations; + + private DamEngineRunner runner; + + [SetUp] + public void SetupFixture() + { + IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + 1); // to be sure no test directory exist from previous tests + IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + 20); + } + + [TearDown] + public void TearDownFixture() + { + IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + 1); + IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + 20); + } + + [TearDown] + public void TearDownTest() + { + GeneralHelper.AssertNoErrors(runner); + } + + [SetUp] + public void SetupTest() {} + + [Test] + [Category("Integration")] + [Category("Work_In_Progress")] + [TestCase(1)] + [TestCase(20)] + public void CalculateStabilityInsideUpliftVanBeeSwarmUsingTestFilesHasExpectedResultsInOutputFile(int maxCores) + { + const double cTolerance = 0.0005; + GeneralHelper.SetupIntegrationProject(maxCores, testWorkingFolder, testIntegrationDataFolder, input1AFilename, + output1AFilename, calculationParametersIntegrationFilename, + projectIntegrationFilename, out runner, out locations); + //SetupStabilityProject(maxCores); + runner.Initialize(); + runner.MaxCalculationCores = maxCores; + Assert.IsNotNull(runner); + Assert.IsNotNull(runner.DamProjectData); + Assert.IsNotNull(runner.CalculationParameters); + Assert.IsNotNull(runner.CalculationParameters.CalculationModules); + Assert.IsNotNull(runner.CalculationParameters.MStabParameters); + + runner.Run(); + //runner.WriteResultsToFile(outputFile); + + GeneralHelper.AssertNoErrors(runner); + + // Assertions + + List series = runner.OutputTimeSeriesCollection.Series; + + var seriesCount = 0; + var resultsCount = 0; + + string[] validParameterIDs = Enum.GetNames(typeof(TimeSerieParameters)); + foreach (TimeSerie timeSeries in series) + { + Assert.IsTrue(validParameterIDs.Any(n => n == timeSeries.ParameterId)); + Assert.IsTrue(locations.Any(l => l.Name == timeSeries.LocationId)); + // StabilityInside check + if (timeSeries.ParameterId == TimeSerieParameters.StabilityInsideFactor.ToString()) + { + resultsCount += timeSeries.Entries.Count; + if (timeSeries.LocationId == "Purmer_PU0042+00_K") + { + TimeSerieEntry firstEntry = timeSeries.Entries.First(); + Assert.AreEqual(1.456, firstEntry.Value, cTolerance, "The computed safety factory is not correct"); + TimeSerieEntry lastEntry = timeSeries.Entries.Last(); + Assert.AreEqual(1.583, lastEntry.Value, cTolerance, "The computed safety factory is not correct"); + } + + if (timeSeries.LocationId == "Purmer_PU0042+00_K_V") + { + TimeSerieEntry firstEntry = timeSeries.Entries.First(); + Assert.AreEqual(1.366, firstEntry.Value, cTolerance, "The computed safety factory is not correct"); + TimeSerieEntry lastEntry = timeSeries.Entries.Last(); + Assert.AreEqual(1.480, lastEntry.Value, cTolerance, "The computed safety factory is not correct"); + } + + if (timeSeries.LocationId == "Purmer_PU0110+20_R") + { + TimeSerieEntry firstEntry = timeSeries.Entries.First(); + Assert.AreEqual(Double.NaN, firstEntry.Value, cTolerance, "The computed safety factory is not correct"); + TimeSerieEntry lastEntry = timeSeries.Entries.Last(); + Assert.AreEqual(Double.NaN, lastEntry.Value, cTolerance, "The computed safety factory is not correct"); + } + } + + seriesCount++; + } + + Assert.IsTrue(seriesCount > 0, "No output time series"); + Assert.IsTrue(resultsCount == 16, "Incorrect number of results"); + } +} \ No newline at end of file