5 #include <gtest/gtest.h>
8 TEST(Comparison, Basic)
35 TEST(Comparison, FloatSpecialCase)
37 ASSERT_FALSE(
uavcan::areClose(0.1, std::numeric_limits<double>::infinity()));
40 std::numeric_limits<long double>::infinity()));
42 ASSERT_FALSE(
uavcan::areClose(std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()));
44 ASSERT_FALSE(
uavcan::areClose(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()));
55 ASSERT_TRUE(
uavcan::areClose(0.0F, -std::numeric_limits<float>::epsilon()));
56 ASSERT_FALSE(
uavcan::areClose(0.0F, std::numeric_limits<float>::epsilon() * 2));
59 TEST(Comparison, BruteforceValidation)
61 const std::streamsize default_precision = std::cout.precision();
62 std::cout.precision(20);
73 std::cout <<
"y1=" << y1 <<
" y2=" << y2 <<
" x=" <<
x << std::endl;
78 std::cout <<
"y1=" << y1 <<
" y2=" << y2 <<
" x=" <<
x << std::endl;
85 std::cout.precision(default_precision);
92 B(
long double val = 0.0L) :
b(val) { }
98 explicit A(
float val = 0.0F) :
a(val) { }
102 std::cout <<
"bool A::isClose(A) --> " << rhs.
a << std::endl;
108 std::cout <<
"bool A::isClose(const B&) --> " << rhs.
b << std::endl;
116 explicit C(
long long val = 0.0L) :
c(val) { }
120 std::cout <<
"bool C::operator==(B) --> " << rhs.
b << std::endl;
121 return c ==
static_cast<long long>(rhs.
b);
125 TEST(Comparison, IsCloseMethod)
131 std::cout << 1 << std::endl;
137 std::cout << 2 << std::endl;
147 std::cout << 3 << std::endl;
155 std::cout << 4 << std::endl;