// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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.Dam.Data; using Deltares.Dam.Data.DamEngineIo; using Deltares.Dam.TestHelper; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using NUnit.Framework; namespace Deltares.Dam.IntegrationTests { /// /// Class for testing Calamity /// [TestFixture] public class CalamityTests { private const double tolerance4Decimals = 0.000051; /// /// Input of this test is based on Pulau Tekong Inside input data, but using Calamity instead of DAM Live operational. /// [Test] public void GivenCalamityInputFile_WhenRun_ThenOutputIsCorrect() { string projectFilename = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\Calamity\PulauTekongCalamity.damx"); using DamProjectData damProjectData = ProjectLoader.LoadProjectData(projectFilename); Input input = FillXmlInputFromDamUi.CreateInput(damProjectData); string inputXml = DamXmlSerialization.SaveInputAsXmlString(input); var damEngineInterface = new EngineInterface(inputXml); string validationMessages = damEngineInterface.Validate(); Assert.That(validationMessages, Is.Null); string outputXml = damEngineInterface.Run(); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputXml); FillDamUiFromXmlOutput.AddOutputToDamProjectData(damProjectData, output); Assert.That(output.Results.OperationalOutputTimeSeries, Has.Length.EqualTo(5)); Assert.Multiple(() => { Assert.That(output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntryOutput, Has.Length.EqualTo(3)); Assert.That(output.Results.OperationalOutputTimeSeries[0].LocationId, Is.EqualTo("CD CS1 X1")); Assert.That(output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntryOutput[0].Value, Is.EqualTo(1.4078).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntryOutput[1].Value, Is.EqualTo(1.4084).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[0].Entries.TimeSerieEntryOutput[2].Value, Is.EqualTo(1.4053).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntryOutput, Has.Length.EqualTo(3)); Assert.That(output.Results.OperationalOutputTimeSeries[1].LocationId, Is.EqualTo("CD CS2 X3")); Assert.That(output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntryOutput[0].Value, Is.EqualTo(0.9985).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntryOutput[1].Value, Is.EqualTo(0.9950).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[1].Entries.TimeSerieEntryOutput[2].Value, Is.EqualTo(0.9891).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[2].Entries.TimeSerieEntryOutput, Has.Length.EqualTo(3)); Assert.That(output.Results.OperationalOutputTimeSeries[2].LocationId, Is.EqualTo("SD CS1 3-3")); Assert.That(output.Results.OperationalOutputTimeSeries[3].Entries.TimeSerieEntryOutput, Has.Length.EqualTo(3)); Assert.That(output.Results.OperationalOutputTimeSeries[3].LocationId, Is.EqualTo("SD CS2 8-8")); Assert.That(output.Results.OperationalOutputTimeSeries[4].Entries.TimeSerieEntryOutput, Has.Length.EqualTo(3)); Assert.That(output.Results.OperationalOutputTimeSeries[4].LocationId, Is.EqualTo("SD CS3 10-10")); for (int i = 2; i < 5; i++) { Assert.That(output.Results.OperationalOutputTimeSeries[i].Entries.TimeSerieEntryOutput[0].Value, Is.EqualTo(double.NaN).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[i].Entries.TimeSerieEntryOutput[1].Value, Is.EqualTo(double.NaN).Within(tolerance4Decimals)); Assert.That(output.Results.OperationalOutputTimeSeries[i].Entries.TimeSerieEntryOutput[2].Value, Is.EqualTo(double.NaN).Within(tolerance4Decimals)); } }); } } }