[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 00cd308 1/4: Fortify a unit test to reveal a
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 00cd308 1/4: Fortify a unit test to reveal a latent defect |
Date: |
Mon, 26 Feb 2018 18:50:50 -0500 (EST) |
branch: master
commit 00cd3084c934b3a91034b77e2ce2c0cdedfecb93
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Fortify a unit test to reveal a latent defect
Added tests to demonstrate that calling simplify_floating_point() with
an argument that violates its (unasserted) precondition causes abrupt
termination. The precondition must hold in the single place (aside from
this unit test) where this function is called, so no such error could
ever have arisen in production unless std::snprintf() is defective, but
the defect should be removed nevertheless.
---
numeric_io_test.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/numeric_io_test.cpp b/numeric_io_test.cpp
index 136af9b..3c941a6 100644
--- a/numeric_io_test.cpp
+++ b/numeric_io_test.cpp
@@ -153,12 +153,21 @@ int test_main(int, char*[])
BOOST_TEST_EQUAL( "100", simplify_floating_point( "100.000"));
BOOST_TEST_EQUAL( "0.0001", simplify_floating_point( "0.0001"));
BOOST_TEST_EQUAL( "0.0001", simplify_floating_point( "0.00010"));
+ BOOST_TEST_EQUAL( "0", simplify_floating_point( "0.0"));
BOOST_TEST_EQUAL( "0", simplify_floating_point( "0."));
+ BOOST_TEST_EQUAL( "-0", simplify_floating_point( "-0.0"));
BOOST_TEST_EQUAL( "-0", simplify_floating_point( "-0."));
BOOST_TEST_EQUAL( "nan", simplify_floating_point( "nan"));
BOOST_TEST_EQUAL( "inf", simplify_floating_point( "inf"));
BOOST_TEST_EQUAL( "-inf", simplify_floating_point( "-inf"));
+ // Also test strings that violate preconditions, just to make sure
+ // they don't cause abrupt termination.
+ simplify_floating_point( ".0");
+ simplify_floating_point("-.0");
+ simplify_floating_point( "0");
+ simplify_floating_point( "");
+
std::cout
<< "Conversions:"
<< "\n 2/3, lmi : " << TimeAnAliquot(mete_two_thirds )