diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-01-13 14:40:59 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-01-13 14:56:41 (GMT) |
commit | ae5812ee793999f78f725e10cb8d531cbd51782f (patch) | |
tree | 50e99f5c792de8be56d0e3fc9bbb20243c03c808 /tests | |
parent | 58be75dec90afbda3c9640266708a7d5b30a1f50 (diff) | |
download | Qt-ae5812ee793999f78f725e10cb8d531cbd51782f.zip Qt-ae5812ee793999f78f725e10cb8d531cbd51782f.tar.gz Qt-ae5812ee793999f78f725e10cb8d531cbd51782f.tar.bz2 |
Replace the truncate function with fuzzierCompare().
truncate did a qRound of the two numbers, which could cause two numbers
that were close to become far away (e.g. (0.000049 and 0.000051 would
become 0 and 1 respectively)
fuzzierCompare allows less precision than qFuzzyCompare. This is because
the anchor layout engine can sometimes do quite a lot of calculations,
and the error will be larger than what the qFuzzyCompare checks for.
Thus, the factor in fuzzierCompare is not chosen due to mathematical
proof but rather it is just chosen by what is acceptable.
(actually it can still be larger and still be acceptable)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index e3d1bbe..7cacd85 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -1669,16 +1669,16 @@ inline QGraphicsLayoutItem *getItem( return widgets[index]; } -static QRectF truncate(QRectF original) +static bool fuzzierCompare(qreal a, qreal b) { - QRectF result; + return qAbs(a - b) <= qreal(0.0001); +} - result.setX(qRound(original.x() * 1000000) / 1000000.0); - result.setY(qRound(original.y() * 1000000) / 1000000.0); - result.setWidth(qRound(original.width() * 1000000) / 1000000.0); - result.setHeight(qRound(original.height() * 1000000) / 1000000.0); +static bool fuzzierCompare(const QRectF &r1, const QRectF &r2) +{ - return result; + return fuzzierCompare(r1.x(), r2.x()) && fuzzierCompare(r1.y(), r2.y()) + && fuzzierCompare(r1.width(), r2.width()) && fuzzierCompare(r1.height(), r2.height()); } void tst_QGraphicsAnchorLayout1::testBasicLayout() @@ -1727,10 +1727,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() // Validate for (int i = 0; i < result.count(); ++i) { const BasicLayoutTestResult item = result[i]; - QRectF expected = truncate(item.rect); - QRectF actual = truncate(widgets[item.index]->geometry()); + QRectF expected = item.rect; + QRectF actual = widgets[item.index]->geometry(); - QCOMPARE(actual, expected); + QVERIFY(fuzzierCompare(actual, expected)); } // Test mirrored mode @@ -1744,10 +1744,10 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() if (mirroredRect.isValid()){ mirroredRect.moveLeft(size.width()-item.rect.width()-item.rect.left()); } - QRectF expected = truncate(mirroredRect); - QRectF actual = truncate(widgets[item.index]->geometry()); + QRectF expected = mirroredRect; + QRectF actual = widgets[item.index]->geometry(); - QCOMPARE(actual, expected); + QVERIFY(fuzzierCompare(actual, expected)); } qDeleteAll(widgets); |