QList benchmark: inline the removAll tests to match most others
It may be the hobgoblin of little minds, but consistency makes code easier to read. Turn the implementation test into a method of the class, like all the others, and rename it to match the common pattern. In the process, eliminate the data-column that was constant, use simpler expressions for the lists whose entries are all the same and Split some long lines. The test still fails, as it did previously. Change-Id: Ic2d6db1edc0bbafad91cd732babcbc129c430b8f Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
parent
65ac651f12
commit
19f522c74a
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -134,11 +134,11 @@ class tst_QList: public QObject
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void removeAll_primitive_data();
|
void removeAll_primitive_data();
|
||||||
void removeAll_primitive();
|
void removeAll_primitive() { removeAll_impl<MyPrimitive>(); }
|
||||||
void removeAll_movable_data();
|
void removeAll_movable_data() { removeAll_primitive_data(); }
|
||||||
void removeAll_movable();
|
void removeAll_movable() { removeAll_impl<MyMovable>(); }
|
||||||
void removeAll_complex_data();
|
void removeAll_complex_data() { removeAll_primitive_data(); }
|
||||||
void removeAll_complex();
|
void removeAll_complex() { removeAll_impl<MyComplex>(); }
|
||||||
|
|
||||||
// append 1 element:
|
// append 1 element:
|
||||||
void appendOne_int_data() const { commonBenchmark_data<int>(); }
|
void appendOne_int_data() const { commonBenchmark_data<int>(); }
|
||||||
@ -248,6 +248,9 @@ private Q_SLOTS:
|
|||||||
void removeFirstSpecial_QString() const { removeFirstSpecial_impl<QList, QString>(); }
|
void removeFirstSpecial_QString() const { removeFirstSpecial_impl<QList, QString>(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template <class T>
|
||||||
|
void removeAll_impl() const;
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
void commonBenchmark_data() const;
|
void commonBenchmark_data() const;
|
||||||
|
|
||||||
@ -277,9 +280,13 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void removeAll_test(const QList<int> &i10, ushort valueToRemove, int itemsToRemove)
|
void tst_QList::removeAll_impl() const
|
||||||
{
|
{
|
||||||
bool isComplex = QTypeInfo<T>::isComplex;
|
QFETCH(QList<int>, i10);
|
||||||
|
QFETCH(int, itemsToRemove);
|
||||||
|
|
||||||
|
constexpr int valueToRemove = 5;
|
||||||
|
constexpr bool isComplex = QTypeInfo<T>::isComplex;
|
||||||
|
|
||||||
MyBase::errorCount = 0;
|
MyBase::errorCount = 0;
|
||||||
MyBase::liveCount = 0;
|
MyBase::liveCount = 0;
|
||||||
@ -311,63 +318,26 @@ void removeAll_test(const QList<int> &i10, ushort valueToRemove, int itemsToRemo
|
|||||||
QCOMPARE(l.size() + removedCount, list.size());
|
QCOMPARE(l.size() + removedCount, list.size());
|
||||||
QVERIFY(!l.contains(valueToRemove));
|
QVERIFY(!l.contains(valueToRemove));
|
||||||
|
|
||||||
QCOMPARE(MyBase::liveCount, isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1);
|
QCOMPARE(MyBase::liveCount,
|
||||||
QCOMPARE(MyBase::copyCount, isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0);
|
isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1);
|
||||||
|
QCOMPARE(MyBase::copyCount,
|
||||||
|
isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0);
|
||||||
}
|
}
|
||||||
if (isComplex)
|
if (isComplex)
|
||||||
QCOMPARE(MyBase::errorCount, 0);
|
QCOMPARE(MyBase::errorCount, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void tst_QList::removeAll_primitive_data()
|
void tst_QList::removeAll_primitive_data()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QList<int> >();
|
qRegisterMetaType<QList<int> >();
|
||||||
|
|
||||||
QTest::addColumn<QList<int> >("i10");
|
QTest::addColumn<QList<int> >("i10");
|
||||||
QTest::addColumn<int>("valueToRemove");
|
|
||||||
QTest::addColumn<int>("itemsToRemove");
|
QTest::addColumn<int>("itemsToRemove");
|
||||||
|
|
||||||
QTest::newRow("0%") << (QList<int>() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0) << 5 << 0;
|
QTest::newRow("0%") << QList<int>(10, 0) << 0;
|
||||||
QTest::newRow("10%") << (QList<int>() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 5 << 1;
|
QTest::newRow("10%") << (QList<int>() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 1;
|
||||||
QTest::newRow("90%") << (QList<int>() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 5 << 9;
|
QTest::newRow("90%") << (QList<int>() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 9;
|
||||||
QTest::newRow("100%") << (QList<int>() << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5 << 5) << 5 << 10;
|
QTest::newRow("100%") << QList<int>(10, 5) << 10;
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QList::removeAll_primitive()
|
|
||||||
{
|
|
||||||
QFETCH(QList<int>, i10);
|
|
||||||
QFETCH(int, valueToRemove);
|
|
||||||
QFETCH(int, itemsToRemove);
|
|
||||||
|
|
||||||
removeAll_test<MyPrimitive>(i10, valueToRemove, itemsToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QList::removeAll_movable_data()
|
|
||||||
{
|
|
||||||
removeAll_primitive_data();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QList::removeAll_movable()
|
|
||||||
{
|
|
||||||
QFETCH(QList<int>, i10);
|
|
||||||
QFETCH(int, valueToRemove);
|
|
||||||
QFETCH(int, itemsToRemove);
|
|
||||||
|
|
||||||
removeAll_test<MyMovable>(i10, valueToRemove, itemsToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QList::removeAll_complex_data()
|
|
||||||
{
|
|
||||||
removeAll_primitive_data();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QList::removeAll_complex()
|
|
||||||
{
|
|
||||||
QFETCH(QList<int>, i10);
|
|
||||||
QFETCH(int, valueToRemove);
|
|
||||||
QFETCH(int, itemsToRemove);
|
|
||||||
|
|
||||||
removeAll_test<MyComplex>(i10, valueToRemove, itemsToRemove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user