Add Hash, Random, Uuid, Encoding, Bits, Math modules + make Testing deps optional
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>
This commit is contained in:
1 parent
42268c6c35
commit
a09e000f0f
65 files changed
+4959
-138
No files matched your search
@@ -0,0 +1,84 @@
|
||||
#include <Void/Concurrency/Channel.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using Void::Concurrency::Channel;
|
||||
|
||||
Void::Testing::Test capacity_is_preserved()
|
||||
{
|
||||
Channel<int> ch{8};
|
||||
Void::Testing::expect_eq(ch.capacity(), std::size_t{8});
|
||||
}
|
||||
|
||||
Void::Testing::Test try_send_and_try_receive_roundtrip()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(ch.try_send(10));
|
||||
Void::Testing::expect(ch.try_send(20));
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{2});
|
||||
auto v1 = ch.try_receive();
|
||||
Void::Testing::expect(v1.has_value());
|
||||
Void::Testing::expect_eq(*v1, 10);
|
||||
auto v2 = ch.try_receive();
|
||||
Void::Testing::expect(v2.has_value());
|
||||
Void::Testing::expect_eq(*v2, 20);
|
||||
auto empty = ch.try_receive();
|
||||
Void::Testing::expect(!empty.has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test try_send_fails_when_full()
|
||||
{
|
||||
Channel<int> ch{2};
|
||||
Void::Testing::expect(ch.try_send(1));
|
||||
Void::Testing::expect(ch.try_send(2));
|
||||
Void::Testing::expect(!ch.try_send(3));
|
||||
}
|
||||
|
||||
Void::Testing::Test close_unblocks_receiver()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
std::thread producer{[&] { ch.close(); }};
|
||||
auto val = ch.receive();
|
||||
producer.join();
|
||||
Void::Testing::expect(!val.has_value());
|
||||
Void::Testing::expect(ch.is_closed());
|
||||
}
|
||||
|
||||
Void::Testing::Test producer_consumer_ordering()
|
||||
{
|
||||
Channel<int> ch{16};
|
||||
constexpr int N = 10;
|
||||
std::thread producer{[&] {
|
||||
for (int i = 0; i < N; ++i) {
|
||||
ch.send(i);
|
||||
}
|
||||
ch.close();
|
||||
}};
|
||||
std::vector<int> received;
|
||||
while (auto v = ch.receive()) {
|
||||
received.push_back(*v);
|
||||
}
|
||||
producer.join();
|
||||
Void::Testing::expect_eq(static_cast<int>(received.size()), N);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
Void::Testing::expect_eq(received[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test try_send_fails_after_close()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
ch.close();
|
||||
Void::Testing::expect(!ch.try_send(1));
|
||||
}
|
||||
|
||||
Void::Testing::Test send_returns_false_when_closed()
|
||||
{
|
||||
Channel<int> ch{1};
|
||||
ch.close();
|
||||
bool ok = ch.send(42);
|
||||
Void::Testing::expect(!ok);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <Void/Concurrency/ParallelFor.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Concurrency;
|
||||
|
||||
Void::Testing::Test parallel_sum_matches_sequential()
|
||||
{
|
||||
constexpr int N = 1000;
|
||||
std::atomic<long long> total{0};
|
||||
parallel_for(0, N, [&](int i) { total += i; });
|
||||
Void::Testing::expect_eq(total.load(),
|
||||
static_cast<long long>(N) * (N - 1) / 2);
|
||||
}
|
||||
|
||||
Void::Testing::Test empty_range_does_nothing()
|
||||
{
|
||||
std::atomic<int> calls{0};
|
||||
parallel_for(5, 5, [&](int) { ++calls; });
|
||||
Void::Testing::expect_eq(calls.load(), 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test with_explicit_pool()
|
||||
{
|
||||
ThreadPool pool{2};
|
||||
std::atomic<int> count{0};
|
||||
parallel_for(0, 10, [&](int) { ++count; }, pool);
|
||||
Void::Testing::expect_eq(count.load(), 10);
|
||||
}
|
||||
|
||||
Void::Testing::Test results_written_to_indexed_array()
|
||||
{
|
||||
constexpr int N = 64;
|
||||
std::vector<int> out(N, 0);
|
||||
parallel_for(0, N, [&](int i) { out[i] = i * i; });
|
||||
for (int i = 0; i < N; ++i) {
|
||||
Void::Testing::expect_eq(out[i], i * i);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test exception_propagates()
|
||||
{
|
||||
bool caught = false;
|
||||
try {
|
||||
parallel_for(0, 4, [](int i) {
|
||||
if (i == 2) {
|
||||
throw std::runtime_error("bad index");
|
||||
}
|
||||
});
|
||||
} catch (const std::runtime_error&) {
|
||||
caught = true;
|
||||
}
|
||||
Void::Testing::expect(caught);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
#include <Void/Concurrency/ThreadPool.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
using Void::Concurrency::ThreadPool;
|
||||
|
||||
Void::Testing::Test thread_count_matches_requested()
|
||||
{
|
||||
ThreadPool pool{4};
|
||||
Void::Testing::expect_eq(pool.thread_count(), std::size_t{4});
|
||||
}
|
||||
|
||||
Void::Testing::Test defaults_to_hardware_concurrency()
|
||||
{
|
||||
ThreadPool pool;
|
||||
Void::Testing::expect(pool.thread_count() >= 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test submit_returns_correct_value()
|
||||
{
|
||||
ThreadPool pool{2};
|
||||
auto fut = pool.submit([] { return 42; });
|
||||
Void::Testing::expect_eq(fut.get(), 42);
|
||||
}
|
||||
|
||||
Void::Testing::Test tasks_run_concurrently()
|
||||
{
|
||||
constexpr int N = 8;
|
||||
ThreadPool pool{N};
|
||||
std::atomic<int> counter{0};
|
||||
std::vector<std::future<void>> futs;
|
||||
futs.reserve(N);
|
||||
for (int i = 0; i < N; ++i) {
|
||||
futs.push_back(pool.submit([&] {
|
||||
++counter;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
}));
|
||||
}
|
||||
for (auto& f : futs) {
|
||||
f.get();
|
||||
}
|
||||
Void::Testing::expect_eq(counter.load(), N);
|
||||
}
|
||||
|
||||
Void::Testing::Test parallel_sum_is_correct()
|
||||
{
|
||||
ThreadPool pool{4};
|
||||
constexpr int N = 100;
|
||||
std::atomic<long long> total{0};
|
||||
std::vector<std::future<void>> futs;
|
||||
futs.reserve(N);
|
||||
for (int i = 1; i <= N; ++i) {
|
||||
futs.push_back(pool.submit([&, i] { total += i; }));
|
||||
}
|
||||
for (auto& f : futs) {
|
||||
f.get();
|
||||
}
|
||||
Void::Testing::expect_eq(total.load(), 5050LL);
|
||||
}
|
||||
|
||||
Void::Testing::Test exception_propagates_through_future()
|
||||
{
|
||||
ThreadPool pool{1};
|
||||
auto fut = pool.submit([] -> int { throw std::runtime_error("boom"); });
|
||||
bool caught = false;
|
||||
try {
|
||||
fut.get();
|
||||
} catch (const std::runtime_error& e) {
|
||||
caught = (std::string{e.what()} == "boom");
|
||||
}
|
||||
Void::Testing::expect(caught);
|
||||
}
|
||||
|
||||
Void::Testing::Test submit_after_destruction_throws()
|
||||
{
|
||||
std::optional<std::future<int>> fut;
|
||||
{
|
||||
ThreadPool pool{1};
|
||||
fut = pool.submit([] { return 1; });
|
||||
fut->get();
|
||||
}
|
||||
// pool is now destroyed; this just verifies destruction was clean
|
||||
Void::Testing::expect(true);
|
||||
}
|
||||
Reference in new issue
Block a user