#include #include #include #include using namespace Void::Hash::Literals; // ── FNV-1a 32 ──────────────────────────────────────────────────────────────── Void::Testing::Test fnv1a32_empty_string() { Void::Testing::expect_eq(Void::Hash::fnv1a32(""), 2166136261u); } Void::Testing::Test fnv1a32_hello_world() { const auto a = Void::Hash::fnv1a32("hello"); const auto b = Void::Hash::fnv1a32("world"); Void::Testing::expect(a != b); Void::Testing::expect(a != 0u); } Void::Testing::Test fnv1a32_deterministic() { Void::Testing::expect_eq(Void::Hash::fnv1a32("test"), Void::Hash::fnv1a32("test")); } Void::Testing::Test fnv1a32_different_strings_differ() { Void::Testing::expect(Void::Hash::fnv1a32("abc") != Void::Hash::fnv1a32("abd")); } // ── FNV-1a 64 ──────────────────────────────────────────────────────────────── Void::Testing::Test fnv1a64_empty_basis() { Void::Testing::expect_eq(Void::Hash::fnv1a64(""), 14695981039346656037ull); } Void::Testing::Test fnv1a64_hello_is_stable() { Void::Testing::expect_eq(Void::Hash::fnv1a64("hello"), Void::Hash::fnv1a64("hello")); } Void::Testing::Test fnv1a64_wider_than_32() { // 64-bit should differ from 32-bit value for same input Void::Testing::expect(Void::Hash::fnv1a64("test") != static_cast(Void::Hash::fnv1a32("test"))); } // ── CRC-32 ─────────────────────────────────────────────────────────────────── Void::Testing::Test crc32_known_value() { // CRC-32 of "123456789" is a well-known check value: 0xCBF43926 Void::Testing::expect_eq(Void::Hash::crc32("123456789"), std::uint32_t{0xCBF43926u}); } Void::Testing::Test crc32_empty_is_zero() { Void::Testing::expect_eq(Void::Hash::crc32(""), std::uint32_t{0u}); } Void::Testing::Test crc32_deterministic() { Void::Testing::expect_eq(Void::Hash::crc32("void"), Void::Hash::crc32("void")); } // ── DJB2 ───────────────────────────────────────────────────────────────────── Void::Testing::Test djb2_non_zero_for_nonempty() { Void::Testing::expect(Void::Hash::djb2("hello") != 0u); } Void::Testing::Test djb2_differs_per_string() { Void::Testing::expect(Void::Hash::djb2("foo") != Void::Hash::djb2("bar")); } // ── MurmurHash3 ────────────────────────────────────────────────────────────── Void::Testing::Test murmur3_32_deterministic() { Void::Testing::expect_eq(Void::Hash::murmur3_32("hello", 42u), Void::Hash::murmur3_32("hello", 42u)); } Void::Testing::Test murmur3_32_seed_affects_output() { Void::Testing::expect(Void::Hash::murmur3_32("hello", 0u) != Void::Hash::murmur3_32("hello", 1u)); } Void::Testing::Test murmur3_32_empty_with_zero_seed() { // MurmurHash3("", 0) = 0 Void::Testing::expect_eq(Void::Hash::murmur3_32("", 0u), std::uint32_t{0u}); } // ── UDL literals ───────────────────────────────────────────────────────────── Void::Testing::Test udl_fnv32_comptime() { constexpr auto h = "hello"_fnv32; static_assert(h != 0u); Void::Testing::expect_eq(h, Void::Hash::fnv1a32("hello")); } Void::Testing::Test udl_fnv64_comptime() { constexpr auto h = "hello"_fnv64; static_assert(h != 0u); Void::Testing::expect_eq(h, Void::Hash::fnv1a64("hello")); }