[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/004 7eacf2b 07/11: Prefer explicit to implic
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/004 7eacf2b 07/11: Prefer explicit to implicit currency rounding in unit test |
Date: |
Sun, 20 Dec 2020 17:40:10 -0500 (EST) |
branch: valyuta/004
commit 7eacf2bebd1550a31f2f35b1840fb17925f42e52
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Prefer explicit to implicit currency rounding in unit test
---
currency_test.cpp | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/currency_test.cpp b/currency_test.cpp
index 2d91c61..e0c36f3 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -23,10 +23,16 @@
#include "currency.hpp"
+#include "round_to.hpp"
#include "test_tools.hpp"
#include <limits>
+namespace
+{
+ round_to<double> const round_to_cents(2, r_to_nearest);
+} // Unnamed namespace.
+
class currency_test
{
public:
@@ -69,13 +75,13 @@ void currency_test::test_something()
BOOST_TEST( -650 == a2.m_);
double d0 = 123.99999999999;
- currency c0(d0);
+ currency c0 = round_to_cents.c(d0);
std::cout << c0 << " converted from 123.999..." << std::endl;
double d1 = 1.0 + std::numeric_limits<double>::epsilon();
- currency c1(d1);
+ currency c1 = round_to_cents.c(d1);
std::cout << c1 << " converted from 1.0 + epsilon..." << std::endl;
double d2 = 1.0 - std::numeric_limits<double>::epsilon();
- currency c2(d2);
+ currency c2 = round_to_cents.c(d2);
std::cout << c2 << " converted from 1.0 - epsilon..." << std::endl;
double big_num = 1.0e100;
@@ -127,9 +133,9 @@ std::cout << "int4: " << big_int4 << std::endl;
);
#endif // !defined CURRENCY_HAS_INTEGER_DATATYPE
- currency b0(464.180000000000006821);
- currency b1(263.01999999999998181);
- currency b2(0.0);
+ currency b0 = round_to_cents.c(464.180000000000006821);
+ currency b1 = round_to_cents.c(263.01999999999998181);
+ currency b2 = round_to_cents.c(0.0);
b2 += b0;
b2 += b1;
currency b3 = b0 + b1;
- [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, 2020/12/20
- [lmi-commits] [lmi] valyuta/004 7eacf2b 07/11: Prefer explicit to implicit currency rounding in unit test,
Greg Chicares <=
- [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