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
@@ -0,0 +1,139 @@
|
||||
#include <Void/Time/Stopwatch.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace Void::Time;
|
||||
using Duration = Void::Time::Stopwatch::Duration;
|
||||
|
||||
// ── Stopwatch ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test stopwatch_not_running_initially()
|
||||
{
|
||||
Stopwatch sw;
|
||||
Void::Testing::expect(!sw.is_running());
|
||||
Void::Testing::expect_eq(sw.elapsed(), Duration::zero());
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_start_sets_running()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
Void::Testing::expect(sw.is_running());
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_increases_while_running()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
const auto first = sw.elapsed();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const auto second = sw.elapsed();
|
||||
Void::Testing::expect(second > first);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_stop_returns_elapsed()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const Duration d = sw.stop();
|
||||
Void::Testing::expect(!sw.is_running());
|
||||
Void::Testing::expect(d.count() > 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_ms()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.stop();
|
||||
Void::Testing::expect(sw.elapsed_ms() >= 4.0);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_lap_count()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.lap();
|
||||
sw.lap();
|
||||
Void::Testing::expect_eq(sw.lap_count(), std::size_t{3});
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_lap_durations_sum_to_elapsed()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{2});
|
||||
sw.lap();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{2});
|
||||
sw.lap();
|
||||
const Duration total = sw.stop();
|
||||
|
||||
Duration lap_sum{};
|
||||
for (const auto& l : sw.laps()) lap_sum += l;
|
||||
// Lap sum should be close to total (within 1ms tolerance)
|
||||
const auto diff = total - lap_sum;
|
||||
Void::Testing::expect(diff.count() < 1'000'000); // < 1 ms
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_reset_clears_state()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.stop();
|
||||
sw.reset();
|
||||
Void::Testing::expect(!sw.is_running());
|
||||
Void::Testing::expect_eq(sw.elapsed(), Duration::zero());
|
||||
Void::Testing::expect_eq(sw.lap_count(), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_restart_clears_laps()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
sw.lap();
|
||||
sw.stop();
|
||||
sw.start(); // restart
|
||||
Void::Testing::expect_eq(sw.lap_count(), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_stopped_elapsed_does_not_grow()
|
||||
{
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.stop();
|
||||
const Duration d1 = sw.elapsed();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const Duration d2 = sw.elapsed();
|
||||
Void::Testing::expect_eq(d1, d2);
|
||||
}
|
||||
|
||||
// ── ScopedTimer ───────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test scoped_timer_records_elapsed()
|
||||
{
|
||||
Duration d{};
|
||||
{
|
||||
ScopedTimer t{d};
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
}
|
||||
Void::Testing::expect(d.count() > 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test scoped_timer_written_on_destruction()
|
||||
{
|
||||
Duration d{};
|
||||
d = Duration::zero();
|
||||
{
|
||||
ScopedTimer t{d};
|
||||
// do nothing
|
||||
}
|
||||
Void::Testing::expect(d != Duration::zero() || d == Duration::zero()); // always true: just verifies it compiles
|
||||
(void)d;
|
||||
Void::Testing::expect(true); // ScopedTimer destructor ran without error
|
||||
}
|
||||
@@ -11,36 +11,36 @@
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_is_non_negative()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
Void::Testing::expect(sw.elapsed().count() >= 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_elapsed_as_milliseconds()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const auto ms = sw.elapsed_as<std::chrono::milliseconds>().count();
|
||||
Void::Testing::expect(ms >= 4);
|
||||
Void::Testing::expect(ms < 500);
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_reset_restarts_from_zero()
|
||||
Void::Testing::Test stopwatch_restart_starts_from_zero()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
sw.reset();
|
||||
sw.start();
|
||||
const auto ns = sw.elapsed().count();
|
||||
Void::Testing::expect(ns < 5'000'000); // < 5ms since reset
|
||||
Void::Testing::expect(ns < 5'000'000); // < 5ms since restart
|
||||
}
|
||||
|
||||
Void::Testing::Test stopwatch_split_returns_elapsed_and_resets()
|
||||
Void::Testing::Test stopwatch_split_returns_elapsed_and_restarts()
|
||||
{
|
||||
Void::Time::Stopwatch sw;
|
||||
auto sw = Void::Time::Stopwatch::started();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
const auto d = sw.split();
|
||||
const auto after = sw.elapsed().count();
|
||||
Void::Testing::expect(d.count() >= 0);
|
||||
Void::Testing::expect(after < d.count()); // after reset < before reset
|
||||
Void::Testing::expect(after < d.count()); // after restart < before
|
||||
}
|
||||
|
||||
// ── format_duration ───────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user