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