summaryrefslogtreecommitdiffstats
path: root/tests/auto/qalgorithms/tst_qalgorithms.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qalgorithms/tst_qalgorithms.cpp')
-rw-r--r--tests/auto/qalgorithms/tst_qalgorithms.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/auto/qalgorithms/tst_qalgorithms.cpp b/tests/auto/qalgorithms/tst_qalgorithms.cpp
index 1f1de82..176a451 100644
--- a/tests/auto/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/qalgorithms/tst_qalgorithms.cpp
@@ -602,9 +602,15 @@ void tst_QAlgorithms::test_qUpperBound()
void tst_QAlgorithms::test_qBinaryFind_data()
{
QTest::addColumn<QList<int> >("data");
- QTest::addColumn<int>("resultValue");
+ QTest::addColumn<int>("resultValue"); // -42 means not found
QTest::newRow("sorted-duplicate") << (QList<int>() << 1 << 2 << 2 << 3) << 2;
+ QTest::newRow("sorted-end") << (QList<int>() << -5 << -2 << 0 << 8) << 8;
+ QTest::newRow("sorted-beginning") << (QList<int>() << -5 << -2 << 0 << 8) << -5;
+ QTest::newRow("sorted-duplicate-beginning") << (QList<int>() << -5 << -5 << -2 << 0 << 8) << -5;
+ QTest::newRow("empty") << (QList<int>()) << -42;
+ QTest::newRow("not found 1 ") << (QList<int>() << 1 << 5 << 8 << 65) << -42;
+ QTest::newRow("not found 2 ") << (QList<int>() << -456 << -5 << 8 << 65) << -42;
}
void tst_QAlgorithms::test_qBinaryFind()
@@ -612,6 +618,15 @@ void tst_QAlgorithms::test_qBinaryFind()
QFETCH(QList<int>, data);
QFETCH(int, resultValue);
+ //-42 means not found
+ if (resultValue == -42) {
+ QVERIFY(qBinaryFind(data.constBegin(), data.constEnd(), resultValue) == data.end());
+ QVERIFY(qBinaryFind(data, resultValue) == data.end());
+ QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue) == data.end());
+ QVERIFY(qBinaryFind(data.begin(), data.end(), resultValue, qLess<int>()) == data.end());
+ return;
+ }
+
QCOMPARE(*qBinaryFind(data.constBegin(), data.constEnd(), resultValue), resultValue);
QCOMPARE(*qBinaryFind(data.begin(), data.end(), resultValue), resultValue);
QCOMPARE(*qBinaryFind(data, resultValue), resultValue);