diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8cea83f7294e107b28db9f223cd989c33a5a6c2d..62a70aad353dbb9d9deb7fcc7688865ab1987024 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 0000000000000000000000000000000000000000..1adbf1650f73e5592748eebad8d3534211664be7 --- /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); + } +}