Utils: Implement more Utils::anyOf variations

Change-Id: I0cba5b58dde6003f5c5cb399142f985cbe83f0a7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tobias Hunger
2017-12-01 11:01:19 +01:00
parent 8cd2c234db
commit 9b832f670d
2 changed files with 37 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ class tst_Algorithm : public QObject
Q_OBJECT
private slots:
void anyOf();
void transform();
void sort();
void contains();
@@ -63,6 +64,29 @@ struct Struct
};
}
void tst_Algorithm::anyOf()
{
{
const QList<QString> strings({"1", "3", "132"});
QVERIFY(Utils::anyOf(strings, [](const QString &s) { return s == "132"; }));
QVERIFY(!Utils::anyOf(strings, [](const QString &s) { return s == "1324"; }));
}
{
const QList<Struct> list({2, 4, 6, 8});
QVERIFY(Utils::anyOf(list, &Struct::isEven));
QVERIFY(!Utils::anyOf(list, &Struct::isOdd));
}
{
const QList<Struct> list({0, 0, 0, 0, 1, 0, 0});
QVERIFY(Utils::anyOf(list, &Struct::member));
}
{
const QList<Struct> list({0, 0, 0, 0, 0, 0, 0});
QVERIFY(!Utils::anyOf(list, &Struct::member));
}
}
void tst_Algorithm::transform()
{
// same container type