|
|
|
@ -1474,9 +1474,17 @@ static void TestAddMatrixOverflow()
|
|
|
|
|
constexpr T MAXI{std::numeric_limits<T>::max()};
|
|
|
|
|
BOOST_CHECK(!CheckedAdd(T{1}, MAXI));
|
|
|
|
|
BOOST_CHECK(!CheckedAdd(MAXI, MAXI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(MAXI, MAXI));
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(0, CheckedAdd(T{0}, T{0}).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{0}, MAXI).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, CheckedAdd(T{1}, MAXI - 1).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI - 1, CheckedAdd(T{1}, MAXI - 2).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(0, SaturatingAdd(T{0}, T{0}));
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{0}, MAXI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI, SaturatingAdd(T{1}, MAXI - 1));
|
|
|
|
|
BOOST_CHECK_EQUAL(MAXI - 1, SaturatingAdd(T{1}, MAXI - 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for overflow or underflow */
|
|
|
|
@ -1488,9 +1496,17 @@ static void TestAddMatrix()
|
|
|
|
|
constexpr T MAXI{std::numeric_limits<T>::max()};
|
|
|
|
|
BOOST_CHECK(!CheckedAdd(T{-1}, MINI));
|
|
|
|
|
BOOST_CHECK(!CheckedAdd(MINI, MINI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, SaturatingAdd(MINI, MINI));
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{0}, MINI).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, CheckedAdd(T{-1}, MINI + 1).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(-1, CheckedAdd(MINI, MAXI).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI + 1, CheckedAdd(T{-1}, MINI + 2).value());
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{0}, MINI));
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI, SaturatingAdd(T{-1}, MINI + 1));
|
|
|
|
|
BOOST_CHECK_EQUAL(MINI + 1, SaturatingAdd(T{-1}, MINI + 2));
|
|
|
|
|
BOOST_CHECK_EQUAL(-1, SaturatingAdd(MINI, MAXI));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(util_overflow)
|
|
|
|
|