New header-only modules: - Void::Hash — FNV-1a 32/64, CRC-32, DJB2, MurmurHash3-32, UDL literals - Void::Random — Xoshiro256** PRNG, uniform_int/real, coin_flip, shuffle, random_string - Void::Uuid — v4 (random), v5_lite (name-based), parse, RFC 4122 namespaces - Void::Encoding — Base64 (standard + URL-safe), Hex encode/decode - Void::Bits — popcount, bit extract/deposit, rotation, align, byteswap, masks - Void::Math — Vec2/Vec3/Vec4, Mat4 (identity, translation, scale, rotation) Testing module: move Stacktrace from INTERNAL_DEPS to OPTIONAL_DEPS. Added Detail/Color.hpp shim that delegates to Stacktrace::Color when present or provides inline ANSI fallback otherwise. All Stacktrace calls in SignalHandler, ConsoleReporter, and Runner are gated on VOID_HAS_STACKTRACE. Fix Repr.hpp reflect_struct to handle template specializations that lack std::meta::identifier_of (now guarded by has_identifier check). 33/33 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
122 lines
4.2 KiB
C++
122 lines
4.2 KiB
C++
#include <Void/Hash/Hash.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
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<std::uint64_t>(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"));
|
|
}
|