/* * SPDX-FileCopyrightText: 2014 Frank Reininghaus * * SPDX-License-Identifier: GPL-2.0-or-later */ #include "kitemviews/kitemrange.h" #include #include Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(KItemRangeList) class KItemRangeTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void testFromSortedContainer_data(); void testFromSortedContainer(); }; void KItemRangeTest::initTestCase() { QStandardPaths::setTestModeEnabled(true); } void KItemRangeTest::testFromSortedContainer_data() { QTest::addColumn>("sortedNumbers"); QTest::addColumn("expected"); QTest::newRow("empty") << QVector{} << KItemRangeList(); QTest::newRow("[1]") << QVector{1} << (KItemRangeList() << KItemRange(1, 1)); QTest::newRow("[9]") << QVector{9} << (KItemRangeList() << KItemRange(9, 1)); QTest::newRow("[1-2]") << QVector{1, 2} << (KItemRangeList() << KItemRange(1, 2)); QTest::newRow("[1-3]") << QVector{1, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); QTest::newRow("[1] [4]") << QVector{1, 4} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(4, 1)); QTest::newRow("[1-3] [5]") << QVector{1, 2, 3, 5} << (KItemRangeList() << KItemRange(1, 3) << KItemRange(5, 1)); QTest::newRow("[1] [5-6]") << QVector{1, 5, 6} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2)); QTest::newRow("duplicates: 1 1") << QVector{1, 1} << (KItemRangeList() << KItemRange(1, 1)); QTest::newRow("duplicates: 1 1 1") << QVector{1, 1, 1} << (KItemRangeList() << KItemRange(1, 1)); QTest::newRow("duplicates: 1 1 5") << QVector{1, 1, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); QTest::newRow("duplicates: 1 5 5") << QVector{1, 5, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); QTest::newRow("duplicates: 1 1 1 5") << QVector{1, 1, 1, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); QTest::newRow("duplicates: 1 5 5 5") << QVector{1, 5, 5, 5} << (KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 1)); QTest::newRow("duplicates: 1 1 2") << QVector{1, 1, 2} << (KItemRangeList() << KItemRange(1, 2)); QTest::newRow("duplicates: 1 2 2") << QVector{1, 2, 2} << (KItemRangeList() << KItemRange(1, 2)); QTest::newRow("duplicates: 1 1 2 3") << QVector{1, 1, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); QTest::newRow("duplicates: 1 2 2 3") << QVector{1, 2, 2, 3} << (KItemRangeList() << KItemRange(1, 3)); QTest::newRow("duplicates: 1 2 3 3") << QVector{1, 2, 3, 3} << (KItemRangeList() << KItemRange(1, 3)); } void KItemRangeTest::testFromSortedContainer() { QFETCH(QVector, sortedNumbers); QFETCH(KItemRangeList, expected); const KItemRangeList result = KItemRangeList::fromSortedContainer(sortedNumbers); QCOMPARE(expected, result); } QTEST_GUILESS_MAIN(KItemRangeTest) #include "kitemrangetest.moc"