Restructure into umbrella modules (~55 -> 16 targets)

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>
This commit is contained in:
faumarayandClaude Fable 5 committed 2026-06-12 18:50:02 +03:00
1 parent da2e93c405
commit 28b94883fd
156 files changed
+278 -220

No files matched your search

+167
View File
@@ -0,0 +1,167 @@
#include <Void/Math/Histogram.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <vector>
using namespace Void::Histogram;
// ── Histogram<K> ──────────────────────────────────────────────────────────────
Void::Testing::Test histogram_add_and_count()
{
Histogram<std::string> h;
h.add("a");
h.add("a");
h.add("b");
Void::Testing::expect_eq(h.count("a"), std::size_t{2});
Void::Testing::expect_eq(h.count("b"), std::size_t{1});
Void::Testing::expect_eq(h.count("c"), std::size_t{0});
}
Void::Testing::Test histogram_total_and_distinct()
{
Histogram<int> h;
h.add(1); h.add(2); h.add(1); h.add(3);
Void::Testing::expect_eq(h.total(), std::size_t{4});
Void::Testing::expect_eq(h.distinct(), std::size_t{3});
}
Void::Testing::Test histogram_add_with_count()
{
Histogram<std::string> h;
h.add("x", 5);
Void::Testing::expect_eq(h.count("x"), std::size_t{5});
Void::Testing::expect_eq(h.total(), std::size_t{5});
}
Void::Testing::Test histogram_frequency()
{
Histogram<int> h;
h.add(1, 3);
h.add(2, 1);
const double f = h.frequency(1);
Void::Testing::expect(f > 0.74 && f < 0.76); // 3/4
}
Void::Testing::Test histogram_mode()
{
Histogram<std::string> h;
h.add("a", 3);
h.add("b", 5);
h.add("c", 1);
const auto m = h.mode();
Void::Testing::expect(m.has_value());
Void::Testing::expect_eq(*m, std::string{"b"});
}
Void::Testing::Test histogram_least_common()
{
Histogram<int> h;
h.add(1, 10);
h.add(2, 1);
h.add(3, 5);
const auto lc = h.least_common();
Void::Testing::expect(lc.has_value());
Void::Testing::expect_eq(*lc, 2);
}
Void::Testing::Test histogram_mode_empty_returns_nullopt()
{
Histogram<int> h;
Void::Testing::expect(!h.mode().has_value());
}
Void::Testing::Test histogram_top_k()
{
Histogram<int> h;
h.add(1, 3);
h.add(2, 10);
h.add(3, 5);
h.add(4, 1);
const auto top = h.top_k(2);
Void::Testing::expect_eq(top.size(), std::size_t{2});
Void::Testing::expect_eq(top[0].first, 2); // highest count first
Void::Testing::expect_eq(top[0].second, std::size_t{10});
}
Void::Testing::Test histogram_erase()
{
Histogram<int> h;
h.add(1, 5);
h.add(2, 3);
Void::Testing::expect(h.erase(1));
Void::Testing::expect(!h.contains(1));
Void::Testing::expect_eq(h.total(), std::size_t{3});
Void::Testing::expect(!h.erase(99));
}
Void::Testing::Test histogram_clear()
{
Histogram<int> h;
h.add(1); h.add(2);
h.clear();
Void::Testing::expect(h.empty());
Void::Testing::expect_eq(h.total(), std::size_t{0});
}
Void::Testing::Test histogram_merge()
{
Histogram<std::string> a, b;
a.add("x", 3);
b.add("x", 2);
b.add("y", 1);
a.merge(b);
Void::Testing::expect_eq(a.count("x"), std::size_t{5});
Void::Testing::expect_eq(a.count("y"), std::size_t{1});
Void::Testing::expect_eq(a.total(), std::size_t{6});
}
// ── FixedBinHistogram ─────────────────────────────────────────────────────────
Void::Testing::Test fixed_bin_basic_add()
{
FixedBinHistogram h{0.0, 10.0, 10};
h.add(0.5); // bin 0
h.add(1.5); // bin 1
h.add(9.9); // bin 9
Void::Testing::expect_eq(h.bin_count(0), std::size_t{1});
Void::Testing::expect_eq(h.bin_count(1), std::size_t{1});
Void::Testing::expect_eq(h.bin_count(9), std::size_t{1});
Void::Testing::expect_eq(h.total(), std::size_t{3});
}
Void::Testing::Test fixed_bin_clamping()
{
FixedBinHistogram h{0.0, 5.0, 5};
h.add(-1.0); // clamp to bin 0
h.add(10.0); // clamp to last bin
Void::Testing::expect_eq(h.bin_count(0), std::size_t{1});
Void::Testing::expect_eq(h.bin_count(4), std::size_t{1});
}
Void::Testing::Test fixed_bin_width()
{
FixedBinHistogram h{0.0, 10.0, 5};
Void::Testing::expect(h.width() > 1.99 && h.width() < 2.01);
}
Void::Testing::Test fixed_bin_invalid_args()
{
bool threw = false;
try { FixedBinHistogram h{5.0, 3.0, 4}; } catch (...) { threw = true; }
Void::Testing::expect(threw);
threw = false;
try { FixedBinHistogram h{0.0, 10.0, 0}; } catch (...) { threw = true; }
Void::Testing::expect(threw);
}
Void::Testing::Test fixed_bin_clear()
{
FixedBinHistogram h{0.0, 10.0, 5};
h.add(1.0); h.add(5.0);
h.clear();
Void::Testing::expect_eq(h.total(), std::size_t{0});
Void::Testing::expect_eq(h.bin_count(0), std::size_t{0});
}
+217
View File
@@ -0,0 +1,217 @@
#include <Void/Math/Matrix.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
using namespace Void::Matrix;
// ── construction ──────────────────────────────────────────────────────────────
Void::Testing::Test matrix_default_zeros()
{
const Mat2<int> m;
Void::Testing::expect_eq(m(0, 0), 0);
Void::Testing::expect_eq(m(1, 1), 0);
}
Void::Testing::Test matrix_fill_constructor()
{
const Matrix<int, 3, 3> m{5};
Void::Testing::expect_eq(m(0, 0), 5);
Void::Testing::expect_eq(m(2, 2), 5);
}
Void::Testing::Test matrix_array_init()
{
const Mat2<int> m{{1, 2, 3, 4}};
Void::Testing::expect_eq(m(0, 0), 1);
Void::Testing::expect_eq(m(0, 1), 2);
Void::Testing::expect_eq(m(1, 0), 3);
Void::Testing::expect_eq(m(1, 1), 4);
}
Void::Testing::Test matrix_identity_factory()
{
const auto id = Mat3<int>::identity();
Void::Testing::expect_eq(id(0, 0), 1);
Void::Testing::expect_eq(id(1, 1), 1);
Void::Testing::expect_eq(id(2, 2), 1);
Void::Testing::expect_eq(id(0, 1), 0);
Void::Testing::expect_eq(id(1, 0), 0);
}
Void::Testing::Test matrix_at_out_of_range()
{
const Mat2<int> m;
bool threw = false;
try { [[maybe_unused]] auto v = m.at(5, 0); } catch (...) { threw = true; }
Void::Testing::expect(threw);
}
// ── arithmetic ────────────────────────────────────────────────────────────────
Void::Testing::Test matrix_add()
{
const Mat2<int> a{{1, 2, 3, 4}};
const Mat2<int> b{{5, 6, 7, 8}};
const auto c = a + b;
Void::Testing::expect_eq(c(0, 0), 6);
Void::Testing::expect_eq(c(1, 1), 12);
}
Void::Testing::Test matrix_subtract()
{
const Mat2<int> a{{10, 8, 6, 4}};
const Mat2<int> b{{1, 2, 3, 4}};
const auto c = a - b;
Void::Testing::expect_eq(c(0, 0), 9);
Void::Testing::expect_eq(c(1, 0), 3);
}
Void::Testing::Test matrix_scalar_mul()
{
const Mat2<int> m{{1, 2, 3, 4}};
const auto r = m * 3;
Void::Testing::expect_eq(r(0, 0), 3);
Void::Testing::expect_eq(r(1, 1), 12);
}
Void::Testing::Test matrix_scalar_mul_left()
{
const Mat2<int> m{{1, 2, 3, 4}};
const auto r = 2 * m;
Void::Testing::expect_eq(r(0, 1), 4);
}
Void::Testing::Test matrix_negate()
{
const Mat2<int> m{{1, -2, 3, -4}};
const auto n = -m;
Void::Testing::expect_eq(n(0, 0), -1);
Void::Testing::expect_eq(n(0, 1), 2);
}
Void::Testing::Test matrix_mul_identity()
{
const Mat2<int> m{{1, 2, 3, 4}};
const auto id = Mat2<int>::identity();
const auto result = m * id;
Void::Testing::expect_eq(result, m);
}
Void::Testing::Test matrix_mul_2x2()
{
// [1 2] * [5 6] = [1*5+2*7 1*6+2*8] = [19 22]
// [3 4] [7 8] [3*5+4*7 3*6+4*8] [43 50]
const Mat2<int> a{{1, 2, 3, 4}};
const Mat2<int> b{{5, 6, 7, 8}};
const auto c = a * b;
Void::Testing::expect_eq(c(0, 0), 19);
Void::Testing::expect_eq(c(0, 1), 22);
Void::Testing::expect_eq(c(1, 0), 43);
Void::Testing::expect_eq(c(1, 1), 50);
}
Void::Testing::Test matrix_mul_non_square()
{
// [1 2 3] (1×3) * [1] (3×1) = [1+4+9] = [14] (1×1)
// [2]
// [3]
Matrix<int, 1, 3> row{{1, 2, 3}};
Matrix<int, 3, 1> col{{1, 2, 3}};
const auto r = row * col;
Void::Testing::expect_eq(r(0, 0), 14);
}
// ── transpose ─────────────────────────────────────────────────────────────────
Void::Testing::Test matrix_transpose()
{
const Mat2<int> m{{1, 2, 3, 4}};
const auto t = m.transposed();
Void::Testing::expect_eq(t(0, 0), 1);
Void::Testing::expect_eq(t(0, 1), 3);
Void::Testing::expect_eq(t(1, 0), 2);
Void::Testing::expect_eq(t(1, 1), 4);
}
Void::Testing::Test matrix_transpose_non_square()
{
Matrix<int, 2, 3> m{{1, 2, 3, 4, 5, 6}};
const auto t = m.transposed();
static_assert(decltype(t)::rows == 3 && decltype(t)::cols == 2);
Void::Testing::expect_eq(t(0, 0), 1);
Void::Testing::expect_eq(t(2, 0), 3);
Void::Testing::expect_eq(t(0, 1), 4);
}
// ── aggregates ────────────────────────────────────────────────────────────────
Void::Testing::Test matrix_sum()
{
const Mat2<int> m{{1, 2, 3, 4}};
Void::Testing::expect_eq(m.sum(), 10);
}
Void::Testing::Test matrix_trace()
{
const Mat3<int> m{{1, 0, 0,
0, 2, 0,
0, 0, 3}};
Void::Testing::expect_eq(m.trace(), 6);
}
// ── determinant ───────────────────────────────────────────────────────────────
Void::Testing::Test matrix_det_2x2()
{
const Mat2<int> m{{1, 2, 3, 4}};
Void::Testing::expect_eq(det(m), -2); // 1*4 - 2*3
}
Void::Testing::Test matrix_det_3x3()
{
const Mat3<int> m{{1, 2, 3,
4, 5, 6,
7, 8, 9}};
Void::Testing::expect_eq(det(m), 0); // singular
}
// ── inverse ───────────────────────────────────────────────────────────────────
Void::Testing::Test matrix_inverse_2x2()
{
const Mat2<double> m{{1.0, 2.0, 3.0, 4.0}};
const auto inv = inverse(m);
Void::Testing::expect(inv.has_value());
// m * inv should equal identity
const auto prod = m * *inv;
Void::Testing::expect(prod(0, 0) > 0.999 && prod(0, 0) < 1.001);
Void::Testing::expect(prod(1, 1) > 0.999 && prod(1, 1) < 1.001);
Void::Testing::expect(prod(0, 1) > -0.001 && prod(0, 1) < 0.001);
}
Void::Testing::Test matrix_inverse_singular_returns_nullopt()
{
const Mat2<double> m{{1.0, 2.0, 2.0, 4.0}}; // det = 0
Void::Testing::expect(!inverse(m).has_value());
}
// ── dot product ───────────────────────────────────────────────────────────────
Void::Testing::Test matrix_dot_product()
{
Vec3<int> a{{1, 2, 3}};
Vec3<int> b{{4, 5, 6}};
Void::Testing::expect_eq(dot(a, b), 32); // 4+10+18
}
// ── equality ──────────────────────────────────────────────────────────────────
Void::Testing::Test matrix_equality()
{
const Mat2<int> a{{1, 2, 3, 4}};
const Mat2<int> b{{1, 2, 3, 4}};
const Mat2<int> c{{1, 2, 3, 5}};
Void::Testing::expect(a == b);
Void::Testing::expect(a != c);
}
+192
View File
@@ -0,0 +1,192 @@
#include <Void/Math/Numeric.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <cstdint>
#include <limits>
// ── checked_add ───────────────────────────────────────────────────────────────
Void::Testing::Test checked_add_ok()
{
const auto r = Void::Numeric::checked_add(3, 4);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 7);
}
Void::Testing::Test checked_add_overflow()
{
const auto r = Void::Numeric::checked_add(
std::numeric_limits<int>::max(), 1);
Void::Testing::expect(!r.has_value());
Void::Testing::expect(r.error() == Void::Numeric::Error::Overflow);
}
Void::Testing::Test checked_add_underflow()
{
const auto r = Void::Numeric::checked_add(
std::numeric_limits<int>::min(), -1);
Void::Testing::expect(!r.has_value());
Void::Testing::expect(r.error() == Void::Numeric::Error::Underflow);
}
// ── checked_sub ───────────────────────────────────────────────────────────────
Void::Testing::Test checked_sub_ok()
{
const auto r = Void::Numeric::checked_sub(10, 3);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 7);
}
Void::Testing::Test checked_sub_underflow()
{
const auto r = Void::Numeric::checked_sub(
std::numeric_limits<int>::min(), 1);
Void::Testing::expect(!r.has_value());
}
// ── checked_mul ───────────────────────────────────────────────────────────────
Void::Testing::Test checked_mul_ok()
{
const auto r = Void::Numeric::checked_mul(6, 7);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 42);
}
Void::Testing::Test checked_mul_overflow()
{
const auto r = Void::Numeric::checked_mul(
std::numeric_limits<int>::max(), 2);
Void::Testing::expect(!r.has_value());
Void::Testing::expect(r.error() == Void::Numeric::Error::Overflow);
}
// ── checked_div ───────────────────────────────────────────────────────────────
Void::Testing::Test checked_div_ok()
{
const auto r = Void::Numeric::checked_div(10, 2);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 5);
}
Void::Testing::Test checked_div_by_zero()
{
const auto r = Void::Numeric::checked_div(10, 0);
Void::Testing::expect(!r.has_value());
Void::Testing::expect(r.error() == Void::Numeric::Error::DivisionByZero);
}
Void::Testing::Test checked_div_min_by_neg1()
{
const auto r = Void::Numeric::checked_div(
std::numeric_limits<int>::min(), -1);
Void::Testing::expect(!r.has_value());
}
// ── saturating_add ────────────────────────────────────────────────────────────
Void::Testing::Test saturating_add_no_overflow()
{
Void::Testing::expect_eq(Void::Numeric::saturating_add(3, 4), 7);
}
Void::Testing::Test saturating_add_clamps_at_max()
{
Void::Testing::expect_eq(
Void::Numeric::saturating_add(std::numeric_limits<int>::max(), 1),
std::numeric_limits<int>::max());
}
// ── saturating_sub ────────────────────────────────────────────────────────────
Void::Testing::Test saturating_sub_clamps_at_min()
{
Void::Testing::expect_eq(
Void::Numeric::saturating_sub(std::numeric_limits<int>::min(), 1),
std::numeric_limits<int>::min());
}
// ── wrapping_add ──────────────────────────────────────────────────────────────
Void::Testing::Test wrapping_add_wraps()
{
const std::uint8_t r = Void::Numeric::wrapping_add(
std::uint8_t{255}, std::uint8_t{1});
Void::Testing::expect_eq(r, std::uint8_t{0});
}
// ── clamp ────────────────────────────────────────────────────────────────────
Void::Testing::Test clamp_in_range()
{
Void::Testing::expect_eq(Void::Numeric::clamp(5, 0, 10), 5);
}
Void::Testing::Test clamp_at_lo()
{
Void::Testing::expect_eq(Void::Numeric::clamp(-5, 0, 10), 0);
}
Void::Testing::Test clamp_at_hi()
{
Void::Testing::expect_eq(Void::Numeric::clamp(15, 0, 10), 10);
}
// ── parse_int ─────────────────────────────────────────────────────────────────
Void::Testing::Test parse_int_valid()
{
const auto r = Void::Numeric::parse_int("42");
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 42);
}
Void::Testing::Test parse_int_negative()
{
const auto r = Void::Numeric::parse_int("-7");
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, -7);
}
Void::Testing::Test parse_int_invalid()
{
Void::Testing::expect(!Void::Numeric::parse_int("abc").has_value());
}
Void::Testing::Test parse_int_hex()
{
const auto r = Void::Numeric::parse_int("ff", 16);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 255);
}
// ── parse_double ─────────────────────────────────────────────────────────────
Void::Testing::Test parse_double_valid()
{
const auto r = Void::Numeric::parse_double("3.14");
Void::Testing::expect(r.has_value());
Void::Testing::expect((*r) > 3.13 && (*r) < 3.15);
}
Void::Testing::Test parse_double_invalid()
{
Void::Testing::expect(!Void::Numeric::parse_double("xyz").has_value());
}
// ── narrow_cast ──────────────────────────────────────────────────────────────
Void::Testing::Test narrow_cast_in_range()
{
const auto r = Void::Numeric::narrow_cast<std::int8_t>(42LL);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, std::int8_t{42});
}
Void::Testing::Test narrow_cast_out_of_range()
{
Void::Testing::expect(!Void::Numeric::narrow_cast<std::int8_t>(500LL).has_value());
}
+120
View File
@@ -0,0 +1,120 @@
#include <Void/Math/Random.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <algorithm>
#include <vector>
// ── Xoshiro256 ───────────────────────────────────────────────────────────────
Void::Testing::Test xoshiro_produces_output()
{
Void::Random::Xoshiro256 rng{42};
const auto a = rng();
const auto b = rng();
Void::Testing::expect(a != b);
}
Void::Testing::Test xoshiro_same_seed_same_sequence()
{
Void::Random::Xoshiro256 r1{12345};
Void::Random::Xoshiro256 r2{12345};
for (int i = 0; i < 10; ++i) {
Void::Testing::expect_eq(r1(), r2());
}
}
Void::Testing::Test xoshiro_different_seeds_differ()
{
Void::Random::Xoshiro256 r1{1};
Void::Random::Xoshiro256 r2{2};
Void::Testing::expect(r1() != r2());
}
// ── uniform_int ──────────────────────────────────────────────────────────────
Void::Testing::Test uniform_int_in_range()
{
for (int i = 0; i < 100; ++i) {
const auto v = Void::Random::uniform_int(1, 6);
Void::Testing::expect(v >= 1);
Void::Testing::expect(v <= 6);
}
}
Void::Testing::Test uniform_int_single_value()
{
Void::Testing::expect_eq(Void::Random::uniform_int(7, 7), 7);
}
// ── uniform_real ─────────────────────────────────────────────────────────────
Void::Testing::Test uniform_real_in_range()
{
for (int i = 0; i < 50; ++i) {
const double v = Void::Random::uniform_real(0.0, 1.0);
Void::Testing::expect(v >= 0.0);
Void::Testing::expect(v < 1.0);
}
}
// ── coin_flip ────────────────────────────────────────────────────────────────
Void::Testing::Test coin_flip_always_true()
{
Void::Testing::expect(Void::Random::coin_flip(1.0));
}
Void::Testing::Test coin_flip_always_false()
{
Void::Testing::expect(!Void::Random::coin_flip(0.0));
}
// ── shuffle ──────────────────────────────────────────────────────────────────
Void::Testing::Test shuffle_preserves_elements()
{
std::vector<int> v{1, 2, 3, 4, 5};
const auto orig = v;
Void::Random::shuffle(v);
auto sorted = v;
std::sort(sorted.begin(), sorted.end());
Void::Testing::expect_eq(sorted, orig);
}
// ── random_string ────────────────────────────────────────────────────────────
Void::Testing::Test random_string_correct_length()
{
Void::Testing::expect_eq(Void::Random::random_string(10).size(),
std::size_t{10});
}
Void::Testing::Test random_string_empty()
{
Void::Testing::expect(Void::Random::random_string(0).empty());
}
Void::Testing::Test random_string_varies()
{
// Extremely unlikely to produce identical 16-char strings twice
const auto a = Void::Random::random_string(16);
const auto b = Void::Random::random_string(16);
Void::Testing::expect(a != b);
}
// ── sample_indices ───────────────────────────────────────────────────────────
Void::Testing::Test sample_indices_correct_count()
{
const auto idxs = Void::Random::sample_indices(20, 5);
Void::Testing::expect_eq(idxs.size(), std::size_t{5});
}
Void::Testing::Test sample_indices_in_range()
{
const auto idxs = Void::Random::sample_indices(10, 10);
for (auto i : idxs) {
Void::Testing::expect(i < std::size_t{10});
}
}