From d6af1ffe8e3a25854d3c3b5dba85f870dc4ea806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana=20G=C3=B3mez?= Date: Wed, 28 Feb 2024 11:51:37 +0100 Subject: [PATCH] Update gcovr config and fix some warnings --- .clang-tidy | 1 + CMakeLists.txt | 10 +++++----- gcovr.cfg | 2 +- src/bayesian_network/Network.cc | 2 +- src/feature_selection/FeatureSelect.cc | 1 - src/feature_selection/IWSS.cc | 2 +- tests/TestBayesModels.cc | 2 ++ 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 81f7209..ef88702 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ Checks: '-*, cppcoreguidelines-*, modernize-*, performance-*, + -modernize-use-nodiscard, -cppcoreguidelines-pro-type-vararg, -modernize-use-trailing-return-type, -bugprone-exception-escape' diff --git a/CMakeLists.txt b/CMakeLists.txt index 69156f7..0babab8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,11 +44,11 @@ endif (CMAKE_BUILD_TYPE STREQUAL "Debug") if (CODE_COVERAGE) - enable_testing() - include(CodeCoverage) - MESSAGE("Code coverage enabled") - set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") - SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") + enable_testing() + include(CodeCoverage) + MESSAGE("Code coverage enabled") + set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g") + SET(GCC_COVERAGE_LINK_FLAGS " ${GCC_COVERAGE_LINK_FLAGS} -lgcov --coverage") endif (CODE_COVERAGE) if (ENABLE_CLANG_TIDY) diff --git a/gcovr.cfg b/gcovr.cfg index 89e0877..01ad57e 100644 --- a/gcovr.cfg +++ b/gcovr.cfg @@ -1,4 +1,4 @@ filter = src/ exclude-directories = build_debug/lib/ print-summary = yes -sort-percentage = yes +sort = uncovered-percent diff --git a/src/bayesian_network/Network.cc b/src/bayesian_network/Network.cc index 32e6ecf..0357ba6 100644 --- a/src/bayesian_network/Network.cc +++ b/src/bayesian_network/Network.cc @@ -71,7 +71,7 @@ namespace bayesnet { for (Node* child : nodes[nodeId]->getChildren()) { if (visited.find(child->getName()) == visited.end() && isCyclic(child->getName(), visited, recStack)) return true; - else if (recStack.find(child->getName()) != recStack.end()) + if (recStack.find(child->getName()) != recStack.end()) return true; } } diff --git a/src/feature_selection/FeatureSelect.cc b/src/feature_selection/FeatureSelect.cc index b8300a5..fba1228 100644 --- a/src/feature_selection/FeatureSelect.cc +++ b/src/feature_selection/FeatureSelect.cc @@ -50,7 +50,6 @@ namespace bayesnet { } double FeatureSelect::computeMeritCFS() { - double result; double rcf = 0; for (auto feature : selectedFeatures) { rcf += suLabels[feature]; diff --git a/src/feature_selection/IWSS.cc b/src/feature_selection/IWSS.cc index 4fd11ea..e63bf6b 100644 --- a/src/feature_selection/IWSS.cc +++ b/src/feature_selection/IWSS.cc @@ -28,7 +28,7 @@ namespace bayesnet { selectedFeatures.push_back(feature); // Compute merit with selectedFeatures auto meritNew = computeMeritCFS(); - double delta = merit != 0.0 ? abs(merit - meritNew) / merit : 0.0; + double delta = merit != 0.0 ? std::abs(merit - meritNew) / merit : 0.0; if (meritNew > merit || delta < threshold) { if (meritNew > merit) { merit = meritNew; diff --git a/tests/TestBayesModels.cc b/tests/TestBayesModels.cc index db318ad..8488f05 100644 --- a/tests/TestBayesModels.cc +++ b/tests/TestBayesModels.cc @@ -224,6 +224,8 @@ TEST_CASE("BoostAODE voting-proba", "[BayesNet]") REQUIRE(score_voting == Catch::Approx(0.98).epsilon(raw.epsilon)); REQUIRE(pred_voting[83][2] == Catch::Approx(0.552091).epsilon(raw.epsilon)); REQUIRE(pred_proba[83][2] == Catch::Approx(0.546017).epsilon(raw.epsilon)); + clf.dump_cpt(); + REQUIRE(clf.topological_order() == std::vector()); } TEST_CASE("BoostAODE order asc, desc & random", "[BayesNet]") {