Skip to content

Commit 8c706fb

Browse files
committed
Add test set
1 parent 606fd4e commit 8c706fb

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

include/boost/decimal.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
#include <boost/decimal/literals.hpp>
1616
#include <boost/decimal/hash.hpp>
1717
#include <boost/decimal/cfloat.hpp>
18+
#include <boost/decimal/format.hpp>
1819

1920
#endif // BOOST_DECIMAL_HPP

test/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ run test_exp.cpp ;
5252
run test_expm1.cpp ;
5353
run test_fenv.cpp ;
5454
run test_float_conversion.cpp ;
55+
run test_format.cpp ;
5556
run test_frexp_ldexp.cpp ;
5657
run test_git_issue_266.cpp ;
5758
run test_git_issue_271.cpp ;

test/test_format.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2023 Matt Borland
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
#include <boost/decimal.hpp>
6+
#include <boost/core/lightweight_test.hpp>
7+
8+
using namespace boost::decimal;
9+
10+
#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) && __has_include(<format>) && !defined(BOOST_DECIMAL_DISABLE_CLIB)
11+
12+
#include <format>
13+
14+
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
15+
void test()
16+
{
17+
/*
18+
BOOST_TEST_EQ(std::format("{}", T{1}), "1");
19+
BOOST_TEST_EQ(std::format("{}", T{10}), "1e+01");
20+
BOOST_TEST_EQ(std::format("{}", T{100}), "1e+02");
21+
BOOST_TEST_EQ(std::format("{}", T{1000}), "1e+03");
22+
BOOST_TEST_EQ(std::format("{}", T{10000}), "1e+04");
23+
BOOST_TEST_EQ(std::format("{}", T{210000}), "2.1e+05");
24+
BOOST_TEST_EQ(std::format("{}", T{2100000}), "2.1e+06");
25+
BOOST_TEST_EQ(std::format("{}", T{21, 6, true}), "-2.1e+07");
26+
BOOST_TEST_EQ(std::format("{}", T{211, 6, true}), "-2.11e+08");
27+
BOOST_TEST_EQ(std::format("{}", T{2111, 6, true}), "-2.111e+09");
28+
29+
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::infinity()), "inf");
30+
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::infinity()), "-inf");
31+
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::quiet_NaN()), "nan");
32+
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::quiet_NaN()), "-nan(ind)");
33+
BOOST_TEST_EQ(std::format("{}", std::numeric_limits<T>::signaling_NaN()), "nan(snan)");
34+
BOOST_TEST_EQ(std::format("{}", -std::numeric_limits<T>::signaling_NaN()), "-nan(snan)");
35+
*/
36+
37+
constexpr const char* fmt_string = "{}";
38+
39+
BOOST_TEST_EQ(std::format(fmt_string, 1.0), "1");
40+
BOOST_TEST_EQ(std::format(fmt_string, T{1}), "1");
41+
}
42+
43+
int main()
44+
{
45+
test<decimal32>();
46+
//test<decimal64>();
47+
//test<decimal128>();
48+
49+
return boost::report_errors();
50+
}
51+
52+
#else
53+
54+
int main()
55+
{
56+
return 0;
57+
}
58+
59+
#endif

0 commit comments

Comments
 (0)