[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/004 abb1363 05/11: Refactor a unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/004 abb1363 05/11: Refactor a unit test |
Date: |
Sun, 20 Dec 2020 17:40:09 -0500 (EST) |
branch: valyuta/004
commit abb1363b0ca6fb9dac697a2fd69627f3e676a564
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Refactor a unit test
Combining free functions into a class makes it easy to grant friendship.
---
round_to_test.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 51 insertions(+), 7 deletions(-)
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 1950a7e..829d8e8 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -110,8 +110,42 @@ void set_hardware_rounding_mode(e_ieee754_rounding mode,
bool synchronize)
}
}
+class round_to_test
+{
+ public:
+ static void test();
+
+ private:
+ static void test_fundamentals();
+ static void test_all_modes(bool synchronize);
+ static void test_rounding();
+ static void test_various_styles
+ (long double unrounded
+ ,long double expected
+ );
+ static void test_various_decimals
+ (rounding_style style
+ ,long double unrounded
+ ,long double expected
+ );
+ static void test_various_float_types
+ (int decimals
+ ,rounding_style style
+ ,long double unrounded
+ ,long double expected
+ );
+
+ template<typename RealType>
+ static bool test_one_case
+ (RealType unrounded
+ ,RealType expected
+ ,int decimals
+ ,rounding_style style
+ );
+};
+
template<typename RealType>
-bool test_one_case
+bool round_to_test::test_one_case
(RealType unrounded
,RealType expected
,int decimals
@@ -258,7 +292,7 @@ bool test_one_case
return error_is_within_tolerance;
}
-void test_various_float_types
+void round_to_test::test_various_float_types
(int decimals
,rounding_style style
,long double unrounded
@@ -274,7 +308,7 @@ void test_various_float_types
}
// Test rounding to various numbers of decimal places.
-void test_various_decimals
+void round_to_test::test_various_decimals
(rounding_style style
,long double unrounded
,long double expected
@@ -288,7 +322,7 @@ void test_various_decimals
}
// Test rounding to zero decimals with each rounding style.
-void test_various_styles
+void round_to_test::test_various_styles
(long double unrounded
,long double expected
)
@@ -300,7 +334,7 @@ void test_various_styles
test_various_float_types(0, r_not_at_all, unrounded, expected);
}
-void test_rounding()
+void round_to_test::test_rounding()
{
// The first several blocks of tests use values with no more than
// six significant decimal digits, six being a natural value for
@@ -453,7 +487,7 @@ void test_rounding()
// rigorous bounds, both overall and for each step.
}
-void test_all_modes(bool synchronize)
+void round_to_test::test_all_modes(bool synchronize)
{
// As stated above, we'd like this to be true for all
// floating-point types:
@@ -513,7 +547,7 @@ void test_all_modes(bool synchronize)
test_rounding();
}
-int test_main(int, char*[])
+void round_to_test::test_fundamentals()
{
default_rounding_style() = r_indeterminate;
@@ -565,6 +599,11 @@ int test_main(int, char*[])
,std::domain_error
,"Invalid number of decimals."
);
+}
+
+void round_to_test::test()
+{
+ test_fundamentals();
// The software default rounding style and the hardware rounding
// mode may be either synchronized or not, so test both ways.
@@ -572,6 +611,11 @@ int test_main(int, char*[])
test_all_modes(true);
std::cout << " Default style NOT synchronized to hardware mode:\n";
test_all_modes(false);
+}
+
+int test_main(int, char*[])
+{
+ round_to_test::test();
return EXIT_SUCCESS;
}
- [lmi-commits] [lmi] valyuta/004 updated (3742c54 -> b73e751), Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 be42a58 03/11: Assert rather than assign, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 4a58266 09/11: Suppress the costly assertion that was recently added, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 2913536 06/11: Fix a unit test, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 c5f666f 08/11: Improve rounding to cents for solves, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 34326d6 04/11: Eliminate a return code that was always zero, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 abb1363 05/11: Refactor a unit test,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/004 7eacf2b 07/11: Prefer explicit to implicit currency rounding in unit test, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 58962eb 01/11: Refactor, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 9a03ce9 10/11: Add a handy git command, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 b73e751 11/11: Record timings as of 20201215T2247Z SHA1 3742c540, Greg Chicares, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 0c93fc2 02/11: Fix a problem somewhat mystically, Greg Chicares, 2020/12/20