[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 5ed8f75 04/15: Refactor a unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 5ed8f75 04/15: Refactor a unit test |
Date: |
Mon, 25 Jan 2021 09:58:04 -0500 (EST) |
branch: master
commit 5ed8f75ecdaac88095be7c32e76330a02086e40c
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 be3951d..64c4d4d 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;
@@ -558,6 +592,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.
@@ -565,6 +604,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] master updated (a111350 -> 9d991b0), Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 6d719d2 10/15: Refactor an assertion, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 2084088 09/15: Record speed measurements, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master da240e8 03/15: Eliminate a return code that was always zero, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master d280c59 05/15: Fix a unit test, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 7b51fab 07/15: Adapt to currency class, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master f7a1129 08/15: Store policy fees as currency, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 2666c48 06/15: Test rounding double to currency, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 5ed8f75 04/15: Refactor a unit test,
Greg Chicares <=
- [lmi-commits] [lmi] master 6a6ebe3 11/15: Adapt to currency class, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 1d5c923 01/15: Change some internal names, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 1e5d1ea 12/15: Adapt to currency class, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 27bd748 13/15: Write $0.00 as a currency rather than floating-point constant, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 9d991b0 15/15: Round currency as such, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master 306ba4e 02/15: Introduce optional (for now) currency class, Greg Chicares, 2021/01/25
- [lmi-commits] [lmi] master fd106fc 14/15: Reformat, Greg Chicares, 2021/01/25