From 6cb32fa0063de0e826e422c370592eef82a680aa Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Sun, 2 Aug 2020 20:57:54 +0200 Subject: [PATCH] Core/Std/Run split off checkSimulation --- Tests/Functional/Core/Std/Run.cpp | 88 ++++++++++++++++++------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/Tests/Functional/Core/Std/Run.cpp b/Tests/Functional/Core/Std/Run.cpp index bcd0bc9d3c5..97c019a9a96 100644 --- a/Tests/Functional/Core/Std/Run.cpp +++ b/Tests/Functional/Core/Std/Run.cpp @@ -25,7 +25,54 @@ #include <cassert> #include <iostream> -bool runSubtest() {} +namespace +{ + +bool checkSimulation(const std::string& name, const Simulation& direct_simulation, + const double limit) +{ + const auto result_data = direct_simulation.result().data(); + + std::unique_ptr<OutputData<double>> reference; + + // Load reference if available + assert(name != ""); + try { + reference.reset(IntensityDataIOFactory::readOutputData( + FileSystemUtils::jointPath(BATesting::StdReferenceDir(), name + ".int.gz"))); + } catch (const std::exception&) { + std::cout + << "No reference found, but we proceed with the simulation to create a new one\n"; + } + + // Compare with reference if available. + bool success = false; + if (reference) { + std::cout << "- check diff" << std::endl; + success = + IntensityDataFunctions::checkRelativeDifference(*reference, *result_data, limit); + } + + // Save simulation if different from reference. + if (!success) { + std::cout << "- failure ..." << std::endl; + FileSystemUtils::createDirectories(BATesting::StdOutputDir()); + std::string out_fname = + FileSystemUtils::jointPath(BATesting::StdOutputDir(), name + ".int.gz"); + IntensityDataIOFactory::writeOutputData(*result_data, out_fname); + std::cout << "New simulation result stored in " << out_fname << "\n" + << "To visualize an intensity map, use " << BABuild::buildBinDir() + << "/plot_intensity_data.py;" + << " to plot a difference image, use " << BABuild::buildBinDir() + << "/plot_intensity_data_diff.py\n" + << "If the new result is correct, then move it to " + << BATesting::CoreReferenceDir() << "/\n"; + } + + return success; +} + +} // namespace int run(const std::string& test_name, const std::string& sim_name, const std::string& sample_builder_name, const double limit) @@ -53,44 +100,9 @@ int run(const std::string& test_name, const std::string& sim_name, full_name += "_" + builder->getName(); simulation->runSimulation(); - const auto result_data = simulation->result().data(); - - std::unique_ptr<OutputData<double>> reference; - - // Load reference if available - assert(full_name != ""); - try { - reference.reset(IntensityDataIOFactory::readOutputData( - FileSystemUtils::jointPath(BATesting::StdReferenceDir(), full_name + ".int.gz"))); - } catch (const std::exception&) { - std::cout - << "No reference found, but we proceed with the simulation to create a new one\n"; - } - - // Compare with reference if available. - bool success = false; - if (reference) { - std::cout << "- check diff" << std::endl; - success = - IntensityDataFunctions::checkRelativeDifference(*reference, *result_data, limit); - } - - // Save simulation if different from reference. - if (!success) { - std::cout << "- failure ..." << std::endl; - FileSystemUtils::createDirectories(BATesting::StdOutputDir()); - std::string out_fname = - FileSystemUtils::jointPath(BATesting::StdOutputDir(), test_name + ".int.gz"); - IntensityDataIOFactory::writeOutputData(*result_data, out_fname); - std::cout << "New simulation result stored in " << out_fname << "\n" - << "To visualize an intensity map, use " << BABuild::buildBinDir() - << "/plot_intensity_data.py;" - << " to plot a difference image, use " << BABuild::buildBinDir() - << "/plot_intensity_data_diff.py\n" - << "If the new result is correct, then move it to " - << BATesting::CoreReferenceDir() << "/\n"; + + if (!checkSimulation(full_name, *simulation, limit)) ++number_of_failed_tests; - } } return !number_of_failed_tests; -- GitLab