summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-10-05 16:44:45 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2023-03-07 16:11:51 +0100
commite1581fba460542049cf9922669096b7802560da9 (patch)
tree6c142cf17a0495bf03f2b331541f1ab52dc6232c /tests
parent21615e8df1340f090a28d7bb6e6a18ff300a22e6 (diff)
Clean up tst_QAlgorithms::count{Trail,Lead}ing_data_impl()
Pull out the arbitrary factor of three as a named constant and document its arbitrariness once. Pull out the mask and bit used in each function's loop to the outer layer of the loop, since they don't depend on the inner loop variable (or the random value generated in that loop). Use QTest::addRow() instead of constructing a string to pass to newRow(). Change-Id: Ifacbcb390e00828fd47f51b0c73d0ad5f6bc8bdb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit ce950bcbf7f6cf3bd5bf5113e7b70016f0d60492)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index 0b921ffdbe..aa5893ec9a 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -304,6 +304,9 @@ void tst_QAlgorithms::popCount_impl()
QCOMPARE(qPopulationCount(value), expected);
}
+// Number of test-cases per offset into each size (arbitrary):
+static constexpr int casesPerOffset = 3;
+
void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
{
using namespace QTest;
@@ -312,10 +315,10 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
int nibs = sizeof_T_Int*2;
- newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
+ addRow("0x%0*llx", nibs, Q_UINT64_C(0)) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
const quint64 input = Q_UINT64_C(1) << i;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i;
+ addRow("0x%0*llx", nibs, input) << input << i;
}
quint64 type_mask;
@@ -326,12 +329,12 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
- for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
+ const quint64 b = Q_UINT64_C(1) << i;
+ const quint64 mask = ((~(b - 1)) ^ b) & type_mask;
+ for (uint j = 0; j < sizeof_T_Int * casesPerOffset; ++j) {
const quint64 r = QRandomGenerator::global()->generate64();
- const quint64 b = Q_UINT64_C(1) << i;
- const quint64 mask = ((~(b-1)) ^ b) & type_mask;
const quint64 input = (r&mask) | b;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << i;
+ addRow("0x%0*llx", nibs, input) << input << i;
}
}
}
@@ -355,20 +358,20 @@ void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int)
int nibs = sizeof_T_Int*2;
- newRow(("0x"+QByteArray::number(0,16).rightJustified(nibs,'0')).constData()) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
+ addRow("0x%0*llx", nibs, Q_UINT64_C(0)) << Q_UINT64_C(0) << uint(sizeof_T_Int*8);
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
const quint64 input = Q_UINT64_C(1) << i;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1);
+ addRow("0x%0*llx", nibs, input) << input << uint(sizeof_T_Int*8-i-1);
}
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
- for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
+ const quint64 b = Q_UINT64_C(1) << i;
+ const quint64 mask = b - 1;
+ for (uint j = 0; j < sizeof_T_Int * casesPerOffset; ++j) {
const quint64 r = QRandomGenerator::global()->generate64();
- const quint64 b = Q_UINT64_C(1) << i;
- const quint64 mask = b-1;
const quint64 input = (r&mask) | b;
- newRow(("0x"+QByteArray::number(input,16).rightJustified(nibs,'0')).constData()) << input << uint(sizeof_T_Int*8-i-1);
+ addRow("0x%0*llx", nibs, input) << input << uint(sizeof_T_Int*8-i-1);
}
}
}