diff options
author | Laszlo Papp <lpapp@kde.org> | 2012-08-02 07:18:35 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-26 00:09:14 +0100 |
commit | e335fb7254ad6c2ce08eda0d092ea524a302c2e0 (patch) | |
tree | 0d6eaa362988c4101d0e210dd97ffa0b44f4beb6 /tests | |
parent | 5f481c98de872e7c58a17f090be697c241b9f256 (diff) |
Add static dotProduct methods to the QPoint(F) classes
Change-Id: I66ac9433b74341a83569a60038ea2f7a025e81b1
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/tools/qpoint/tst_qpoint.cpp | 25 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qpointf/tst_qpointf.cpp | 26 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp index 924cac292e..3231469261 100644 --- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp +++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp @@ -70,6 +70,9 @@ private slots: void operator_divide_data(); void operator_divide(); + void dotProduct_data(); + void dotProduct(); + void operator_unary_plus_data(); void operator_unary_plus(); @@ -271,6 +274,28 @@ void tst_QPoint::operator_divide() QCOMPARE(point, expected); } +void tst_QPoint::dotProduct_data() +{ + QTest::addColumn<QPoint>("point1"); + QTest::addColumn<QPoint>("point2"); + QTest::addColumn<int>("expected"); + + QTest::newRow("(0, 0) dot (0, 0)") << QPoint(0, 0) << QPoint(0, 0)<< 0; + QTest::newRow("(10, 0) dot (0, 10)") << QPoint(10, 0) << QPoint(0, 10) << 0; + QTest::newRow("(0, 10) dot (10, 0)") << QPoint(0, 10) << QPoint(10, 0) << 0; + QTest::newRow("(10, 20) dot (-10, -20)") << QPoint(10, 20) << QPoint(-10, -20) << -500; + QTest::newRow("(-10, -20) dot (10, 20)") << QPoint(-10, -20) << QPoint(10, 20) << -500; +} + +void tst_QPoint::dotProduct() +{ + QFETCH(QPoint, point1); + QFETCH(QPoint, point2); + QFETCH(int, expected); + + QCOMPARE(QPoint::dotProduct(point1, point2), expected); +} + void tst_QPoint::operator_unary_plus_data() { operator_unary_minus_data(); diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp index 0f2e74e68e..fc79b40a18 100644 --- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp +++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp @@ -75,6 +75,9 @@ private slots: void operator_divide(); void division(); + void dotProduct_data(); + void dotProduct(); + void operator_unary_plus_data(); void operator_unary_plus(); @@ -290,6 +293,29 @@ void tst_QPointF::division() } } +void tst_QPointF::dotProduct_data() +{ + QTest::addColumn<QPointF>("point1"); + QTest::addColumn<QPointF>("point2"); + QTest::addColumn<qreal>("expected"); + + QTest::newRow("(0, 0) dot (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << qreal(0); + QTest::newRow("(10, 0) dot (0, 10)") << QPointF(10, 0) << QPointF(0, 10)<< qreal(0); + QTest::newRow("(0, 10) dot (10, 0)") << QPointF(0, 10) << QPointF(10, 0) << qreal(0); + QTest::newRow("(10, 20) dot (-10, -20)") << QPointF(10, 20) << QPointF(-10, -20) << qreal(-500); + QTest::newRow("(10.1, 20.2) dot (-10.1, -20.2)") << QPointF(10.1, 20.2) << QPointF(-10.1, -20.2) << qreal(-510.05); + QTest::newRow("(-10.1, -20.2) dot (10.1, 20.2)") << QPointF(-10.1, -20.2) << QPointF(10.1, 20.2) << qreal(-510.05); +} + +void tst_QPointF::dotProduct() +{ + QFETCH(QPointF, point1); + QFETCH(QPointF, point2); + QFETCH(qreal, expected); + + QCOMPARE(QPointF::dotProduct(point1, point2), expected); +} + void tst_QPointF::operator_unary_plus_data() { operator_unary_minus_data(); |