catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Modified hash to make it more independent of the choice of test names.
- Commit
3ba745552bd26cbbb7c271720c0ec9eaaf1dc8dd- Author
- Sergio Losilla ·
- Committer
- Martin Hořeňovský
- Parents
ff349a50bfc6
Changes
include/internal/catch_test_case_registry_impl.cpp | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp index b337ee3e..0fc3e8be 100644 --- a/include/internal/catch_test_case_registry_impl.cpp +++ b/include/internal/catch_test_case_registry_impl.cpp @@ -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; - uint64_t basis; + explicit TestHasher(hash_t seed): m_seed{seed} { + } - uint64_t operator()(TestCase const& t) const { - // Modified FNV-1a hash - static constexpr uint64_t prime = 1099511628211; - uint64_t hash = basis; - for (const char c : t.name) { + 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() );