From 2945400ce50931967f5f9d5b39b9bce388a8cf00 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Mon, 16 Sep 2024 09:42:44 +0200 Subject: [PATCH] Add few missing tests for ReproducibleSumManager --- src/utils/ReproducibleSumMPI.hpp | 5 +++++ tests/CMakeLists.txt | 1 + tests/test_ReproducibleSumManager.cpp | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tests/test_ReproducibleSumManager.cpp diff --git a/src/utils/ReproducibleSumMPI.hpp b/src/utils/ReproducibleSumMPI.hpp index d4b80eb5d..c3b2e8ef3 100644 --- a/src/utils/ReproducibleSumMPI.hpp +++ b/src/utils/ReproducibleSumMPI.hpp @@ -7,6 +7,9 @@ #ifdef PUGS_HAS_MPI +// LCOV_EXCL_START +// This piece of code is not catchable by coverage... + template <typename RSumType> struct ReproducibleMPIReducer { @@ -22,6 +25,8 @@ struct ReproducibleMPIReducer } }; +// LCOV_EXCL_STOP + template <typename ArrayT, typename BoolArrayT> auto allReduceReproducibleSum(const ReproducibleScalarSum<ArrayT, BoolArrayT>& s) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9d2b66f1e..14727109e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -130,6 +130,7 @@ add_executable (unit_tests test_QuadratureType.cpp test_RefId.cpp test_RefItemList.cpp + test_ReproducibleSumManager.cpp test_RevisionInfo.cpp test_SmallArray.cpp test_SmallMatrix.cpp diff --git a/tests/test_ReproducibleSumManager.cpp b/tests/test_ReproducibleSumManager.cpp new file mode 100644 index 000000000..a406a7cd0 --- /dev/null +++ b/tests/test_ReproducibleSumManager.cpp @@ -0,0 +1,22 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <utils/ReproducibleSumManager.hpp> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("ReproducibleSumManager", "[utils]") +{ + SECTION("control settings") + { + const bool init_value = ReproducibleSumManager::reproducibleSums(); + + ReproducibleSumManager::setReproducibleSums(not init_value); + + REQUIRE(init_value == not ReproducibleSumManager::reproducibleSums()); + + ReproducibleSumManager::setReproducibleSums(init_value); + + REQUIRE(init_value == ReproducibleSumManager::reproducibleSums()); + } +} -- GitLab