Index: DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs =================================================================== diff -u -r6139 -r6404 --- DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs (.../GeneralHelper.cs) (revision 6139) +++ DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/GeneralHelper.cs (.../GeneralHelper.cs) (revision 6404) @@ -1,4 +1,4 @@ -// Copyright (C) Stichting Deltares 2024. All rights reserved. +// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the Dam Engine. // @@ -116,16 +116,86 @@ return output; } + public static void CompareDesignOutput(Output expected, Output actual) + { + StripCalculationSubDir(expected); + StripCalculationSubDir(actual); + CompareOutput(expected, actual); + } + + public static void CompareOutput(Output expected, Output actual) + { + var compare = new CompareLogic + { + Config = + { + MaxDifferences = 100 + } + }; + ComparisonResult result = compare.Compare(expected, actual); + Assert.That(result.Differences, Is.Empty, "Differences found read/write Output object"); + } + + public static void RemoveTestWorkingDirectory(string testWorkingFolder) + { + if (Directory.Exists(testWorkingFolder)) + { + const bool recursive = true; + Directory.Delete(testWorkingFolder, recursive); + } + } + + public static Output RunMultiCoreWithXmlInputFile(string mapTestFiles, DamProjectType damProjectType, + int maxCores, string calcDir, string inputFilename, string outputFilename, + bool justOneScenario = false, bool expectedNoErrors = true) + { + int processorCount = Environment.ProcessorCount; + if (maxCores > processorCount) + { + Assert.Ignore($"The number of cores requested ({maxCores}) is higher than the number of available cores ({processorCount})."); + } + + if (Directory.Exists(calcDir)) + { + Directory.Delete(calcDir, true); // delete previous results + } + + Directory.CreateDirectory(calcDir); + + string fullInputFilename = Path.Combine(mapTestFiles, inputFilename); + string inputString = File.ReadAllText(fullInputFilename); + 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, "MaxCalculationCores", maxCores.ToString()); + var engineInterface = new EngineInterface(inputString); + if (justOneScenario) + { + engineInterface.DamProjectData.Dike.ClearLocationScenariosExceptFirst(); + } + + Assert.That(engineInterface.DamProjectData, Is.Not.Null); + Assert.That(engineInterface.DamProjectData.DamProjectType, Is.EqualTo(damProjectType)); + + Output output = RunAfterInputValidation(engineInterface, true, outputFilename); + if (expectedNoErrors) + { + int errorCount = DetermineNumberOfCalculationErrors(engineInterface.DamProjectData.CalculationMessages); + Assert.That(errorCount, Is.EqualTo(0), "There should be no errors during the calculation."); + } + + return output; + } + private static void CheckConsistencyOfAdaptGeometryResults(EngineInterface engineInterface, OutputResults outputResults) { - if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design && + if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design && engineInterface.DamProjectData.DamProjectCalculationSpecification.AnalysisTypeForSerializationPurposeOnly == AnalysisType.AdaptGeometry) { var isIteratedFilePresent = false; foreach (DesignResult calculationResult in outputResults.CalculationResults) { - bool isDesignSuccessful = calculationResult.CalculationResult == ConversionHelper.ConvertToOutputCalculationResult(CalculationResult.Succeeded) && + bool isDesignSuccessful = calculationResult.CalculationResult == ConversionHelper.ConvertToOutputCalculationResult(CalculationResult.Succeeded) && IsAdaptGeometrySuccessful(outputResults.CalculationMessages, calculationResult); double fosRequired = FetchRequiredFactor(engineInterface, calculationResult.ScenarioName, calculationResult.LocationName); double fosCalculated = FetchCalculatedFactor(engineInterface, calculationResult); @@ -218,79 +288,11 @@ return 0; } - public static void CompareDesignOutput(Output expected, Output actual) - { - StripCalculationSubDir(expected); - StripCalculationSubDir(actual); - CompareOutput(expected, actual); - } - private static void StripCalculationSubDir(Output expected) { foreach (DesignResult result in expected.Results.CalculationResults) { result.CalculationSubDir = ""; } } - - public static void CompareOutput(Output expected, Output actual) - { - var compare = new CompareLogic - { - Config = - { - MaxDifferences = 100 - } - }; - ComparisonResult result = compare.Compare(expected, actual); - Assert.That(result.Differences, Is.Empty, "Differences found read/write Output object"); - } - - public static void RemoveTestWorkingDirectory(string testWorkingFolder) - { - if (Directory.Exists(testWorkingFolder)) - { - const bool recursive = true; - Directory.Delete(testWorkingFolder, recursive); - } - } - - public static Output RunMultiCoreWithXmlInputFile(string mapTestFiles, DamProjectType damProjectType, - int maxCores, string calcDir, string inputFilename, string outputFilename, - bool justOneScenario = false, bool expectedNoErrors = true) - { - var processorCount = Environment.ProcessorCount; - if (maxCores > processorCount) - { - Assert.Ignore($"The number of cores requested ({maxCores}) is higher than the number of available cores ({processorCount})."); - } - if (Directory.Exists(calcDir)) - { - Directory.Delete(calcDir, true); // delete previous results - } - Directory.CreateDirectory(calcDir); - - string fullInputFilename = Path.Combine(mapTestFiles, inputFilename); - string inputString = File.ReadAllText(fullInputFilename); - 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, "MaxCalculationCores", maxCores.ToString()); - var engineInterface = new EngineInterface(inputString); - if (justOneScenario) - { - engineInterface.DamProjectData.Dike.ClearLocationScenariosExceptFirst(); - } - Assert.That(engineInterface.DamProjectData, Is.Not.Null); - Assert.That(engineInterface.DamProjectData.DamProjectType, Is.EqualTo(damProjectType)); - - Output output = GeneralHelper.RunAfterInputValidation(engineInterface, true, outputFilename); - if (expectedNoErrors) - { - int errorCount = GeneralHelper.DetermineNumberOfCalculationErrors(engineInterface.DamProjectData.CalculationMessages); - Assert.That(errorCount, Is.EqualTo(0), "There should be no errors during the calculation."); - } - return output; - } - - } \ No newline at end of file