mirror of https://github.com/catchorg/Catch2.git
Modified hash to make it more independent of the choice of test names.
This commit is contained in:
parent
ff349a50bf
commit
3ba745552b
|
@ -22,24 +22,27 @@ namespace Catch {
|
|||
|
||||
namespace {
|
||||
struct TestHasher {
|
||||
explicit TestHasher(Catch::SimplePcg32& rng_instance) {
|
||||
basis = rng_instance();
|
||||
basis <<= 32;
|
||||
basis |= rng_instance();
|
||||
using hash_t = uint64_t;
|
||||
|
||||
explicit TestHasher(hash_t seed): m_seed{seed} {
|
||||
}
|
||||
|
||||
uint64_t basis;
|
||||
|
||||
uint64_t operator()(TestCase const& t) const {
|
||||
// Modified FNV-1a hash
|
||||
static constexpr uint64_t prime = 1099511628211;
|
||||
uint64_t hash = basis;
|
||||
hash_t operator()(TestCase const& t) const {
|
||||
// FNV-1a hash with multiplication fold.
|
||||
const hash_t prime = 1099511628211u;
|
||||
hash_t hash = 14695981039346656037u;
|
||||
for ( const char c : t.name ) {
|
||||
hash ^= c;
|
||||
hash *= prime;
|
||||
}
|
||||
return hash;
|
||||
hash ^= m_seed;
|
||||
hash *= prime;
|
||||
const uint32_t low{ static_cast<uint32_t>( hash ) };
|
||||
const uint32_t high{ static_cast<uint32_t>( hash >> 32 ) };
|
||||
return hash_t{ low * high };
|
||||
}
|
||||
private:
|
||||
hash_t m_seed;
|
||||
};
|
||||
} // end unnamed namespace
|
||||
|
||||
|
@ -58,9 +61,9 @@ namespace Catch {
|
|||
|
||||
case RunTests::InRandomOrder: {
|
||||
seedRng( config );
|
||||
TestHasher h( rng() );
|
||||
TestHasher h{ config.rngSeed() };
|
||||
|
||||
using hashedTest = std::pair<uint64_t, TestCase const*>;
|
||||
using hashedTest = std::pair<TestHasher::hash_t, TestCase const*>;
|
||||
std::vector<hashedTest> indexed_tests;
|
||||
indexed_tests.reserve( unsortedTestCases.size() );
|
||||
|
||||
|
|
Loading…
Reference in New Issue