lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 24611b1 1/7: Improve a unit test


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 24611b1 1/7: Improve a unit test
Date: Sat, 6 Mar 2021 17:55:54 -0500 (EST)

branch: master
commit 24611b105aa194eedb23932e1f80bc9a3276b29c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve a unit test
    
    Demonstrate that the public interface forbids creating binary-fractional
    currency objects, by resurrecting a test from an earlier version that
    did not forbid that.
---
 currency_test.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/currency_test.cpp b/currency_test.cpp
index b1f4970..95add74 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -105,16 +105,20 @@ void currency_test::test_explicit_ctor()
 {
     currency const a1(325, raw_cents{});
     LMI_TEST_EQUAL( 325, a1.m_);
-#if defined DETECT_NONINTEGRAL_CENTS
     // 1/64 is an exact binary constant, so 100/64 cents could be
-    // converted to 1/64 dollars and back without loss of precision;
+    // converted to 1/64 dollars and back without loss of precision,
     // but that's outside the intended scope of the currency class.
+    // Binary-fractional currency could be constructed by using the
+    // private interface to manipulate class internals...
+    currency abusive {1.5625, raw_cents {}};
+    LMI_TEST_EQUAL(1.5625, abusive.m_);
+    LMI_TEST_EQUAL(0.015625, abusive.d());
+    // ...but the public interface forbids it:
     LMI_TEST_THROW
-        ((currency {1.5625, raw_cents {}})
+        (from_cents(1.5625)
         ,std::runtime_error
         ,"Nonintegral cents."
         );
-#endif // defined DETECT_NONINTEGRAL_CENTS
 }
 
 void currency_test::test_negation()



reply via email to

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