#include #include #include #include #include #include #include // ── Stopwatch ───────────────────────────────────────────────────────────── Void::Testing::Test stopwatch_elapsed_is_non_negative() { auto sw = Void::Time::Stopwatch::started(); Void::Testing::expect(sw.elapsed().count() >= 0); } Void::Testing::Test stopwatch_elapsed_as_milliseconds() { auto sw = Void::Time::Stopwatch::started(); std::this_thread::sleep_for(std::chrono::milliseconds{5}); const auto ms = sw.elapsed_as().count(); Void::Testing::expect(ms >= 4); Void::Testing::expect(ms < 500); } Void::Testing::Test stopwatch_restart_starts_from_zero() { auto sw = Void::Time::Stopwatch::started(); std::this_thread::sleep_for(std::chrono::milliseconds{5}); sw.start(); const auto ns = sw.elapsed().count(); Void::Testing::expect(ns < 5'000'000); // < 5ms since restart } Void::Testing::Test stopwatch_split_returns_elapsed_and_restarts() { 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 restart < before } // ── format_duration ─────────────────────────────────────────────────────── Void::Testing::Test format_duration_nanoseconds() { using namespace std::chrono_literals; Void::Testing::expect_eq(Void::Time::format_duration(500ns), std::string{"500ns"}); } Void::Testing::Test format_duration_microseconds() { using namespace std::chrono_literals; Void::Testing::expect( Void::Time::format_duration(4500ns).find("\xc2\xb5s") != std::string::npos); } Void::Testing::Test format_duration_milliseconds() { using namespace std::chrono_literals; Void::Testing::expect( Void::Time::format_duration(2'300'000ns).find("ms") != std::string::npos); } Void::Testing::Test format_duration_seconds() { using namespace std::chrono_literals; Void::Testing::expect( Void::Time::format_duration(1'500'000'000ns).find('s') != std::string::npos); } Void::Testing::Test format_duration_minutes() { Void::Testing::expect( Void::Time::format_duration(std::chrono::seconds{90}).find('m') != std::string::npos); } Void::Testing::Test format_duration_hours() { Void::Testing::expect( Void::Time::format_duration(std::chrono::seconds{3700}).find('h') != std::string::npos); } Void::Testing::Test format_duration_works_with_chrono_milliseconds() { using namespace std::chrono_literals; const auto s = Void::Time::format_duration(15ms); Void::Testing::expect(s.find("ms") != std::string::npos); } // ── utc timestamps ──────────────────────────────────────────────────────── Void::Testing::Test utc_now_iso8601_has_correct_format() { const auto s = Void::Time::utc_now_iso8601(); // "2026-05-14T10:30:00Z" Void::Testing::expect_eq(s.size(), std::size_t{20}); Void::Testing::expect_eq(s[4], '-'); Void::Testing::expect_eq(s[7], '-'); Void::Testing::expect_eq(s[10], 'T'); Void::Testing::expect_eq(s.back(), 'Z'); } Void::Testing::Test utc_now_iso8601_ms_has_correct_format() { const auto s = Void::Time::utc_now_iso8601_ms(); // "2026-05-14T10:30:00.123Z" Void::Testing::expect_eq(s.size(), std::size_t{24}); Void::Testing::expect_eq(s[10], 'T'); Void::Testing::expect_eq(s[19], '.'); Void::Testing::expect_eq(s.back(), 'Z'); }