diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2012-02-03 15:43:28 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-09 04:07:50 +0100 |
commit | 52744f505381c2840efbe1dc4858d422d32d9f32 (patch) | |
tree | 273b2cfda689912de42cc1cfa09f1b5822cfabb4 /tests/auto/testlib/selftests/float/tst_float.cpp | |
parent | 7b7b58ae095e1f098a401f584aeefeb6e2a2fd43 (diff) |
Improve float selftest
Correct a bug in the test and use unique names for data rows. The bug
was that the test assumed that QCOMPARE for float values 100001 and
100002 would fail, but it actually succeeds. QCOMPARE for floats uses
qFuzzyCompare(), which succeeds if the numbers differ by no more than
1/100,000th of the smaller value. Thus QCOMPARE(100001, 100002) passes,
while QCOMPARE(99998, 99999) fails.
Change-Id: Ia35d3126c2e3ebe91d64daa309048514a365d9fb
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto/testlib/selftests/float/tst_float.cpp')
-rw-r--r-- | tests/auto/testlib/selftests/float/tst_float.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/auto/testlib/selftests/float/tst_float.cpp b/tests/auto/testlib/selftests/float/tst_float.cpp index 9b7865ed25..fb10521604 100644 --- a/tests/auto/testlib/selftests/float/tst_float.cpp +++ b/tests/auto/testlib/selftests/float/tst_float.cpp @@ -66,19 +66,28 @@ void tst_float::floatComparisons_data() const QTest::addColumn<float>("operandLeft"); QTest::addColumn<float>("operandRight"); - QTest::newRow("should SUCCEED") + QTest::newRow("should SUCCEED 1") << float(0) << float(0); - QTest::newRow("should FAIL") + QTest::newRow("should FAIL 1") << float(1.00000) << float(3.00000); - QTest::newRow("should FAIL") + QTest::newRow("should FAIL 2") << float(1.00000e-7f) << float(3.00000e-7f); - QTest::newRow("should FAIL") + // QCOMPARE for floats uses qFuzzyCompare(), which succeeds if the numbers + // differ by no more than 1/100,000th of the smaller value. Thus + // QCOMPARE(99998, 99999) should fail, while QCOMPARE(100001, 100002) + // should pass. + + QTest::newRow("should FAIL 3") + << float(99998) + << float(99999); + + QTest::newRow("should SUCCEED 2") << float(100001) << float(100002); } |