diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-28 13:20:29 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-10-28 13:21:17 (GMT) |
commit | b41086b8f68f280f1f683d0f107b26d1c6221883 (patch) | |
tree | 9093e337b0264f7d9adda45121b8b09c0ef805ab /tests/auto/qalgorithms | |
parent | e2584b9e910da18e7e472b5681eb7d0d1630647a (diff) | |
download | Qt-b41086b8f68f280f1f683d0f107b26d1c6221883.zip Qt-b41086b8f68f280f1f683d0f107b26d1c6221883.tar.gz Qt-b41086b8f68f280f1f683d0f107b26d1c6221883.tar.bz2 |
Extand test of qBinaryFind
Diffstat (limited to 'tests/auto/qalgorithms')
-rw-r--r-- | tests/auto/qalgorithms/tst_qalgorithms.cpp | 17 |
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); |