// 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.IO;
using System.Linq;
using Deltares.DamLive.Application;
using Deltares.Dam.Data;
using Deltares.DamLive.TestHelper;
using NUnit.Framework;
namespace Deltares.DamLive.Tests;
[TestFixture]
[Category("Integration")]
public class StabilityInside2DTests
{
private const string projectIntegrationFilename = @"DAMLive.damx";
private const string inputFilename = @"live.InputTimeSeriesMHW.xml";
private const string outputFilename = @"live.OutputTimeSeriesMHW.xml";
private const string calculationParametersIntegrationFilename = @"live.ParametersFile.xml";
private const string testWorkingFolder = @".\damLive2DProfile";
private const string testIntegrationDataFolder = @"..\..\TestData\IntegrationTests\StabilityInside2D";
private List locations;
private DamEngineRunner runner;
[SetUp]
public void SetupFixture()
{
IoHelper.RemoveTestWorkingDirectory(testWorkingFolder);
}
[SetUp]
public void SetupTest() {}
[TearDown]
public void TearDownFixture()
{
IoHelper.RemoveTestWorkingDirectory(testWorkingFolder);
}
[Test, Category("Integration")]
public void Given2DProfileWithSensorData_WhenCalculatingStabilityInside_ThenReturnsExpectedResultsInOutputFile()
{
const double cTolerance = 0.00051;
const string testFileName = "CalculateStabilityInside2D";
GeneralHelper.SetupIntegrationProject(1, testWorkingFolder, testIntegrationDataFolder, inputFilename,
outputFilename, testFileName, calculationParametersIntegrationFilename,
projectIntegrationFilename, out runner, out locations);
runner.Initialize();
runner.MaxCalculationCores = 1;
Assert.That(runner, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(runner.DamProjectData, Is.Not.Null);
Assert.That(runner.CalculationParameters, Is.Not.Null);
});
Assert.Multiple(() =>
{
Assert.That(runner.CalculationParameters.CalculationModules, Is.Not.Null);
Assert.That(runner.CalculationParameters.StabilityParameters, Is.Not.Null);
});
runner.StabilityWorkingPath = Path.GetTempPath();
runner.Run();
runner.OutputTimeSeriesCollection.Save("StabilityInside2DOutputFile");
GeneralHelper.AssertNoErrors(runner);
List series = runner.OutputTimeSeriesCollection.Series;
var seriesCount = 0;
var resultsCount = 0;
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.ParameterId == TimeSerieParameters.StabilityInsideFactor.ToString())
{
Assert.Multiple(() =>
{
switch (timeSeries.LocationId)
{
case "LocationOnlyPL3":
{
TimeSerieEntry firstEntry = timeSeries.Entries.First();
Assert.That(firstEntry.Value, Is.EqualTo(1.433).Within(cTolerance), "The computed safety factory is not correct");
resultsCount++;
TimeSerieEntry lastEntry = timeSeries.Entries.Last();
Assert.That(lastEntry.Value, Is.EqualTo(1.327).Within(cTolerance), "The computed safety factory is not correct");
resultsCount++;
break;
}
case "LocationPL3AndPL4":
{
TimeSerieEntry firstEntry = timeSeries.Entries.First();
Assert.That(firstEntry.Value, Is.EqualTo(1.518).Within(cTolerance), "The computed safety factory is not correct");
resultsCount++;
TimeSerieEntry lastEntry = timeSeries.Entries.Last();
Assert.That(lastEntry.Value, Is.EqualTo(1.536).Within(cTolerance), "The computed safety factory is not correct");
resultsCount++;
break;
}
}
});
}
seriesCount++;
}
Assert.Multiple(() =>
{
Assert.That(seriesCount, Is.EqualTo(2), "Incorrect number of time series");
Assert.That(resultsCount, Is.EqualTo(4), "Incorrect number of results");
});
}
}