summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/float/tst_float.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-09 14:05:35 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-11-20 21:34:13 +0000
commit37f617c405ae4f26cbb6bb4f08d61d6ccc111a98 (patch)
treec824af3e026f1b71103dc85b401ce68fe3a432a3 /tests/auto/testlib/selftests/float/tst_float.cpp
parent1135cf3df4ef9670332891153e9b38f1aa5f2f56 (diff)
Add qfloat16 support to QCOMPARE
Change-Id: Ide06f215a888328308a06e7e48edd666f790a5f0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/float/tst_float.cpp')
-rw-r--r--tests/auto/testlib/selftests/float/tst_float.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp
index 2fffcc7803..b12bc24c58 100644
--- a/tests/auto/testlib/selftests/float/tst_float.cpp
+++ b/tests/auto/testlib/selftests/float/tst_float.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include <QtCore/QCoreApplication>
+#include <QtCore/qfloat16.h>
#include <QtTest/QtTest>
#include <QDebug>
@@ -36,6 +37,8 @@ class tst_float: public QObject
private slots:
void floatComparisons() const;
void floatComparisons_data() const;
+ void float16Comparisons() const;
+ void float16Comparisons_data() const;
void compareFloatTests() const;
void compareFloatTests_data() const;
};
@@ -79,6 +82,42 @@ void tst_float::floatComparisons_data() const
<< float(100002);
}
+void tst_float::float16Comparisons() const
+{
+ QFETCH(qfloat16, operandLeft);
+ QFETCH(qfloat16, operandRight);
+
+ QCOMPARE(operandLeft, operandRight);
+}
+
+void tst_float::float16Comparisons_data() const
+{
+ QTest::addColumn<qfloat16>("operandLeft");
+ QTest::addColumn<qfloat16>("operandRight");
+
+ 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);
+
+ // QCOMPARE for qfloat16s uses qFuzzyCompare()
+
+ QTest::newRow("should FAIL 3")
+ << qfloat16(98)
+ << qfloat16(99);
+
+ QTest::newRow("should SUCCEED 2")
+ << qfloat16(1001)
+ << qfloat16(1002);
+}
+
void tst_float::compareFloatTests() const
{
QFETCH(float, t1);