Compiling right

This commit is contained in:
2025-06-28 17:18:57 +02:00
parent 159e24b5cb
commit 4418ea8a6f
8 changed files with 27 additions and 39 deletions

View File

@@ -104,6 +104,10 @@
"stop_token": "cpp", "stop_token": "cpp",
"text_encoding": "cpp", "text_encoding": "cpp",
"typeindex": "cpp", "typeindex": "cpp",
"valarray": "cpp" "valarray": "cpp",
"csignal": "cpp",
"regex": "cpp",
"future": "cpp",
"shared_mutex": "cpp"
} }
} }

View File

@@ -28,6 +28,7 @@ endif()
if (ENABLE_TESTING) if (ENABLE_TESTING)
message("Debug mode") message("Debug mode")
enable_testing() enable_testing()
set(CODE_COVERAGE ON) set(CODE_COVERAGE ON)
set(GCC_COVERAGE_LINK_FLAGS "${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") 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) 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 # Installation
# ------------ # ------------

View File

@@ -54,11 +54,9 @@ class FimdlpConan(ConanFile):
self.requires("libtorch/2.7.0") self.requires("libtorch/2.7.0")
def build_requirements(self): def build_requirements(self):
# Test dependencies - only when testing is enabled self.requires("arff-files/1.2.0") # for tests and sample
if self.options.enable_testing: if self.options.enable_testing:
self.requires("catch2/3.8.1") self.test_requires("gtest/1.16.0")
self.requires("arff/1.2.0")
self.requires("gtest/1.16.0")
def layout(self): def layout(self):
cmake_layout(self) cmake_layout(self)

View File

@@ -2,14 +2,15 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
find_package(Torch REQUIRED) find_package(arff-files REQUIRED)
include_directories( include_directories(
${fimdlp_SOURCE_DIR}/src ${fimdlp_SOURCE_DIR}/src
${fimdlp_SOURCE_DIR}/tests/lib/Files ${fimdlp_SOURCE_DIR}/tests/lib/Files
${CMAKE_BINARY_DIR}/configured_files/include ${CMAKE_BINARY_DIR}/configured_files/include
${libtorch_INCLUDE_DIRS_RELEASE} ${libtorch_INCLUDE_DIRS_RELEASE}
${arff-files_INCLUDE_DIRS}
) )
add_executable(sample sample.cpp ) add_executable(sample sample.cpp)
target_link_libraries(sample PRIVATE fimdlp torch::torch) target_link_libraries(sample PRIVATE fimdlp torch::torch arff-files::arff-files)

View File

@@ -16,13 +16,13 @@ namespace mdlp {
const float margin = 1e-4; const float margin = 1e-4;
static std::string set_data_path() static std::string set_data_path()
{ {
std::string path = "../datasets/"; std::string path = "datasets/";
std::ifstream file(path + "iris.arff"); std::ifstream file(path + "iris.arff");
if (file.is_open()) { if (file.is_open()) {
file.close(); file.close();
return path; return path;
} }
return "../../tests/datasets/"; return "tests/datasets/";
} }
const std::string data_path = set_data_path(); const std::string data_path = set_data_path();
class TestBinDisc3U : public BinDisc, public testing::Test { class TestBinDisc3U : public BinDisc, public testing::Test {

View File

@@ -1,27 +1,11 @@
# Check if we should use Catch2 from Conan or GoogleTest via FetchContent
find_package(Catch2 3 QUIET)
if(Catch2_FOUND) find_package(arff-files REQUIRED)
message(STATUS "Using Catch2 from Conan") find_package(GTest REQUIRED)
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()
include_directories( include_directories(
${libtorch_INCLUDE_DIRS_DEBUG} ${libtorch_INCLUDE_DIRS_DEBUG}
${fimdlp_SOURCE_DIR}/src ${fimdlp_SOURCE_DIR}/src
${fimdlp_SOURCE_DIR}/tests/lib/Files ${arff-files_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/configured_files/include ${CMAKE_BINARY_DIR}/configured_files/include
) )
@@ -32,18 +16,18 @@ target_link_options(Metrics_unittest PRIVATE --coverage)
add_executable(FImdlp_unittest FImdlp_unittest.cpp 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) ${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_compile_options(FImdlp_unittest PRIVATE --coverage)
target_link_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) 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_compile_options(BinDisc_unittest PRIVATE --coverage)
target_link_options(BinDisc_unittest PRIVATE --coverage) target_link_options(BinDisc_unittest PRIVATE --coverage)
add_executable(Discretizer_unittest Discretizer_unittest.cpp 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 ) ${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_compile_options(Discretizer_unittest PRIVATE --coverage)
target_link_options(Discretizer_unittest PRIVATE --coverage) target_link_options(Discretizer_unittest PRIVATE --coverage)

View File

@@ -17,13 +17,13 @@ namespace mdlp {
const float margin = 1e-4; const float margin = 1e-4;
static std::string set_data_path() static std::string set_data_path()
{ {
std::string path = "../datasets/"; std::string path = "datasets/";
std::ifstream file(path + "iris.arff"); std::ifstream file(path + "iris.arff");
if (file.is_open()) { if (file.is_open()) {
file.close(); file.close();
return path; return path;
} }
return "../../tests/datasets/"; return "tests/datasets/";
} }
const std::string data_path = set_data_path(); 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 }; 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(); auto version = disc->version();
delete disc; delete disc;
std::cout << "Version computed: " << version; std::cout << "Version computed: " << version;
EXPECT_EQ("2.0.1", version); EXPECT_EQ("2.1.0", version);
} }
TEST(Discretizer, BinIrisUniform) TEST(Discretizer, BinIrisUniform)
{ {

View File

@@ -40,13 +40,13 @@ namespace mdlp {
static string set_data_path() static string set_data_path()
{ {
string path = "../datasets/"; string path = "datasets/";
ifstream file(path + "iris.arff"); ifstream file(path + "iris.arff");
if (file.is_open()) { if (file.is_open()) {
file.close(); file.close();
return path; return path;
} }
return "../../tests/datasets/"; return "tests/datasets/";
} }
void checkSortedVector() void checkSortedVector()