[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()
- [lmi-commits] [lmi] master updated (27b708a -> 7d2794b), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 869de45 4/7: Fix defect introduced 20180319T1957Z: min() isn't lowest(), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 7d2794b 7/7: Use minmax<T> iff std::numeric_limits<T>::is_bounded, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 5004bd4 5/7: Define 'minmax' of an empty vector, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master e23c058 6/7: Prefer data-member initializers to ctor delegation, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 24611b1 1/7: Improve a unit test,
Greg Chicares <=
- [lmi-commits] [lmi] master 8e69f1d 2/7: Don't write lowest() as "min()" without asserting they're the same, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] master 3330a9a 3/7: Don't write lowest() as "min()" even it they're the same, Greg Chicares, 2021/03/06