Finish module consolidation: fold Memo into Pipeline, dedupe Channel/Stopwatch
Completes the in-progress merges (Optional->Either/Opt, Curry+Memo->Pipeline,
ScopeGuard->Scope, String->Str):
- Pipeline/Memo.hpp now carries the full Memo API (memoize with recursion
support, TupleHash, SimpleCache) alongside memoize_fn; old Memo module
and its test dir removed.
- Duplicate Channel module removed; Concurrency::Channel gains empty() and
the unique test cases (drain-after-close, multi-producer, string payloads).
- StopWatch module merged into Time::Stopwatch: one class with explicit
start/stop/laps plus a started() factory for the auto-start RAII style;
ScopedTimer moved along.
- Testing optional dep retargeted String->Str (pad_right lives in Str now).
- Stale empty dirs removed: src/{ScopeGuard,String,Core}, include/Void/{Core,
Filesystem,Memo,Channel,StopWatch}.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58ff7b38a0
commit
da2e93c405
29 files changed
+752
-1593
No files matched your search
@@ -2,6 +2,8 @@
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
@@ -82,3 +84,59 @@ Void::Testing::Test send_returns_false_when_closed()
|
||||
bool ok = ch.send(42);
|
||||
Void::Testing::expect(!ok);
|
||||
}
|
||||
|
||||
Void::Testing::Test size_and_empty()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
Void::Testing::expect(ch.empty());
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{0});
|
||||
ch.try_send(1);
|
||||
ch.try_send(2);
|
||||
Void::Testing::expect_eq(ch.size(), std::size_t{2});
|
||||
Void::Testing::expect(!ch.empty());
|
||||
}
|
||||
|
||||
Void::Testing::Test receive_drains_then_nullopt_after_close()
|
||||
{
|
||||
Channel<int> ch{4};
|
||||
ch.try_send(10);
|
||||
ch.try_send(20);
|
||||
ch.close();
|
||||
Void::Testing::expect_eq(*ch.try_receive(), 10);
|
||||
Void::Testing::expect_eq(*ch.try_receive(), 20);
|
||||
Void::Testing::expect(!ch.try_receive().has_value());
|
||||
}
|
||||
|
||||
Void::Testing::Test multiple_producers_sum()
|
||||
{
|
||||
Channel<int> ch{64};
|
||||
std::atomic<int> total{0};
|
||||
|
||||
auto producer = [&](int n) {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
ch.send(i);
|
||||
}
|
||||
};
|
||||
|
||||
std::thread t1(producer, 5);
|
||||
std::thread t2(producer, 5);
|
||||
t1.join();
|
||||
t2.join();
|
||||
ch.close();
|
||||
|
||||
while (auto v = ch.receive()) {
|
||||
total += *v;
|
||||
}
|
||||
|
||||
// Sum of 0+1+2+3+4 = 10, two producers → 20
|
||||
Void::Testing::expect_eq(total.load(), 20);
|
||||
}
|
||||
|
||||
Void::Testing::Test string_values_roundtrip()
|
||||
{
|
||||
Channel<std::string> ch{4};
|
||||
ch.try_send("hello");
|
||||
ch.try_send("world");
|
||||
Void::Testing::expect_eq(*ch.try_receive(), std::string{"hello"});
|
||||
Void::Testing::expect_eq(*ch.try_receive(), std::string{"world"});
|
||||
}
|
||||
Reference in new issue
Block a user