lmi-commits
[Top][All Lists]
Advanced

[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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]