// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine 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.IO; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests; /// /// These tests were based on DamLiveIntegrationTest.Run_UsingTestFiles_HasExpectedResultsInOutputFile() /// [TestFixture] class OperationalIntegrationTests { private const double tolerance = 0.0005; [Test] [Category(Categories.WorkInProgress), Ignore("This test is not yet implemented, waits on stix implementation")] public void Run_UsingTestFiles_HasExpectedResultsInOutputFile() { const string calcDir = "TestOperationalIntegration"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); // Based on "DamLive\trunk\src\Deltares.DamLive.Tests\TestData\DamLive\Set2\\output.damx" const string inputFileName = @"TestFiles\OperationalSet2.xml"; const string outputFileName = @"TestFiles\OperationalSet2.output.xml"; string inputString = File.ReadAllText(inputFileName); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "MapForSoilgeometries2D", @"TestFiles\output.Geometries\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\output0.soilmaterials.mdb"); Output output = GeneralHelper.RunAfterInputValidation(inputString, true, outputFileName); Assert.That(output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntry[0].Value, Is.EqualTo(1.226).Within(tolerance)); Assert.That(output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntry[0].Value, Is.EqualTo(1.244).Within(tolerance)); Assert.That(output.Results.OperationalOutputTimeSeries[2].Entries.TimeSerieEntry[0].Value, Is.EqualTo(1.311).Within(tolerance)); } [Test, Category(Categories.MultiCore), Category(Categories.WorkInProgress), Ignore("This test is not yet implemented, waits on stix implementation")] // This test runs the same project as Run_UsingTestFiles_HasExpectedResultsInOutputFile // except that it runs it with both single core and multi core. // The output of both runs must be the same public void CompareResultFromMultiCoreRunWithSingleCoreRun() { var calcDir = "TestOperationalIntegrationSingleCore"; var outputFileName = @"OperationalSet2SingleCore.output.xml"; Output output = RunTestProjectCores(calcDir, outputFileName, 1); string outputSingleCore = DamXmlSerialization.SaveOutputAsXmlString(output); calcDir = "TestOperationalIntegrationMultiCore"; outputFileName = @"OperationalSet2MultiCore.output.xml"; output = RunTestProjectCores(calcDir, outputFileName, 4); string outputMultiCore = DamXmlSerialization.SaveOutputAsXmlString(output); Assert.That(outputMultiCore, Is.EqualTo(outputSingleCore)); } private Output RunTestProjectCores(string calcDir, string outputFileName, int coreCount) { if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); const string inputFileName = @"TestFiles\OperationalSet2.xml"; string inputString = File.ReadAllText(inputFileName); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "MapForSoilgeometries2D", @"TestFiles\output.Geometries\"); inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\output0.soilmaterials.mdb"); inputString = XmlAdapter.ChangeValueInXml(inputString, "MaxCalculationCores", coreCount.ToString()); return GeneralHelper.RunAfterInputValidation(inputString, false); } }