[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b9b9b0f 2/4: Improve unit tests for boost::nu
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b9b9b0f 2/4: Improve unit tests for boost::numeric_cast |
Date: |
Thu, 6 Apr 2017 09:17:43 -0400 (EDT) |
branch: master
commit b9b9b0f4b7a78054a729611a8c725af9c8484270
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Improve unit tests for boost::numeric_cast
Tests that formerly verified the actual (but incorrect) behavior have
been replaced by tests that fail for incorrect behavior.
---
bourn_cast_test.cpp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/bourn_cast_test.cpp b/bourn_cast_test.cpp
index b85b227..23d0ff3 100644
--- a/bourn_cast_test.cpp
+++ b/bourn_cast_test.cpp
@@ -248,9 +248,11 @@ void test_floating_conversions(char const* file, int line)
INVOKE_BOOST_TEST_EQUAL( to_inf, bourn_cast<To>( from_inf), file, line);
INVOKE_BOOST_TEST_EQUAL(-to_inf, bourn_cast<To>(-from_inf), file, line);
#else // defined TEST_BOOST_CAST_INSTEAD
- // Boost doesn't allow conversion of infinities to a narrower
- // floating type, presumably because is presumptively permits
- // conversion to the same or a wider floating type.
+ // Boost allows conversion of infinities to the same type or a
+ // wider floating type, but not to a narrower type--presumably
+ // because infinities are outside the [lowest(), max()] range but
+ // non-narrowing conversions are presumptively allowed regardless
+ // of value.
if(from_traits::digits10 <= to_traits::digits10) // Widening or same.
{
INVOKE_BOOST_TEST_EQUAL( to_inf, bourn_cast<To>( from_inf), file,
line);
@@ -258,16 +260,15 @@ void test_floating_conversions(char const* file, int line)
}
else
{
- INVOKE_BOOST_TEST(false, file, line); // This should be allowed.
BOOST_TEST_THROW
(bourn_cast<To>( from_traits::infinity())
,std::runtime_error
- ,"Cast would transgress upper limit."
+ ,"This cast should have succeeded."
);
BOOST_TEST_THROW
(bourn_cast<To>(-from_traits::infinity())
,std::runtime_error
- ,"Cast would transgress lower limit."
+ ,"This cast should have succeeded."
);
}
#endif // defined TEST_BOOST_CAST_INSTEAD