88
99using namespace boost ::decimal;
1010
11- template <typename T >
12- void test_to_chars_scientific ()
11+ template <typename ResultsType, typename StringsType >
12+ void test_to_chars_scientific (const ResultsType& decimals, const StringsType& strings )
1313{
14- const std::array<T, 7 > decimals = {
15- T{3 , 2 },
16- T{30 , 1 },
17- T{300 , 0 },
18- T{3000 , -1 },
19- T{30000 , -2 },
20- T{300000 , -3 },
21- T{3000000 , -4 },
22- };
23-
2414 for (std::size_t i {}; i < decimals.size (); ++i)
2515 {
2616 for (std::size_t j {}; j < decimals.size (); ++j)
@@ -29,16 +19,6 @@ void test_to_chars_scientific()
2919 }
3020 }
3121
32- const std::array<const char *, 7 > strings = {
33- " 3e+02" ,
34- " 3.0e+02" ,
35- " 3.00e+02" ,
36- " 3.000e+02" ,
37- " 3.0000e+02" ,
38- " 3.00000e+02" ,
39- " 3.000000e+02" ,
40- };
41-
4222 for (std::size_t i {}; i < decimals.size (); ++i)
4323 {
4424 char buffer[64 ] {};
@@ -66,11 +46,55 @@ void test_to_chars_scientific()
6646 }
6747}
6848
49+ template <typename T>
50+ const std::array<T, 7 > decimals = {
51+ T{3 , 2 },
52+ T{30 , 1 },
53+ T{300 , 0 },
54+ T{3000 , -1 },
55+ T{30000 , -2 },
56+ T{300000 , -3 },
57+ T{3000000 , -4 },
58+ };
59+
60+ constexpr std::array<const char *, 7 > strings = {
61+ " 3e+02" ,
62+ " 3.0e+02" ,
63+ " 3.00e+02" ,
64+ " 3.000e+02" ,
65+ " 3.0000e+02" ,
66+ " 3.00000e+02" ,
67+ " 3.000000e+02" ,
68+ };
69+
70+ template <typename T>
71+ const std::array<T, 6 > decimals_with_exp = {
72+ T {42 , 50 },
73+ T {420 , 49 },
74+ T {4200 , 48 },
75+ T {42000 , 47 },
76+ T {420000 , 46 },
77+ T {4200000 , 45 }
78+ };
79+
80+ constexpr std::array<const char *, 6 > decimals_with_exp_strings = {
81+ " 4.2e+51" ,
82+ " 4.20e+51" ,
83+ " 4.200e+51" ,
84+ " 4.2000e+51" ,
85+ " 4.20000e+51" ,
86+ " 4.200000e+51" ,
87+ };
88+
6989int main ()
7090{
71- test_to_chars_scientific<decimal32_t >();
72- test_to_chars_scientific<decimal64_t >();
73- test_to_chars_scientific<decimal128_t >();
91+ test_to_chars_scientific (decimals<decimal32_t >, strings);
92+ test_to_chars_scientific (decimals<decimal64_t >, strings);
93+ test_to_chars_scientific (decimals<decimal128_t >, strings);
94+
95+ test_to_chars_scientific (decimals_with_exp<decimal32_t >, decimals_with_exp_strings);
96+ test_to_chars_scientific (decimals_with_exp<decimal64_t >, decimals_with_exp_strings);
97+ test_to_chars_scientific (decimals_with_exp<decimal128_t >, decimals_with_exp_strings);
7498
7599 return boost::report_errors ();
76100}
0 commit comments