void tst_QVectorArray::create2DArray() { QVector2DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f); array.append(3.0f, 4.0f); array.append(QVector2D(5.0f, 6.0f)); array.append(QPointF(7.0f, 8.0f)); array.append(QPoint(9, 10)); QCOMPARE(array.size(), 5); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[1] == QVector2D(3.0f, 4.0f)); QVERIFY(array[2] == QVector2D(5.0f, 6.0f)); QVERIFY(array[3] == QVector2D(7.0f, 8.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); array.append(QVector2D(11.0f, 12.0f), QVector2D(13.0f, 14.0f)); array.append(QVector2D(15.0f, 16.0f), QVector2D(17.0f, 18.0f), QVector2D(19.0f, 20.0f)); array.append(QVector2D(21.0f, 22.0f), QVector2D(23.0f, 24.0f), QVector2D(25.0f, 26.0f)); for (int index = 0; index < array.size(); ++index) QVERIFY(array[index] == QVector2D(index * 2 + 1, index * 2 + 2)); QVector2DArray array2(34); QCOMPARE(array2.size(), 34); for (int index = 0; index < array2.size(); ++index) QCOMPARE(array2[index], QVector2D(0.0f, 0.0f)); QVector2DArray array3(15, QVector2D(1.0f, 2.0f)); QCOMPARE(array3.size(), 15); for (int index = 0; index < array3.size(); ++index) QCOMPARE(array3[index], QVector2D(1.0f, 2.0f)); }
void tst_QVectorArray::vector2DArray() { QVector2DArray array; QVERIFY(array.isEmpty()); array.append(1.0f, 2.0f); array.append(3.0f, 4.0f); array.append(QVector2D(5.0f, 6.0f)); array.append(QPointF(7.0f, 8.0f)); array.append(QPoint(9, 10)); QCOMPARE(array.size(), 5); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[1] == QVector2D(3.0f, 4.0f)); QVERIFY(array[2] == QVector2D(5.0f, 6.0f)); QVERIFY(array[3] == QVector2D(7.0f, 8.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); array.append(QVector2D(11.0f, 12.0f), QVector2D(13.0f, 14.0f)); array.append(QVector2D(15.0f, 16.0f), QVector2D(17.0f, 18.0f), QVector2D(19.0f, 20.0f)); array.append(QVector2D(21.0f, 22.0f), QVector2D(23.0f, 24.0f), QVector2D(25.0f, 26.0f)); for (int index = 0; index < array.size(); ++index) QVERIFY(array[index] == QVector2D(index * 2 + 1, index * 2 + 2)); int size = array.size(); QVector2DArray result = array.scaled(1.0); // check did not change the original QCOMPARE(array.size(), size); QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); // result should be copy - mult by 1.0 costs nothing QVERIFY(!result.isDetached()); QCOMPARE(result.size(), size); QCOMPARE(result[0], QVector2D(1.0f, 2.0f)); QCOMPARE(result[4], QVector2D(9.0f, 10.0f)); QCOMPARE(result[12], QVector2D(25.0f, 26.0f)); // now actually do a scale result = array.scaled(2.0); QCOMPARE(result.size(), size); QCOMPARE(array.size(), size); QCOMPARE(array[0], QVector2D(1.0f, 2.0f)); QCOMPARE(array[4], QVector2D(9.0f, 10.0f)); QCOMPARE(result[0], QVector2D(2.0f, 4.0f)); QCOMPARE(result[4], QVector2D(18.0f, 20.0f)); QCOMPARE(result[12], QVector2D(50.0f, 52.0f)); array.scale(1.0); QCOMPARE(array.size(), size); // should all be the same QCOMPARE(array[0], QVector2D(1.0f, 2.0f)); QCOMPARE(array[4], QVector2D(9.0f, 10.0f)); QCOMPARE(array[12], QVector2D(25.0f, 26.0f)); array.scale(2.0); QCOMPARE(array.size(), size); // size should be the same QCOMPARE(array[0], QVector2D(2.0f, 4.0f)); QCOMPARE(array[4], QVector2D(18.0f, 20.0f)); QCOMPARE(array[12], QVector2D(50.0f, 52.0f)); }