diff options
Diffstat (limited to 'tests/auto/algorithm/tst_algorithm.cpp')
-rw-r--r-- | tests/auto/algorithm/tst_algorithm.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/algorithm/tst_algorithm.cpp b/tests/auto/algorithm/tst_algorithm.cpp index 87e3b7ecbd..88845d7e01 100644 --- a/tests/auto/algorithm/tst_algorithm.cpp +++ b/tests/auto/algorithm/tst_algorithm.cpp @@ -50,6 +50,7 @@ private slots: void findOrDefault(); void toRawPointer(); void toReferences(); + void take(); }; @@ -612,6 +613,31 @@ void tst_Algorithm::toReferences() } } +void tst_Algorithm::take() +{ + { + QList<Struct> v {1, 3, 5, 6, 7, 8, 9, 11, 13, 15, 13, 16, 17}; + Utils::optional<Struct> r1 = Utils::take(v, [](const Struct &s) { return s.member == 13; }); + QVERIFY(r1); + QCOMPARE(r1.value(), 13); + Utils::optional<Struct> r2 = Utils::take(v, [](const Struct &s) { return s.member == 13; }); + QVERIFY(r2); + QCOMPARE(r2.value(), 13); + Utils::optional<Struct> r3 = Utils::take(v, [](const Struct &s) { return s.member == 13; }); + QVERIFY(!r3); + + Utils::optional<Struct> r4 = Utils::take(v, &Struct::isEven); + QVERIFY(r4); + QCOMPARE(r4.value(), 6); + } + { + QList<Struct> v {0, 0, 0, 0, 0, 0, 1, 2, 3}; + Utils::optional<Struct> r1 = Utils::take(v, &Struct::member); + QVERIFY(r1); + QCOMPARE(r1.value(), 1); + } +} + QTEST_MAIN(tst_Algorithm) #include "tst_algorithm.moc" |