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>
This commit is contained in:
parent
e75b1dfe38
commit
84c9fcffee
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user