From 63b4e49f99fd348b42e1b528d1268ae6b4b1d532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Thu, 3 Aug 2023 11:12:02 +0200 Subject: [PATCH] Fix handling of CSV file --- test/CMakeLists.txt | 7 +++++++ test/testSimulation.cpp | 10 +++++----- test/testSimulation.hpp.in | 7 +++++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 test/testSimulation.hpp.in diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 709197b..9431fc2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,6 +14,13 @@ endif() add_executable(testTug setup.cpp testBoundaryCondition.cpp testDiffusion.cpp testSimulation.cpp) target_link_libraries(testTug doctest tug) +# get relative path of the CSV file +get_filename_component(testSimulationCSV "FTCS_11_11_7000.csv" REALPATH CACHE) +# set relative path in header file +configure_file(testSimulation.hpp.in testSimulation.hpp) +# include test directory with generated header file from above +target_include_directories(testTug PUBLIC "${CMAKE_CURRENT_BINARY_DIR}") + add_custom_target( check COMMAND $ diff --git a/test/testSimulation.cpp b/test/testSimulation.cpp index 72beacc..8336cb7 100644 --- a/test/testSimulation.cpp +++ b/test/testSimulation.cpp @@ -1,11 +1,11 @@ #include #include #include -#include #include "TestUtils.cpp" #include -namespace fs = std::filesystem; +// include the configured header file +#include static Grid setupSimulation() { int row = 11; @@ -58,10 +58,10 @@ static Grid setupSimulation() { } TEST_CASE("equality to reference matrix") { - fs::path p = fs::current_path(); // .parent_path().parent_path(); - string test_path = p.generic_string() + "/FTCS_11_11_7000.csv"; + // set string from the header file + string test_path = testSimulationCSVDir; MatrixXd reference = CSV2Eigen(test_path); cout << test_path << endl; Grid grid = setupSimulation(); CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true); -} \ No newline at end of file +} diff --git a/test/testSimulation.hpp.in b/test/testSimulation.hpp.in new file mode 100644 index 0000000..2e1e19a --- /dev/null +++ b/test/testSimulation.hpp.in @@ -0,0 +1,7 @@ +#ifndef TESTSIMULATION_H_ +#define TESTSIMULATION_H_ + +// CSV file needed for validation +const char *testSimulationCSVDir = "@testSimulationCSV@"; + +#endif // TESTSIMULATION_H_