Add 20+ new modules with tests: Pipeline, Matrix, Tokenizer, ScopeGuard, Bitset, Optional, Counted, Curry, TypeMap, Bench, DisjointSet, Histogram, StopWatch, and more

Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now
an alias for Edit<string> so count_op/apply work on line diffs; Memoized
uses std::apply instead of type-based get to handle duplicate arg types.

874/877 tests pass (3 are platform-gated plugin tests).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 4.6 committed 2026-05-14 23:49:09 +03:00
1 parent cb4dd58500
commit 58ff7b38a0
65 files changed
+8987 -37

No files matched your search

+147
View File
@@ -0,0 +1,147 @@
#include <Void/Variant/Variant.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <variant>
using namespace Void::Variant;
using V3 = std::variant<int, double, std::string>;
// ── match ─────────────────────────────────────────────────────────────────────
Void::Testing::Test variant_match_int()
{
V3 v = 42;
const auto s = match(v,
[](int i) { return std::to_string(i); },
[](double d) { return std::to_string(d); },
[](const std::string& s) { return s; });
Void::Testing::expect_eq(s, std::string{"42"});
}
Void::Testing::Test variant_match_string()
{
V3 v = std::string{"hello"};
bool got_string = false;
match(v,
[](int) {},
[](double) {},
[&](const std::string&) { got_string = true; });
Void::Testing::expect(got_string);
}
Void::Testing::Test variant_match_returns_value()
{
V3 v = 3.14;
const int result = match(v,
[](int i) { return i; },
[](double d) { return static_cast<int>(d); },
[](const std::string&) { return 0; });
Void::Testing::expect_eq(result, 3);
}
// ── overload ──────────────────────────────────────────────────────────────────
Void::Testing::Test variant_overload_helper()
{
V3 v = 99;
const auto visitor = overload{
[](int i) { return i * 2; },
[](double d) { return static_cast<int>(d); },
[](const std::string&) { return -1; }
};
Void::Testing::expect_eq(std::visit(visitor, v), 198);
}
// ── holds ─────────────────────────────────────────────────────────────────────
Void::Testing::Test variant_holds_correct_type()
{
V3 v = 1;
Void::Testing::expect(holds<int>(v));
Void::Testing::expect(!holds<double>(v));
Void::Testing::expect(!holds<std::string>(v));
}
Void::Testing::Test variant_holds_after_assignment()
{
V3 v = 1;
v = 3.14;
Void::Testing::expect(!holds<int>(v));
Void::Testing::expect(holds<double>(v));
}
// ── get_or ────────────────────────────────────────────────────────────────────
Void::Testing::Test variant_get_or_present()
{
V3 v = 7;
Void::Testing::expect_eq(get_or<int>(v, 0), 7);
}
Void::Testing::Test variant_get_or_absent()
{
V3 v = 3.14;
Void::Testing::expect_eq(get_or<int>(v, -1), -1);
}
// ── try_get ───────────────────────────────────────────────────────────────────
Void::Testing::Test variant_try_get_present()
{
V3 v = std::string{"world"};
const auto r = try_get<std::string>(v);
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, std::string{"world"});
}
Void::Testing::Test variant_try_get_absent()
{
V3 v = 1;
Void::Testing::expect(!try_get<std::string>(v).has_value());
}
// ── index_of ─────────────────────────────────────────────────────────────────
Void::Testing::Test variant_index_of_compile_time()
{
static_assert(index_of<int, V3> == 0);
static_assert(index_of<double, V3> == 1);
static_assert(index_of<std::string, V3> == 2);
Void::Testing::expect(true); // compile-time assertion passed
}
// ── apply_to ─────────────────────────────────────────────────────────────────
Void::Testing::Test variant_apply_to_matching()
{
V3 v = 5;
const auto r = apply_to<int>(v, [](int i) { return i * 10; });
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 50);
}
Void::Testing::Test variant_apply_to_non_matching()
{
V3 v = 3.14;
const auto r = apply_to<int>(v, [](int i) { return i; });
Void::Testing::expect(!r.has_value());
}
// ── narrow ────────────────────────────────────────────────────────────────────
Void::Testing::Test variant_narrow_convertible()
{
V3 v = 7;
const auto r = narrow<double>(v); // int is convertible to double
Void::Testing::expect(r.has_value());
Void::Testing::expect_eq(*r, 7.0);
}
Void::Testing::Test variant_narrow_not_convertible()
{
V3 v = std::string{"x"};
const auto r = narrow<double>(v);
Void::Testing::expect(!r.has_value());
}