QCOMPARE(
std::numeric_limits<double>::infinity(),
std::numeric_limits<double>::infinity());
fails with:
Compared doubles are not the same (fuzzy compare)
Actual (std::numeric_limits<double>::infinity()): inf
Expected (std::numeric_limits<double>::infinity()): inf
Loc: [...]
Question
Why does this fail? Is there a good work-around (other than using QVERIFY
instead)?
UPDATE:
I mean a work-around from the perspective of a test-writer. It is desirable to provide a proper diagnostic with the actual value which is not infinity. Instead of
QCOMPARE(val, std::numeric_limits<double>::infinity());
one could
QVERIFY(val == std::numeric_limits<double>::infinity()))
but the value of val
is not shown in the generated diagnostic message if the check fails. Looks like a major oversight from developers.
So do I have to roll-out my own macro with exact comparison similar to QCOMPARE
? Any recommendations here?
Also, it is clear that qFuzzyCompare
does not support some corner-cases. But I hoped for a more in-depth explanation of why this is the case.