tests/auto/qalgorithms/tst_qalgorithms.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tests/auto/qalgorithms/tst_qalgorithms.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tests/auto/qalgorithms/tst_qalgorithms.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -602,9 +602,15 @@
 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 @@
     QFETCH(QList<int>, data);
     QFETCH(int, resultValue);
 
+    //-42 means not found
+    if (resultValue == -42) {
+        QVERIFY(qBinaryFind(data.constBegin(), data.constEnd(), resultValue) == data.constEnd());
+        QVERIFY(qBinaryFind(data, resultValue) == data.constEnd());
+        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);