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>
bb10
Jason McDonald 2012-02-03 15:43:28 +10:00 committed by Qt by Nokia
parent 7b7b58ae09
commit 52744f5053
2 changed files with 23 additions and 10 deletions

View File

@ -1,26 +1,30 @@
********* Start testing of tst_float *********
Config: Using QTest library @INSERT_QT_VERSION_HERE@, Qt @INSERT_QT_VERSION_HERE@
PASS : tst_float::initTestCase()
FAIL! : tst_float::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare)
FAIL! : tst_float::floatComparisons(should FAIL 1) Compared floats are not the same (fuzzy compare)
Actual (operandLeft): 1
Expected (operandRight): 3
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(61)]
FAIL! : tst_float::floatComparisons(should FAIL) Compared floats are not the same (fuzzy compare)
FAIL! : tst_float::floatComparisons(should FAIL 2) Compared floats are not the same (fuzzy compare)
Actual (operandLeft): 1e-07
Expected (operandRight): 3e-07
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(61)]
FAIL! : tst_float::floatComparisons(should FAIL 3) Compared floats are not the same (fuzzy compare)
Actual (operandLeft): 99998
Expected (operandRight): 99999
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(61)]
FAIL! : tst_float::compareFloatTests(1e0) Compared floats are not the same (fuzzy compare)
Actual (t1): 1
Expected (t3): 3
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(100)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(104)]
FAIL! : tst_float::compareFloatTests(1e-7) Compared floats are not the same (fuzzy compare)
Actual (t1): 1e-07
Expected (t3): 3e-07
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(100)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(104)]
FAIL! : tst_float::compareFloatTests(1e+7) Compared floats are not the same (fuzzy compare)
Actual (t1): 1e+07
Expected (t3): 3e+07
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(100)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/float/tst_float.cpp(104)]
PASS : tst_float::cleanupTestCase()
Totals: 2 passed, 5 failed, 0 skipped
Totals: 2 passed, 6 failed, 0 skipped
********* Finished testing of tst_float *********

View File

@ -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);
}