Project

General

Profile

Bug #9596 » 0001-Add-regression-tests-for-floating-point-retrieval.patch

Bruce Toll, 01/10/2022 01:07 PM

View differences:

test/dbo/DboTest.C
}
}
BOOST_AUTO_TEST_CASE( dbo_test48 )
{
// Test that Dbo can retrieve float values without precision loss
// Use a simple SELECT statement as source, so Dbo is not involved in storing data
DboFixture f;
#define FLOAT_WITH_STRING(fl) { fl ## f, #fl }
typedef std::tuple<float, std::string> FloatWithString;
std::vector<FloatWithString> fws_v = {
FLOAT_WITH_STRING(3.354194e-37),
FLOAT_WITH_STRING(0.000100000005),
FLOAT_WITH_STRING(0.000106811516),
FLOAT_WITH_STRING(0.98999995),
FLOAT_WITH_STRING(2.7182817)
};
#undef FLOAT_WITH_STRING
for (auto fws: fws_v) {
{
struct {
float as_float;
std::string as_string;
} in_value, out_value;
std::tie(in_value.as_float, in_value.as_string) = fws;
dbo::Transaction t(*f.session_);
std::tie(out_value.as_float, out_value.as_string) = f.session_->query<FloatWithString>(
"SELECT CAST(" + in_value.as_string + " AS FLOAT(24)), '" + in_value.as_string + "'"
).resultValue();
// Sanity check: the string version of the float should be unchanged
BOOST_CHECK_EQUAL(in_value.as_string, out_value.as_string);
// The retrieved float value should also match
BOOST_CHECK_EQUAL(in_value.as_float, out_value.as_float);
}
}
}
BOOST_AUTO_TEST_CASE( dbo_test49 )
{
// Test that Dbo can retrieve double values without precision loss
// Use a simple SELECT statement as source, so Dbo is not involved in storing data
DboFixture f;
#define DOUBLE_WITH_STRING(dbl) { dbl, #dbl }
typedef std::tuple<double, std::string> DoubleWithString;
std::vector<DoubleWithString> dws_v = {
DOUBLE_WITH_STRING(9.999999999999999e-05),
DOUBLE_WITH_STRING(0.9999999999999999),
DOUBLE_WITH_STRING(1.0000000000000007),
DOUBLE_WITH_STRING(1000.0000000000001),
DOUBLE_WITH_STRING(99999999.99999999),
DOUBLE_WITH_STRING(9.999999999999999e+17),
DOUBLE_WITH_STRING(1.0000000000000001e+18)
};
#undef DOUBLE_WITH_STRING
for (auto dws: dws_v) {
{
struct {
double as_double;
std::string as_string;
} in_value, out_value;
std::tie(in_value.as_double, in_value.as_string) = dws;
dbo::Transaction t(*f.session_);
std::tie(out_value.as_double, out_value.as_string) = f.session_->query<DoubleWithString>(
"SELECT CAST(" + in_value.as_string + " AS FLOAT(53)), '" + in_value.as_string + "'"
).resultValue();
// Sanity check: the string version of the double should be unchanged
BOOST_CHECK_EQUAL(in_value.as_string, out_value.as_string);
// The retrieved double value should also match
BOOST_CHECK_EQUAL(in_value.as_double, out_value.as_double);
}
}
}
BOOST_AUTO_TEST_SUITE_END()
(1-1/2)