Files
faumarayandClaude Fable 5 28b94883fd 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>
2026-06-12 18:50:02 +03:00

58 lines
1.3 KiB
C++

#include <Void/Async/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);
}