Files
Library/tests/standalone/Concurrency/ParallelFor.cpp
T
faumarayandClaude Sonnet 4.6 a09e000f0f 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>
2026-05-14 21:52:22 +03:00

58 lines
1.3 KiB
C++

#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);
}