#include "zeroerr/assert.h" #include "zeroerr/unittest.h" #include "timer/Timer.h" #include #include TEST_CASE("timer.getTime.monotonic") { auto* t = eve::timer::Timer::create(); float t0 = t->getTime(); float t1 = t->getTime(); CHECK(t1 >= t0); } TEST_CASE("timer.step.deltaNonNegative") { auto* t = eve::timer::Timer::create(); t->step(); CHECK(t->getDelta() >= 0.f); float d = t->step(); CHECK(d >= 0.f); CHECK(t->getDelta() == d); } TEST_CASE("timer.step.deltaPositiveAfterSleep") { auto* t = eve::timer::Timer::create(); t->step(); std::this_thread::sleep_for(std::chrono::milliseconds(15)); float delta = t->step(); CHECK(delta > 0.f); CHECK(t->getDelta() == delta); } TEST_CASE("timer.simulationClockUsesInjectedFixedSteps") { auto* t = eve::timer::Timer::create(); const auto before = t->getFrameIndex(); auto steps = t->stepSimulation(); REQUIRE(steps.ok()); CHECK(t->getFrameIndex() > before); CHECK(t->getDeltaDuration().nanoseconds() >= 0); CHECK(t->monotonicNow() >= eve::MonotonicTimestamp::zero()); CHECK(t->wallClockNow().unixNanoseconds() != 0); }