2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/range.hpp>
|
2016-01-19 18:31:49 +11:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2015-04-13 16:45:56 +10:00
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
int
|
2016-01-19 18:31:49 +11:00
|
|
|
main (int, char **)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2016-01-19 18:31:49 +11:00
|
|
|
|
2012-06-15 16:38:10 +10:00
|
|
|
// Check some simple cases close to the edges of a unit range. Tests float rounding.
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::range<double>::unit ().contains ( 0.0), "floating unit contains 0");
|
|
|
|
tap.expect ( cruft::range<double>::unit ().contains ( 1.0), "floating unit contains 1");
|
|
|
|
tap.expect ( cruft::range<double>::unit ().contains (std::numeric_limits<double>::min ()), "floating unit contains min");
|
|
|
|
tap.expect (!cruft::range<double>::unit ().contains (-0.00001), "doesn't contain fractionally low value");
|
|
|
|
tap.expect (!cruft::range<double>::unit ().contains ( 1.00001), "doesn't contain fractionally high value");
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-06-15 16:38:10 +10:00
|
|
|
// Check edge cases of unit with integer values
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::range<uint16_t>::unit ().contains (0), "unsigned unit contains 0");
|
|
|
|
tap.expect ( cruft::range<uint16_t>::unit ().contains (1), "unsigned unit contains 1");
|
|
|
|
tap.expect (!cruft::range<uint16_t>::unit ().contains (2), "unsigned unit doesn't contain 2");
|
|
|
|
tap.expect (!cruft::range<uint16_t>::unit ().contains (std::numeric_limits <uint16_t>::max ()), "unsigned unit doesn't contain max");
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2016-12-21 16:44:48 +11:00
|
|
|
// Check the inclusivity of unlimited with special floating values
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::range<double>::unlimited ().contains (0.0), "floating unlimited contains 0");
|
|
|
|
tap.expect ( cruft::range<double>::unlimited ().contains (+std::numeric_limits<double>::infinity ()), "floating unlimited contains +INF");
|
|
|
|
tap.expect ( cruft::range<double>::unlimited ().contains (-std::numeric_limits<double>::infinity ()), "floating unlimited contains -INF");
|
|
|
|
tap.expect (!cruft::range<double>::unlimited ().contains ( std::numeric_limits<double>::quiet_NaN ()), "floating unlimited doesn't contain NAN");
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2016-12-21 16:44:48 +11:00
|
|
|
// Check the inclusivity of unlimited with some large numbers
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::range<uint16_t>::unlimited ().contains (std::numeric_limits<uint16_t>::min()), "floating unlimited contains min");
|
|
|
|
tap.expect ( cruft::range<uint16_t>::unlimited ().contains (std::numeric_limits<uint16_t>::max()), "floating unlimited contains max");
|
2012-05-23 20:41:11 +10:00
|
|
|
|
2016-12-21 16:44:48 +11:00
|
|
|
// Check inclusivity of max
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect (!cruft::range<double>::max ().contains ( std::numeric_limits<double>::infinity ()), "floating max contains +INF");
|
|
|
|
tap.expect (!cruft::range<double>::max ().contains (-std::numeric_limits<double>::infinity ()), "floating max contains -INF");
|
2012-06-15 16:38:10 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect ( cruft::range<uint16_t>::max ().contains (std::numeric_limits<uint16_t>::min()), "unsigned max contains min");
|
|
|
|
tap.expect ( cruft::range<uint16_t>::max ().contains (std::numeric_limits<uint16_t>::max()), "unsigned max contains max");
|
2012-06-15 16:38:10 +10:00
|
|
|
|
|
|
|
// Check that expansion via NaN is a noop
|
2012-05-23 20:41:11 +10:00
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::range<double> initial_nan (std::numeric_limits<double>::quiet_NaN (),
|
2016-01-19 18:31:49 +11:00
|
|
|
std::numeric_limits<double>::quiet_NaN ());
|
2012-05-23 20:41:11 +10:00
|
|
|
initial_nan.expand (1.0);
|
2016-01-19 18:31:49 +11:00
|
|
|
|
2016-12-21 16:44:48 +11:00
|
|
|
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");
|
2012-05-23 20:41:11 +10:00
|
|
|
}
|
|
|
|
|
2016-01-19 18:31:49 +11:00
|
|
|
return tap.status ();
|
2011-05-23 17:18:52 +10:00
|
|
|
}
|