lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] valyuta/004 2913536 06/11: Fix a unit test


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/004 2913536 06/11: Fix a unit test
Date: Sun, 20 Dec 2020 17:40:09 -0500 (EST)

branch: valyuta/004
commit 2913536e91c1b8b99e9ef9bd62155d71c3e06b4d
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Fix a unit test
    
    Cf.:
      https://lists.nongnu.org/archive/html/lmi/2020-12/msg00006.html
---
 currency.hpp      | 1 +
 round_to_test.cpp | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index 00316b2..d69dd69 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -60,6 +60,7 @@ class currency
     friend std::ostream& operator<<(std::ostream&, currency const&);
     friend class currency_test;
     template<typename T> friend class round_to;
+    friend class round_to_test;
 
 #if defined CURRENCY_UNIT_IS_CENTS
     static constexpr int cents_digits = 2;
diff --git a/round_to_test.cpp b/round_to_test.cpp
index 829d8e8..519e18f 100644
--- a/round_to_test.cpp
+++ b/round_to_test.cpp
@@ -23,6 +23,7 @@
 
 #include "round_to.hpp"
 
+#include "currency.hpp"                 // currency::cents_digits
 #include "fenv_lmi.hpp"
 #include "miscellany.hpp"               // floating_rep()
 #include "test_tools.hpp"
@@ -593,9 +594,10 @@ void round_to_test::test_fundamentals()
     // Try to provoke division by zero in ctor-initializer.
     //
     // nonstd::power() negates a negative exponent, but negating
-    // INT_MIN constitutes UB, so use 1 + INT_MIN.
+    // INT_MIN constitutes UB, so add one, plus currency::cents_digits
+    // because of the interplay between classes currency and round_to.
     BOOST_TEST_THROW
-        (round_to<double>(1 + INT_MIN, r_to_nearest)
+        (round_to<double>(1 + currency::cents_digits + INT_MIN, r_to_nearest)
         ,std::domain_error
         ,"Invalid number of decimals."
         );



reply via email to

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