summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-11-23 10:41:52 -0800
committerThiago Macieira <thiago.macieira@intel.com>2021-11-23 20:48:08 -0800
commit84c9fcffeeb088d37d014f1f7b7f26f8d3a6a907 (patch)
tree739ba35c4c801875d2ebdffd71ef0e7dcc655247 /tests/auto/corelib/tools
parente75b1dfe380e854ed5ceaf5933740e3759a22aaf (diff)
tst_QHashSeed: improve quality of the quality() test
We expect to produce all-bits-set in the combined OR'ed value of the seed, so instead of counting how many bits got set and reporting that, simply compare to -1 and count how long it took to get that far. To make sure, I've increased the number of iterations by 50%. Change-Id: I89446ea06b5742efb194fffd16ba37b2d93c19ef Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
index f726a29d97..f91ecced76 100644
--- a/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
+++ b/tests/auto/corelib/tools/qhashseed/tst_qhashseed.cpp
@@ -137,9 +137,10 @@ void tst_QHashSeed::quality()
// this "bad seed" is used internally in qhash.cpp and should never leak!
constexpr size_t BadSeed = size_t(Q_UINT64_C(0x5555'5555'5555'5555));
- constexpr int Iterations = 16;
+ constexpr int Iterations = 24; // nicely divisible by 3
int oneThird = 0;
int badSeeds = 0;
+ int seedsToMinus1 = 0;
size_t ored = 0;
for (int i = 0; i < Iterations; ++i) {
@@ -152,29 +153,33 @@ void tst_QHashSeed::quality()
++oneThird;
if (seed == BadSeed)
++badSeeds;
+ if (ored != size_t(-1))
+ ++seedsToMinus1;
QHashSeed::resetRandomGlobalSeed();
}
// report out
+ qInfo() << "Number of seeds until all bits became set:" << seedsToMinus1 << '/' << Iterations;
qInfo() << "Number of seeds with at least one third of the bits set:"
<< oneThird << '/' << Iterations;
- qInfo() << "Number of bits in OR'ed value:" << qPopulationCount(quintptr(ored))
- << '/' << std::numeric_limits<size_t>::digits;
- if (std::numeric_limits<size_t>::digits > 32) {
- quint32 upper = quint64(ored) >> 32;
- qInfo() << "Number of bits in the upper half:" << qPopulationCount(upper) << "/ 32";
- QVERIFY(qPopulationCount(upper) > (32/3));
- }
+
+ // we must have set all bits after all the iterations
+ QCOMPARE(ored, size_t(-1));
// at least one third of the seeds must have one third of all the bits set
- QVERIFY(oneThird > (16/3));
+ QVERIFY(oneThird > (Iterations/3));
// at most one seed can be the bad seed, if 32-bit, none on 64-bit
if (std::numeric_limits<size_t>::digits > 32)
QCOMPARE(badSeeds, 0);
else
- QVERIFY(badSeeds <= 1);
+ QVERIFY2(badSeeds <= 1, "badSeeds = " + QByteArray::number(badSeeds));
+
+ // we must have taken at most two thirds of the iterations to have set each
+ // bit at least once
+ QVERIFY2(seedsToMinus1 < 2*Iterations/3,
+ "seedsToMinus1 = " + QByteArray::number(seedsToMinus1));
}
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)