From 969c83060fac85796db3ad541dc4403a2e8400df Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Thu, 1 Dec 2022 16:08:47 +0100 Subject: [PATCH] fix headers and data in tests --- tests/CMakeLists.txt | 12 ++++++++++++ tests/test_determinist.cpp | 13 +++++++++---- tests/test_probabilist.cpp | 21 +++++++++++++-------- tests/test_uncertainty.cpp | 1 + 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8eac385..48c1462 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,18 @@ add_executable( test_uncertainty.cpp ) +target_include_directories( + evalhyd_tests + PRIVATE + ${CMAKE_SOURCE_DIR}/src +) + +target_compile_definitions( + evalhyd_tests + PRIVATE + EVALHYD_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" +) + find_package(GTest REQUIRED) target_link_libraries( diff --git a/tests/test_determinist.cpp b/tests/test_determinist.cpp index 0000cbb..ea12693 100644 --- a/tests/test_determinist.cpp +++ b/tests/test_determinist.cpp @@ -3,6 +3,7 @@ #include <tuple> #include <array> #include <gtest/gtest.h> + #include <xtensor/xtensor.hpp> #include <xtensor/xview.hpp> #include <xtensor/xmanipulation.hpp> @@ -10,17 +11,21 @@ #include "evalhyd/evald.hpp" +#ifndef EVALHYD_DATA_DIR +#error "need to define data directory" +#endif + using namespace xt::placeholders; // required for `_` to work std::tuple<xt::xtensor<double, 2>, xt::xtensor<double, 2>> load_data_d() { // read in data std::ifstream ifs; - ifs.open("./data/q_obs.csv"); + ifs.open(EVALHYD_DATA_DIR "/q_obs.csv"); xt::xtensor<double, 2> observed = xt::load_csv<int>(ifs); ifs.close(); - ifs.open("./data/q_prd.csv"); + ifs.open(EVALHYD_DATA_DIR "/q_prd.csv"); xt::xtensor<double, 2> predicted = xt::view( xt::load_csv<double>(ifs), xt::range(0, 5), xt::all() ); @@ -347,7 +352,7 @@ TEST(DeterministTests, TestBootstrap) {{"n_samples", 10}, {"len_sample", 3}, {"summary", 0}}; std::vector<xt::xarray<double>> metrics_bts = - eh::evald( + evalhyd::evald( xt::view(observed, xt::newaxis(), xt::all()), predicted, metrics, @@ -372,7 +377,7 @@ TEST(DeterministTests, TestBootstrap) xt::concatenate(xt::xtuple(predicted, predicted, predicted), 1); std::vector<xt::xarray<double>> metrics_rep = - eh::evald( + evalhyd::evald( xt::view(observed_x3, xt::newaxis(), xt::all()), predicted_x3, metrics diff --git a/tests/test_probabilist.cpp b/tests/test_probabilist.cpp index 4583ade..655a276 100644 --- a/tests/test_probabilist.cpp +++ b/tests/test_probabilist.cpp @@ -4,23 +4,28 @@ #include <array> #include <gtest/gtest.h> #include <xtensor/xtensor.hpp> +#include <xtensor/xview.hpp> +#include <xtensor/xsort.hpp> #include <xtensor/xmanipulation.hpp> #include <xtensor/xcsv.hpp> #include "evalhyd/evalp.hpp" -using namespace xt::placeholders; // required for `_` to work +#ifndef EVALHYD_DATA_DIR +#error "need to define data directory" +#endif +using namespace xt::placeholders; // required for `_` to work std::tuple<xt::xtensor<double, 1>, xt::xtensor<double, 2>> load_data_p() { // read in data std::ifstream ifs; - ifs.open("./data/q_obs.csv"); + ifs.open(EVALHYD_DATA_DIR "/q_obs.csv"); xt::xtensor<double, 1> observed = xt::squeeze(xt::load_csv<int>(ifs)); ifs.close(); - ifs.open("./data/q_prd.csv"); + ifs.open(EVALHYD_DATA_DIR "/q_prd.csv"); xt::xtensor<double, 2> predicted = xt::load_csv<double>(ifs); ifs.close(); @@ -318,7 +323,7 @@ TEST(ProbabilistTests, TestMissingData) {{ 4.7, 4.3, NAN, 2.7, 4.1 }}; std::vector<xt::xarray<double>> metrics_nan = - eh::evalp( + evalhyd::evalp( observed_nan, forecast_nan, metrics, @@ -337,7 +342,7 @@ TEST(ProbabilistTests, TestMissingData) {{ 4.7, 4.3, 2.7 }}; std::vector<xt::xarray<double>> metrics_pp1 = - eh::evalp( + evalhyd::evalp( observed_pp1, forecast_pp1, metrics, @@ -355,7 +360,7 @@ TEST(ProbabilistTests, TestMissingData) {{ 4.3, 2.7, 4.1 }}; std::vector<xt::xarray<double>> metrics_pp2 = - eh::evalp( + evalhyd::evalp( observed_pp2, forecast_pp2, metrics, @@ -410,7 +415,7 @@ TEST(ProbabilistTests, TestBootstrap) {{"n_samples", 10}, {"len_sample", 3}, {"summary", 0}}; std::vector<xt::xarray<double>> metrics_bts = - eh::evalp( + evalhyd::evalp( xt::view(observed, xt::newaxis(), xt::all()), xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()), metrics, @@ -433,7 +438,7 @@ TEST(ProbabilistTests, TestBootstrap) xt::concatenate(xt::xtuple(predicted, predicted, predicted), 1); std::vector<xt::xarray<double>> metrics_rep = - eh::evalp( + evalhyd::evalp( xt::view(observed_x3, xt::newaxis(), xt::all()), xt::view(predicted_x3, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()), metrics, diff --git a/tests/test_uncertainty.cpp b/tests/test_uncertainty.cpp index 091e74a..1bfb312 100644 --- a/tests/test_uncertainty.cpp +++ b/tests/test_uncertainty.cpp @@ -1,5 +1,6 @@ #include <unordered_map> #include <gtest/gtest.h> + #include <xtensor/xtensor.hpp> #include <xtensor/xrandom.hpp> #include <xtensor/xio.hpp> -- GitLab