Skip to content

Commit

Permalink
Add test set
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Dec 13, 2023
1 parent 606fd4e commit 8c706fb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/boost/decimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
#include <boost/decimal/literals.hpp>
#include <boost/decimal/hash.hpp>
#include <boost/decimal/cfloat.hpp>
#include <boost/decimal/format.hpp>

#endif // BOOST_DECIMAL_HPP
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ run test_exp.cpp ;
run test_expm1.cpp ;
run test_fenv.cpp ;
run test_float_conversion.cpp ;
run test_format.cpp ;
run test_frexp_ldexp.cpp ;
run test_git_issue_266.cpp ;
run test_git_issue_271.cpp ;
Expand Down
59 changes: 59 additions & 0 deletions test/test_format.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/decimal.hpp>
#include <boost/core/lightweight_test.hpp>

using namespace boost::decimal;

#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) && __has_include(<format>) && !defined(BOOST_DECIMAL_DISABLE_CLIB)

#include <format>

template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
void test()
{
/*
BOOST_TEST_EQ(std::format("{}", T{1}), "1");
BOOST_TEST_EQ(std::format("{}", T{10}), "1e+01");
BOOST_TEST_EQ(std::format("{}", T{100}), "1e+02");
BOOST_TEST_EQ(std::format("{}", T{1000}), "1e+03");
BOOST_TEST_EQ(std::format("{}", T{10000}), "1e+04");
BOOST_TEST_EQ(std::format("{}", T{210000}), "2.1e+05");
BOOST_TEST_EQ(std::format("{}", T{2100000}), "2.1e+06");
BOOST_TEST_EQ(std::format("{}", T{21, 6, true}), "-2.1e+07");
BOOST_TEST_EQ(std::format("{}", T{211, 6, true}), "-2.11e+08");
BOOST_TEST_EQ(std::format("{}", T{2111, 6, true}), "-2.111e+09");
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::infinity()), "inf");
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::infinity()), "-inf");
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::quiet_NaN()), "nan");
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)");
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
*/

constexpr const char* fmt_string = "{}";

BOOST_TEST_EQ(std::format(fmt_string, 1.0), "1");
BOOST_TEST_EQ(std::format(fmt_string, T{1}), "1");
}

int main()
{
test<decimal32>();
//test<decimal64>();
//test<decimal128>();

return boost::report_errors();
}

#else

int main()
{
return 0;
}

#endif

0 comments on commit 8c706fb

Please sign in to comment.