Annotate and slight rework some tests for cover

This commit is contained in:
ckormanyos
2025-07-06 14:07:23 +02:00
parent 40fede4b5d
commit 4f47836361
5 changed files with 87 additions and 39 deletions

View File

@@ -1,23 +1,40 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2019 John Maddock. Distributed under the Boost
// Copyright 2019 - 2025 John Maddock.
// Copyright 2025 Christopher Kormanyos.
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <test.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include "test.hpp"
#include <locale>
#include <string>
int main()
{
try{
std::locale::global(std::locale("en-US"));
boost::multiprecision::cpp_dec_float_50 d("1234.56");
std::string s = d.str();
std::string str { };
BOOST_CHECK_EQUAL(s, "1234.56");
try
{
using local_dec_float_type = boost::multiprecision::cpp_dec_float_50;
std::locale::global(std::locale("en-US"));
local_dec_float_type d("1234.56");
str = d.str();
BOOST_CHECK_EQUAL(str, "1234.56");
d = local_dec_float_type("123.456");
str = d.str();
BOOST_CHECK_EQUAL(str, "123.456");
}
catch(const std::runtime_error&){} // No en-US locale
BOOST_CHECK(!str.empty());
BOOST_CHECK(str.find('.') != std::string::npos);
return boost::report_errors();
}

View File

@@ -13,9 +13,11 @@
#define _SCL_SECURE_NO_WARNINGS
#endif
#include <test.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <array>
#include "test.hpp"
#if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50) && !defined(TEST_MPFI_50) && !defined(TEST_FLOAT128) && !defined(TEST_CPP_BIN_FLOAT) && !defined(TEST_CPP_DOUBLE_FLOAT)
#define TEST_MPF_50
@@ -73,11 +75,16 @@ T atan2_def(T y, T x)
T t;
t.backend() = boost::multiprecision::default_ops::get_constant_pi<typename T::backend_type>();
T t2;
if (x)
if (x != 0)
{
t2 = atan(y / x);
t2 += T((t / 2) * (1 - x.sign()) * T(y.sign() + 0.5).sign());
}
else
{
t2 = y.sign() * t / 2;
return t2 + (t / 2) * (1 - x.sign()) * T(y.sign() + 0.5).sign();
}
return t2;
}
template <class T>
@@ -158,13 +165,13 @@ void test()
T e = relative_error(val, T(data[k]));
unsigned err = e.template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
val = atan(-arg);
e = relative_error(val, T(-T(data[k])));
err = e.template convert_to<unsigned>();
if (err > max_err)
{
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
arg *= 10000;
}
@@ -184,28 +191,28 @@ void test()
err = e.template convert_to<unsigned>();
if (err > max_err)
{
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
val = atan2(-arg, 1);
e = relative_error(val, atan2_def(T(-arg), T(1)));
err = e.template convert_to<unsigned>();
if (err > max_err)
{
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
val = atan2(arg, -1);
e = relative_error(val, atan2_def(arg, T(-1)));
err = e.template convert_to<unsigned>();
if (err > max_err)
{
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
val = atan2(-arg, -1);
e = relative_error(val, atan2_def(T(-arg), T(-1)));
err = e.template convert_to<unsigned>();
if (err > max_err)
{
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
arg *= 10000;
}
@@ -214,13 +221,13 @@ void test()
//
err = relative_error(T(atan2(T(0), T(1))), atan2_def(T(0), T(1))).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
if (!boost::multiprecision::is_interval_number<T>::value)
{
// We don't test this with intervals as [-0,0] leads to strange behaviour in atan2...
err = relative_error(T(atan2(T(0), T(-1))), atan2_def(T(0), T(-1))).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
T pi;
@@ -228,29 +235,31 @@ void test()
err = relative_error(T(atan2(T(1), T(0))), T(pi / 2)).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
err = relative_error(T(atan2(T(-1), T(0))), T(pi / -2)).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
T mv = (std::numeric_limits<T>::max)();
err = relative_error(T(atan2(mv, T(1))), T(pi / 2)).template convert_to<unsigned>();
err = relative_error(T(atan2(mv, T(1))), T(pi / 2)).template convert_to<unsigned>();
err = relative_error(T(atan2(mv, T(1))), atan2_def(T(mv), T(1))).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
err = relative_error(T(atan2(-mv, T(1))), T(pi / -2)).template convert_to<unsigned>();
err = relative_error(T(atan2(-mv, T(1))), atan2_def(T(-mv), T(0))).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
if (std::numeric_limits<T>::has_infinity)
{
mv = (std::numeric_limits<T>::infinity)();
err = relative_error(T(atan2(mv, T(1))), T(pi / 2)).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
err = relative_error(T(atan2(-mv, T(1))), T(pi / -2)).template convert_to<unsigned>();
if (err > max_err)
max_err = err;
max_err = err; // LCOV_EXCL_LINE This line might not necessarily be expected to get hit in tests.
}
std::cout << "Max error was: " << max_err << std::endl;

View File

@@ -1,5 +1,7 @@
///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. Distributed under the Boost
// Copyright 2012 - 2025 John Maddock.
// Copyright 2025 Christopher Kormanyos.
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
//
@@ -8,14 +10,15 @@
#define _SCL_SECURE_NO_WARNINGS
#endif
#include <boost/detail/lightweight_test.hpp>
#include <array>
#include "test.hpp"
#include <test.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <array>
#include <cstdint>
template <class T>
@@ -48,6 +51,7 @@ void check_round(const T& val, bool check_extended = false)
if (diff2 < diff1)
{
// Some debugging code here...
// LCOV_EXCL_START These lines are not expected to get hit in tests.
std::cout << val.str() << std::endl;
std::cout << std::setprecision(18);
std::cout << d1 << std::endl;
@@ -55,14 +59,19 @@ void check_round(const T& val, bool check_extended = false)
std::cout << diff1 << std::endl;
std::cout << diff2 << std::endl;
d1 = val.template convert_to<double>();
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
}
using std::signbit;
BOOST_CHECK(diff2 >= diff1);
BOOST_CHECK_EQUAL(boost::math::signbit(val), boost::math::signbit(d1));
// Note: Ask John if boost::multiprecision::signbit() should return bool?
BOOST_CHECK_EQUAL((boost::math::signbit(val) != 0), signbit(d1));
float f1 = val.template convert_to<float>();
float f2 = boost::math::nextafter(f1, f1 < val ? FLT_MAX : -FLT_MAX);
BOOST_CHECK(((abs(f1 - val) <= abs(f2 - val))));
BOOST_CHECK_EQUAL(boost::math::signbit(val), boost::math::signbit(f1));
BOOST_CHECK_EQUAL((boost::math::signbit(val) != 0), signbit(f1));
#if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
@@ -78,6 +87,7 @@ void check_round(const T& val, bool check_extended = false)
if (diff2 < diff1)
{
// Some debugging code here...
// LCOV_EXCL_START These lines are not expected to get hit in tests.
std::cout << val.str() << std::endl;
std::cout << std::setprecision(18);
std::cout << l1 << std::endl;
@@ -85,9 +95,10 @@ void check_round(const T& val, bool check_extended = false)
std::cout << diff1 << std::endl;
std::cout << diff2 << std::endl;
l1 = val.template convert_to<long double>();
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
}
BOOST_CHECK(diff2 >= diff1);
BOOST_CHECK_EQUAL(boost::math::signbit(val), boost::math::signbit(l1));
BOOST_CHECK_EQUAL((boost::math::signbit(val) != 0), signbit(l1));
}
#endif

View File

@@ -1,5 +1,7 @@
///////////////////////////////////////////////////////////////
// Copyright 2012 John Maddock. Distributed under the Boost
// Copyright 2012 - 2025 John Maddock.
// Copyright 2025 Christopher Kormanyos.
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
@@ -17,12 +19,13 @@
//
#define BOOST_MP_USE_LIMB_SHIFT
#include <boost/multiprecision/gmp.hpp>
#include <timer.hpp>
#include <test.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/gmp.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include "timer.hpp"
#include "test.hpp"
#ifdef _MSC_VER
#pragma warning(disable : 4127) // Conditional expression is constant
@@ -785,6 +788,7 @@ struct tester
if (last_error_count != (unsigned)boost::detail::test_errors())
{
// LCOV_EXCL_START These lines are not expected to get hit in tests.
last_error_count = boost::detail::test_errors();
std::cout << std::hex << std::showbase;
@@ -817,6 +821,7 @@ struct tester
std::cout << "a1%b1 = " << a1 % b1 << std::endl;
std::cout << "a%d = " << a % d << std::endl;
std::cout << "a1%d1 = " << a1 % d1 << std::endl;
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
}
//

View File

@@ -109,6 +109,7 @@ bool is_bankers_rounding_error(const std::string& s, const char* expect)
return true;
}
// LCOV_EXCL_START These lines are not expected to get hit in tests.
void print_flags(std::ios_base::fmtflags f)
{
std::cout << "Formatting flags were: ";
@@ -122,6 +123,7 @@ void print_flags(std::ios_base::fmtflags f)
std::cout << "showpos ";
std::cout << std::endl;
}
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
template <class T>
void test()
@@ -162,6 +164,7 @@ void test()
}
else
{
// LCOV_EXCL_START These lines are not expected to get hit in tests.
std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
print_flags(f[i]);
std::cout << "Precision is: " << prec << std::endl;
@@ -169,6 +172,7 @@ void test()
std::cout << "Expected: " << expect << std::endl;
++boost::detail::test_errors();
mp_t(val).str(prec, f[i]); // for debugging
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
}
}
}
@@ -195,6 +199,7 @@ void test()
const char* expect = zeros[col];
if (ss.str() != expect)
{
// LCOV_EXCL_START These lines are not expected to get hit in tests.
std::cout << std::setprecision(20) << "Testing value " << val << std::endl;
print_flags(f[i]);
std::cout << "Precision is: " << prec << std::endl;
@@ -202,6 +207,7 @@ void test()
std::cout << "Expected: " << expect << std::endl;
++boost::detail::test_errors();
mp_t(val).str(prec, f[i]); // for debugging
// LCOV_EXCL_STOP These lines are not expected to get hit in tests.
}
}
}