600 } |
600 } |
601 |
601 |
602 void tst_QAlgorithms::test_qBinaryFind_data() |
602 void tst_QAlgorithms::test_qBinaryFind_data() |
603 { |
603 { |
604 QTest::addColumn<QList<int> >("data"); |
604 QTest::addColumn<QList<int> >("data"); |
605 QTest::addColumn<int>("resultValue"); |
605 QTest::addColumn<int>("resultValue"); // -42 means not found |
606 |
606 |
607 QTest::newRow("sorted-duplicate") << (QList<int>() << 1 << 2 << 2 << 3) << 2; |
607 QTest::newRow("sorted-duplicate") << (QList<int>() << 1 << 2 << 2 << 3) << 2; |
|
608 QTest::newRow("sorted-end") << (QList<int>() << -5 << -2 << 0 << 8) << 8; |
|
609 QTest::newRow("sorted-beginning") << (QList<int>() << -5 << -2 << 0 << 8) << -5; |
|
610 QTest::newRow("sorted-duplicate-beginning") << (QList<int>() << -5 << -5 << -2 << 0 << 8) << -5; |
|
611 QTest::newRow("empty") << (QList<int>()) << -42; |
|
612 QTest::newRow("not found 1 ") << (QList<int>() << 1 << 5 << 8 << 65) << -42; |
|
613 QTest::newRow("not found 2 ") << (QList<int>() << -456 << -5 << 8 << 65) << -42; |
608 } |
614 } |
609 |
615 |
610 void tst_QAlgorithms::test_qBinaryFind() |
616 void tst_QAlgorithms::test_qBinaryFind() |
611 { |
617 { |
612 QFETCH(QList<int>, data); |
618 QFETCH(QList<int>, data); |
613 QFETCH(int, resultValue); |
619 QFETCH(int, resultValue); |
|
620 |
|
621 //-42 means not found |
|
622 if (resultValue == -42) { |
|
623 QVERIFY(qBinaryFind(data.constBegin(), data.constEnd(), resultValue) == data.constEnd()); |
|
624 QVERIFY(qBinaryFind(data, resultValue) == data.constEnd()); |
|
625 QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue) == data.end()); |
|
626 QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue, qLess<int>()) == data.end()); |
|
627 return; |
|
628 } |
614 |
629 |
615 QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue), resultValue); |
630 QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue), resultValue); |
616 QCOMPARE(*qBinaryFind(data.begin(), data.end(), resultValue), resultValue); |
631 QCOMPARE(*qBinaryFind(data.begin(), data.end(), resultValue), resultValue); |
617 QCOMPARE(*qBinaryFind(data, resultValue), resultValue); |
632 QCOMPARE(*qBinaryFind(data, resultValue), resultValue); |
618 QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue, qLess<int>()), resultValue); |
633 QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue, qLess<int>()), resultValue); |