2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Coverage: Fix up nonfinite_num_facets.hpp

Add more tests, and enable one test that was not even being built.
This commit is contained in:
jzmaddock
2025-05-07 16:36:19 +01:00
parent 295c5a37f5
commit 404fccdd16
4 changed files with 80 additions and 5 deletions

View File

@@ -493,10 +493,10 @@ namespace boost {
return;
}
}
break;
break; // LCOV_EXCL_LINE simple fallthrough not registered as covered.
default:
break;
break; // LCOV_EXCL_LINE simple fallthrough not registered as covered.
}
state |= std::ios_base::failbit;
@@ -533,10 +533,10 @@ namespace boost {
val = positive_nan<ValType>();
return;
}
break;
break; // LCOV_EXCL_LINE simple fallthrough not registered as covered.
default:
break;
break; // LCOV_EXCL_LINE simple fallthrough not registered as covered.
}
}

View File

@@ -895,6 +895,7 @@ test-suite distribution_tests :
[ run test_legacy_nonfinite.cpp /boost/test//boost_unit_test_framework ]
[ run test_basic_nonfinite.cpp /boost/test//boost_unit_test_framework ]
[ run test_nonfinite_io.cpp /boost/test//boost_unit_test_framework ]
[ run test_lexical_cast.cpp /boost/test//boost_unit_test_framework ]
[ run test_nonfinite_trap.cpp /boost/test//boost_unit_test_framework : : : <exception-handling>off:<build>no ]
[ run test_signed_zero.cpp /boost/test//boost_unit_test_framework ]

View File

@@ -163,6 +163,19 @@ template<class CharType, class ValType> void basic_test_inf_impl()
BOOST_CHECK(b2 == a2);
BOOST_CHECK(b3 == std::numeric_limits<ValType>::infinity());
BOOST_CHECK(ss.rdstate() == std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "ind";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit);
ss.clear();
ss.str(S_(""));
ss << "infinidy";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit);
}
//------------------------------------------------------------------------------
@@ -221,6 +234,56 @@ template<class CharType, class ValType> void basic_test_nan_impl()
BOOST_CHECK(!(signbit)(b5));
BOOST_CHECK(ss.rdstate() == std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "nad";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit);
ss.clear();
ss.str(S_(""));
ss << "nan(123";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "qnad";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
std::locale new_locale_2(tmp_locale, new nonfinite_num_get<CharType>(legacy));
ss.imbue(new_locale_2);
ss.clear();
ss.str(S_(""));
ss << "qnan";
ss >> b1;
BOOST_CHECK((boost::math::isnan)(b1));
ss.clear();
ss.str(S_(""));
ss << "qnad";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "1.#SNAD";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "1.#POP";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
ss.clear();
ss.str(S_(""));
ss << "1.#IMP";
ss >> b1;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit | std::ios_base::eofbit);
}
//------------------------------------------------------------------------------

View File

@@ -22,6 +22,8 @@
#include <sstream>
#include <iomanip>
#include "boost/math/tools/test.hpp"
namespace {
// Using an anonymous namespace resolves ambiguities on platforms
@@ -30,7 +32,7 @@ namespace {
using namespace boost::math;
using boost::math::signbit;
using boost::math::changesign;
using (boost::math::isnan)(;
using boost::math::isnan;
//------------------------------------------------------------------------------
// Test nonfinite_num_put and nonfinite_num_get facets by checking
@@ -232,6 +234,15 @@ template<class CharType, class ValType> void trap_test_get_nan_impl()
ss.clear();
ss.str(S_(""));
ValType a3 = std::numeric_limits<ValType>::quiet_NaN();
ss << std::showpos << a3;
ValType b3;
ss >> b3;
BOOST_CHECK(ss.rdstate() == std::ios_base::failbit);
ss.clear();
ss.str(S_(""));
ValType a2 = std::numeric_limits<ValType>::signaling_NaN();
ss << a2;
ValType b2;