Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
122 lines
4.2 KiB
C++
122 lines
4.2 KiB
C++
#include <Void/Core/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"));
|
|
}
|