#include #include #include #include int main (int, char **) { cruft::TAP::logger tap; // Check some simple cases close to the edges of a unit range. Tests float rounding. tap.expect ( cruft::range::unit ().contains ( 0.0), "floating unit contains 0"); tap.expect ( cruft::range::unit ().contains ( 1.0), "floating unit contains 1"); tap.expect ( cruft::range::unit ().contains (std::numeric_limits::min ()), "floating unit contains min"); tap.expect (!cruft::range::unit ().contains (-0.00001), "doesn't contain fractionally low value"); tap.expect (!cruft::range::unit ().contains ( 1.00001), "doesn't contain fractionally high value"); // Check edge cases of unit with integer values tap.expect ( cruft::range::unit ().contains (0), "unsigned unit contains 0"); tap.expect ( cruft::range::unit ().contains (1), "unsigned unit contains 1"); tap.expect (!cruft::range::unit ().contains (2), "unsigned unit doesn't contain 2"); tap.expect (!cruft::range::unit ().contains (std::numeric_limits ::max ()), "unsigned unit doesn't contain max"); // Check the inclusivity of unlimited with special floating values tap.expect ( cruft::range::unlimited ().contains (0.0), "floating unlimited contains 0"); tap.expect ( cruft::range::unlimited ().contains (+std::numeric_limits::infinity ()), "floating unlimited contains +INF"); tap.expect ( cruft::range::unlimited ().contains (-std::numeric_limits::infinity ()), "floating unlimited contains -INF"); tap.expect (!cruft::range::unlimited ().contains ( std::numeric_limits::quiet_NaN ()), "floating unlimited doesn't contain NAN"); // Check the inclusivity of unlimited with some large numbers tap.expect ( cruft::range::unlimited ().contains (std::numeric_limits::min()), "floating unlimited contains min"); tap.expect ( cruft::range::unlimited ().contains (std::numeric_limits::max()), "floating unlimited contains max"); // Check inclusivity of max tap.expect (!cruft::range::max ().contains ( std::numeric_limits::infinity ()), "floating max contains +INF"); tap.expect (!cruft::range::max ().contains (-std::numeric_limits::infinity ()), "floating max contains -INF"); tap.expect ( cruft::range::max ().contains (std::numeric_limits::min()), "unsigned max contains min"); tap.expect ( cruft::range::max ().contains (std::numeric_limits::max()), "unsigned max contains max"); // Check that expansion via NaN is a noop { cruft::range initial_nan (std::numeric_limits::quiet_NaN (), std::numeric_limits::quiet_NaN ()); initial_nan.expand (1.0); tap.expect_eq (initial_nan.lo, 1.0, "NAN expansion noop for lo"); tap.expect_eq (initial_nan.hi, 1.0, "NAN expansion noop for hi"); } return tap.status (); }