// Copyright (C) Stichting Deltares 2023. 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.Globalization; using System.IO; using System.Threading; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlOutput; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests { [TestFixture] public class DebuggingTest { private const string mapTestFiles = @"TestFiles\"; /// Debugs the with XML input file. /// Usage: /// 1) Generate the input XML file in the DAM UI /// 2) Copy the file to src\Deltares.DamEngine.IntegrationTests\TestFiles\InputForDebugging.xml /// 3) Run the test in Debugging mode /// [Test, Ignore("This test is only used for debugging XML files generated by Dam UI")] [TestCase(1)] [TestCase(4)] [TestCase(16)] public void DebugWithXmlInputFile(int maxCores) { const string inputFilename = "InputFileMultiCoreTestForScenario.xml"; // or put your own name here; string fullInputFilename = Path.Combine(mapTestFiles, inputFilename); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string inputString = File.ReadAllText(fullInputFilename); var engineInterface = new EngineInterface(inputString); engineInterface.DamProjectData.MaxCalculationCores = maxCores; engineInterface.DamProjectData.CalculationMap = engineInterface.DamProjectData.CalculationMap + "_Cores_" + maxCores; Assert.IsNotNull(engineInterface.DamProjectData); string result = engineInterface.Validate(); Assert.IsTrue(result == null, "Validation must succeed but does not, see output xml in debugger"); string outputString = engineInterface.Run(); File.WriteAllText("Results_Cores_" + maxCores + ".xml", outputString); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString); if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design) { Assert.AreNotEqual(null, output.Results.CalculationResults); } else { Assert.AreNotEqual(null, output.Results.OperationalOutputTimeSeries); } } [Test, Ignore("This test is only used for debugging XML files generated by Dam UI")] [TestCase(1)] [TestCase(4)] [TestCase(16)] [SetUICulture("nl-NL")] public void TestInputXmlForV1933(int maxCores) { // Based on InputFile.xml as produced by DAM UI in debug mode Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; const string fileName = @"TestFiles\InputFileV1933.xml"; Assert.IsTrue(File.Exists(fileName), "The file is not found."); string inputString = File.ReadAllText(fileName); EngineInterface engineInterface = new EngineInterface(inputString); engineInterface.DamProjectData.MaxCalculationCores = maxCores; engineInterface.DamProjectData.CalculationMap = engineInterface.DamProjectData.CalculationMap + "_K_" + maxCores; Assert.IsNotNull(engineInterface.DamProjectData); string outputString = engineInterface.Run(); File.WriteAllText("Results_K_" + maxCores + ".xml", outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.AreEqual(0, output.Results.CalculationMessages.Length, "No messages expected"); Assert.AreEqual(54, output.Results.CalculationResults.Length, "One result expected"); Assert.AreEqual(10.0233, output.Results.CalculationResults[0].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(0, output.Results.CalculationResults[1].CalculationResult); Assert.AreEqual(10.0233, output.Results.CalculationResults[2].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(9.7419, output.Results.CalculationResults[3].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(0, output.Results.CalculationResults[4].CalculationResult); Assert.AreEqual(9.7419, output.Results.CalculationResults[5].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(1.2034, output.Results.CalculationResults[6].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(0, output.Results.CalculationResults[7].CalculationResult); Assert.AreEqual(1.2034, output.Results.CalculationResults[8].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(5.8214, output.Results.CalculationResults[21].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(0, output.Results.CalculationResults[22].CalculationResult); Assert.AreEqual(5.8214, output.Results.CalculationResults[23].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(1.6480, output.Results.CalculationResults[24].StabilityDesignResults.SafetyFactor, 0.0001); Assert.AreEqual(0, output.Results.CalculationResults[25].CalculationResult); Assert.AreEqual(1.6480, output.Results.CalculationResults[26].StabilityDesignResults.SafetyFactor, 0.0001); } [Test, Ignore("This test is only used for debugging XML files generated by Dam UI")] public void DebugProbleemOnno() { const string inputFilename = "InputFileProbleemOnno.xml"; // or put your own name here; string fullInputFilename = Path.Combine(mapTestFiles, inputFilename); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string inputString = File.ReadAllText(fullInputFilename); var engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); string result = engineInterface.Validate(); Assert.IsTrue(result == null, "Validation must succeed but does not, see output xml in debugger"); string outputString = engineInterface.Run(); File.WriteAllText("Output.xml", outputString); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString); if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design) { Assert.AreNotEqual(null, output.Results.CalculationResults); } else { Assert.AreNotEqual(null, output.Results.OperationalOutputTimeSeries); } } } }