37#include <boost/test/tools/floating_point_comparison.hpp>
38#include <boost/test/unit_test.hpp>
46namespace CheckCastUnitTest
53 double adouble = std::numeric_limits<int>::max();
54 int aint = checked_cast<int>(adouble);
55 BOOST_CHECK_EQUAL(aint, adouble);
58 double adouble = std::numeric_limits<int>::min();
59 int aint = checked_cast<int>(adouble);
60 BOOST_CHECK_EQUAL(aint, adouble);
66 double adouble = std::numeric_limits<int>::max() + 1.0;
67 int aint = checked_cast<int>(adouble);
68 BOOST_CHECK_EQUAL(aint, adouble);
70 catch (std::runtime_error &e)
72 std::string errmss = e.what();
73 BOOST_CHECK_EQUAL(
"Level 0 assertion violation", errmss.substr(0, 27));
78 double adouble = std::numeric_limits<int>::min() - 1.0;
79 int aint = checked_cast<int>(adouble);
80 BOOST_CHECK_EQUAL(aint, adouble);
82 catch (std::runtime_error &e)
84 std::string errmss = e.what();
85 BOOST_CHECK_EQUAL(
"Level 0 assertion violation", errmss.substr(0, 27));
BOOST_AUTO_TEST_CASE(TestDoubleToInt)
The above copyright notice and this permission notice shall be included.