From 3abfa4dfff08d9d2ab9aeb474656b36076a48b3b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 21 Nov 2018 14:36:08 +0100 Subject: QtTestLib: handle float16 the same as double and float In QCOMPARE, handle NaNs and infinities the way tests want them handled, rather than by strict IEEE rules. In particular, if a test expects NaN, this lets it treat that just like any other expected value, despite NaN != NaN as float16 values. Likewise, format infinities and NaNs specially in toString() so that they're reported consistently. Enable the qfloat16 tests that depend on this QCOMPARE() behavior. Refise the testlib selftest's float test to test qfloat16 the same way it tests float and double (and format the test the same way). This is a follow-up to 37f617c405a. Change-Id: I433256a09b1657e6725d68d07c5f80d805bf586a Reviewed-by: Thiago Macieira --- tests/auto/testlib/selftests/float/tst_float.cpp | 30 ++++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'tests/auto/testlib/selftests/float/tst_float.cpp') diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp index 621dd1ccd9..cefd8a57c4 100644 --- a/tests/auto/testlib/selftests/float/tst_float.cpp +++ b/tests/auto/testlib/selftests/float/tst_float.cpp @@ -175,28 +175,22 @@ void tst_float::float16Comparisons_data() const { QTest::addColumn("operandLeft"); QTest::addColumn("operandRight"); + qfloat16 zero(0), one(1); - QTest::newRow("should SUCCEED 1") - << qfloat16(0) - << qfloat16(0); - - QTest::newRow("should FAIL 1") - << qfloat16(1.000) - << qfloat16(3.000); - - QTest::newRow("should FAIL 2") - << qfloat16(1.000e-4f) - << qfloat16(3.000e-4f); + QTest::newRow("should FAIL 1") << one << qfloat16(3); + QTest::newRow("should PASS 1") << zero << zero; + QTest::newRow("should FAIL 2") << qfloat16(1e-4f) << qfloat16(3e-4f); // QCOMPARE for qfloat16s uses qFuzzyCompare() + QTest::newRow("should PASS 2") << qfloat16(1001) << qfloat16(1002); + QTest::newRow("should FAIL 3") << qfloat16(98) << qfloat16(99); + // ... which gets a bit unreliable near to the type's bounds + QTest::newRow("should PASS 3") << qfloat16(6e-5f) + qfloat16(6e-7f) << qfloat16(6e-5f) + qfloat16(11e-7f); + QTest::newRow("should FAIL 4") << qfloat16(6e-5f) - qfloat16(7e-7f) << qfloat16(6e-5f) - qfloat16(13e-7f); + QTest::newRow("should PASS 4") << qfloat16(6e4) + qfloat16(700) << qfloat16(6e4) + qfloat16(1200); + QTest::newRow("should FAIL 5") << qfloat16(6e4) - qfloat16(600) << qfloat16(6e4) - qfloat16(1200); - QTest::newRow("should FAIL 3") - << qfloat16(98) - << qfloat16(99); - - QTest::newRow("should SUCCEED 2") - << qfloat16(1001) - << qfloat16(1002); + nonFinite_data(zero, one); } void tst_float::compareFloatTests() const -- cgit v1.2.3