From 4418ea8a6fae64e18586960123843f008d034f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Sat, 28 Jun 2025 17:18:57 +0200 Subject: [PATCH] Compiling right --- .vscode/settings.json | 6 +++++- CMakeLists.txt | 3 ++- conanfile.py | 8 +++----- sample/CMakeLists.txt | 7 ++++--- tests/BinDisc_unittest.cpp | 4 ++-- tests/CMakeLists.txt | 28 ++++++---------------------- tests/Discretizer_unittest.cpp | 6 +++--- tests/FImdlp_unittest.cpp | 4 ++-- 8 files changed, 27 insertions(+), 39 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbb1d45..11a301e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -104,6 +104,10 @@ "stop_token": "cpp", "text_encoding": "cpp", "typeindex": "cpp", - "valarray": "cpp" + "valarray": "cpp", + "csignal": "cpp", + "regex": "cpp", + "future": "cpp", + "shared_mutex": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8de8385..4cab5f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ endif() if (ENABLE_TESTING) message("Debug mode") + enable_testing() set(CODE_COVERAGE ON) set(GCC_COVERAGE_LINK_FLAGS "${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") @@ -47,7 +48,7 @@ include_directories( ) add_library(fimdlp src/CPPFImdlp.cpp src/Metrics.cpp src/BinDisc.cpp src/Discretizer.cpp) -target_link_libraries(fimdlp torch::torch) +target_link_libraries(fimdlp PRIVATE torch::torch) # Installation # ------------ diff --git a/conanfile.py b/conanfile.py index c3351ae..df9a1a3 100644 --- a/conanfile.py +++ b/conanfile.py @@ -54,11 +54,9 @@ class FimdlpConan(ConanFile): self.requires("libtorch/2.7.0") def build_requirements(self): - # Test dependencies - only when testing is enabled - if self.options.enable_testing: - self.requires("catch2/3.8.1") - self.requires("arff/1.2.0") - self.requires("gtest/1.16.0") + self.requires("arff-files/1.2.0") # for tests and sample + if self.options.enable_testing: + self.test_requires("gtest/1.16.0") def layout(self): cmake_layout(self) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index f185d04..dd5c880 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -2,14 +2,15 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_BUILD_TYPE Debug) -find_package(Torch REQUIRED) +find_package(arff-files REQUIRED) include_directories( ${fimdlp_SOURCE_DIR}/src ${fimdlp_SOURCE_DIR}/tests/lib/Files ${CMAKE_BINARY_DIR}/configured_files/include ${libtorch_INCLUDE_DIRS_RELEASE} + ${arff-files_INCLUDE_DIRS} ) -add_executable(sample sample.cpp ) -target_link_libraries(sample PRIVATE fimdlp torch::torch) +add_executable(sample sample.cpp) +target_link_libraries(sample PRIVATE fimdlp torch::torch arff-files::arff-files) diff --git a/tests/BinDisc_unittest.cpp b/tests/BinDisc_unittest.cpp index e19c727..5ba1451 100644 --- a/tests/BinDisc_unittest.cpp +++ b/tests/BinDisc_unittest.cpp @@ -16,13 +16,13 @@ namespace mdlp { const float margin = 1e-4; static std::string set_data_path() { - std::string path = "../datasets/"; + std::string path = "datasets/"; std::ifstream file(path + "iris.arff"); if (file.is_open()) { file.close(); return path; } - return "../../tests/datasets/"; + return "tests/datasets/"; } const std::string data_path = set_data_path(); class TestBinDisc3U : public BinDisc, public testing::Test { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 220db38..1f873ea 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,27 +1,11 @@ -# Check if we should use Catch2 from Conan or GoogleTest via FetchContent -find_package(Catch2 3 QUIET) -if(Catch2_FOUND) - message(STATUS "Using Catch2 from Conan") - set(TEST_FRAMEWORK "Catch2") -else() - message(STATUS "Using GoogleTest via FetchContent") - set(TEST_FRAMEWORK "GoogleTest") - include(FetchContent) - include_directories(${GTEST_INCLUDE_DIRS}) - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip - ) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) -endif() +find_package(arff-files REQUIRED) +find_package(GTest REQUIRED) include_directories( ${libtorch_INCLUDE_DIRS_DEBUG} ${fimdlp_SOURCE_DIR}/src - ${fimdlp_SOURCE_DIR}/tests/lib/Files + ${arff-files_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}/configured_files/include ) @@ -32,18 +16,18 @@ target_link_options(Metrics_unittest PRIVATE --coverage) add_executable(FImdlp_unittest FImdlp_unittest.cpp ${fimdlp_SOURCE_DIR}/src/CPPFImdlp.cpp ${fimdlp_SOURCE_DIR}/src/Metrics.cpp ${fimdlp_SOURCE_DIR}/src/Discretizer.cpp) -target_link_libraries(FImdlp_unittest GTest::gtest_main "${TORCH_LIBRARIES}") +target_link_libraries(FImdlp_unittest GTest::gtest_main torch::torch) target_compile_options(FImdlp_unittest PRIVATE --coverage) target_link_options(FImdlp_unittest PRIVATE --coverage) add_executable(BinDisc_unittest BinDisc_unittest.cpp ${fimdlp_SOURCE_DIR}/src/BinDisc.cpp ${fimdlp_SOURCE_DIR}/src/Discretizer.cpp) -target_link_libraries(BinDisc_unittest GTest::gtest_main "${TORCH_LIBRARIES}") +target_link_libraries(BinDisc_unittest GTest::gtest_main torch::torch) target_compile_options(BinDisc_unittest PRIVATE --coverage) target_link_options(BinDisc_unittest PRIVATE --coverage) add_executable(Discretizer_unittest Discretizer_unittest.cpp ${fimdlp_SOURCE_DIR}/src/BinDisc.cpp ${fimdlp_SOURCE_DIR}/src/CPPFImdlp.cpp ${fimdlp_SOURCE_DIR}/src/Metrics.cpp ${fimdlp_SOURCE_DIR}/src/Discretizer.cpp ) -target_link_libraries(Discretizer_unittest GTest::gtest_main "${TORCH_LIBRARIES}") +target_link_libraries(Discretizer_unittest GTest::gtest_main torch::torch) target_compile_options(Discretizer_unittest PRIVATE --coverage) target_link_options(Discretizer_unittest PRIVATE --coverage) diff --git a/tests/Discretizer_unittest.cpp b/tests/Discretizer_unittest.cpp index 718d3a6..3bc8a5f 100644 --- a/tests/Discretizer_unittest.cpp +++ b/tests/Discretizer_unittest.cpp @@ -17,13 +17,13 @@ namespace mdlp { const float margin = 1e-4; static std::string set_data_path() { - std::string path = "../datasets/"; + std::string path = "datasets/"; std::ifstream file(path + "iris.arff"); if (file.is_open()) { file.close(); return path; } - return "../../tests/datasets/"; + return "tests/datasets/"; } const std::string data_path = set_data_path(); const labels_t iris_quantile = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 3, 3, 3, 1, 3, 1, 2, 0, 3, 1, 0, 2, 2, 2, 1, 3, 1, 2, 2, 1, 2, 2, 2, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2, 1, 2, 3, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 2, 1, 1, 2, 2, 3, 2, 3, 3, 0, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 2, 3, 1, 3, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 2, 2 }; @@ -33,7 +33,7 @@ namespace mdlp { auto version = disc->version(); delete disc; std::cout << "Version computed: " << version; - EXPECT_EQ("2.0.1", version); + EXPECT_EQ("2.1.0", version); } TEST(Discretizer, BinIrisUniform) { diff --git a/tests/FImdlp_unittest.cpp b/tests/FImdlp_unittest.cpp index 26ae424..ecc10bd 100644 --- a/tests/FImdlp_unittest.cpp +++ b/tests/FImdlp_unittest.cpp @@ -40,13 +40,13 @@ namespace mdlp { static string set_data_path() { - string path = "../datasets/"; + string path = "datasets/"; ifstream file(path + "iris.arff"); if (file.is_open()) { file.close(); return path; } - return "../../tests/datasets/"; + return "tests/datasets/"; } void checkSortedVector()