Skip to content

Commit

Permalink
Generalize floating-point conversion tests.
Browse files Browse the repository at this point in the history
Runs the tests for more float-like types.  Also, fixes a crash with a
type conversion when comparing to integral reference numbers.
  • Loading branch information
jtv committed Nov 28, 2017
1 parent ff3645f commit 0e8dae1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/unit/test_float.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ template<typename T> T make_infinity()
return numeric_limits<T>::infinity();
}

void infinity_test(transaction_base &)
/// Test conversions for some floating-point type.
template<typename T> void infinity_test()
{
double inf = make_infinity<double>();
T inf = make_infinity<T>();
string inf_string;
double back_conversion;
T back_conversion;

inf_string = to_string(inf);
from_string(inf_string, back_conversion);
PQXX_CHECK_LESS(
999999999,
T(999999999),
back_conversion,
"Infinity doesn't convert back to something huge.");

inf_string = to_string(-inf);
from_string(inf_string, back_conversion);
PQXX_CHECK_LESS(back_conversion, -999999999, "Negative infinity is broken");
PQXX_CHECK_LESS(
back_conversion,
-T(999999999),
"Negative infinity is broken");
}

void test_infinities(transaction_base &)
{
infinity_test<float>();
infinity_test<double>();
infinity_test<long double>();
}
} // namespace

PQXX_REGISTER_TEST_NODB(infinity_test)
PQXX_REGISTER_TEST_NODB(test_infinities)

0 comments on commit 0e8dae1

Please sign in to comment.