[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/eraseme_limits 2a83f41 1/6: Improve unit test
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/eraseme_limits 2a83f41 1/6: Improve unit test |
Date: |
Sat, 6 Mar 2021 17:57:41 -0500 (EST) |
branch: odd/eraseme_limits
commit 2a83f41e40a2e91894e63b65b539a024d5d4e378
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve 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] branch odd/eraseme_limits created (now 5e7ba88), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] odd/eraseme_limits 2a83f41 1/6: Improve unit test,
Greg Chicares <=
- [lmi-commits] [lmi] odd/eraseme_limits e43dd18 2/6: Don't write lowest() as "min()" without asserting they're the same, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] odd/eraseme_limits 7e36141 3/6: Don't write lowest() as "min()" even it they're the same, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] odd/eraseme_limits 5bf69bf 4/6: Fix defect introduced 20180319T1957Z: min() isn't lowest(), Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] odd/eraseme_limits 700e166 5/6: Define 'minmax' of an empty vector, Greg Chicares, 2021/03/06
- [lmi-commits] [lmi] odd/eraseme_limits 5e7ba88 6/6: Specialize std::numeric_limits, sort of, Greg Chicares, 2021/03/06