From ae5812ee793999f78f725e10cb8d531cbd51782f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Wed, 13 Jan 2010 15:40:59 +0100 Subject: 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) --- .../tst_qgraphicsanchorlayout1.cpp | 26 +++++++++++----------- 1 file 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); -- cgit v0.12