From b63a6b2cfc2bc19f0f64a780e1496d53242b91e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Sat, 31 Jul 2021 18:13:24 +0200 Subject: [PATCH] Add tests for NaNHelper --- tests/CMakeLists.txt | 1 + tests/test_NaNHelper.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/test_NaNHelper.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8cea83f72..62a70aad3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -85,6 +85,7 @@ add_executable (unit_tests test_ListAffectationProcessor.cpp test_MathModule.cpp test_NameProcessor.cpp + test_NaNHelper.cpp test_OStreamProcessor.cpp test_ParseError.cpp test_PETScUtils.cpp diff --git a/tests/test_NaNHelper.cpp b/tests/test_NaNHelper.cpp new file mode 100644 index 000000000..1adbf1650 --- /dev/null +++ b/tests/test_NaNHelper.cpp @@ -0,0 +1,38 @@ +#include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_all.hpp> + +#include <utils/NaNHelper.hpp> + +#include <sstream> + +// clazy:excludeall=non-pod-global-static + +TEST_CASE("NaNHelper", "[utils]") +{ + SECTION("signaling NaN") + { + std::ostringstream ost_nan_helper; + ost_nan_helper << NaNHelper(std::numeric_limits<double>::signaling_NaN()); + + REQUIRE(ost_nan_helper.str() == "nan"); + } + + SECTION("valid double") + { + std::ostringstream ost_nan_helper; + ost_nan_helper << NaNHelper(double{3.2}); + + std::ostringstream ost; + ost << double{3.2}; + REQUIRE(ost_nan_helper.str() == ost.str()); + } + + SECTION("non arithmetic type") + { + std::string s = "foo"; + std::ostringstream ost_nan_helper; + ost_nan_helper << NaNHelper(s); + + REQUIRE(ost_nan_helper.str() == s); + } +} -- GitLab