50{
51
52 {
53 double adouble = std::numeric_limits<int>::max();
54 int aint = checked_cast<int>(adouble);
55 BOOST_CHECK_EQUAL(aint, adouble);
56 }
57 {
58 double adouble = std::numeric_limits<int>::min();
59 int aint = checked_cast<int>(adouble);
60 BOOST_CHECK_EQUAL(aint, adouble);
61 }
62
63
64 try
65 {
66 double adouble = std::numeric_limits<int>::max() + 1.0;
67 int aint = checked_cast<int>(adouble);
68 BOOST_CHECK_EQUAL(aint, adouble);
69 }
70 catch (std::runtime_error &e)
71 {
72 std::string errmss = e.what();
73 BOOST_CHECK_EQUAL("Level 0 assertion violation", errmss.substr(0, 27));
74 }
75
76 try
77 {
78 double adouble = std::numeric_limits<int>::min() - 1.0;
79 int aint = checked_cast<int>(adouble);
80 BOOST_CHECK_EQUAL(aint, adouble);
81 }
82 catch (std::runtime_error &e)
83 {
84 std::string errmss = e.what();
85 BOOST_CHECK_EQUAL("Level 0 assertion violation", errmss.substr(0, 27));
86 }
87}