From a28790b91d89002edb27dd1bc3997b1d03a94d7e Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 2 Aug 2023 00:19:41 +0200 Subject: timer: add assertions to test --- test/timer.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') diff --git a/test/timer.cc b/test/timer.cc index 5ac169c..3b5b5ac 100644 --- a/test/timer.cc +++ b/test/timer.cc @@ -1,5 +1,6 @@ #include #include +#include #include int main() { @@ -15,6 +16,9 @@ int main() { const timer::scoped_timer kS{t}; usleep(100 * 1000); } + assert(100000 < t.as_usec() && t.as_usec() < 101000); + assert(100 < t.as_msec() && t.as_msec() < 101); + assert(0.100 < t.as_sec() && t.as_sec() < 0.101); kShowTime(); { @@ -22,6 +26,20 @@ int main() { const timer::scoped_timer kS{t}; usleep(500 * 1000); } + assert(600000 < t.as_usec() && t.as_usec() < 601000); + assert(600 < t.as_msec() && t.as_msec() < 601); + assert(0.600 < t.as_sec() && t.as_sec() < 0.601); + kShowTime(); + + t.reset(); + { + puts("Sleep 200ms"); + timer::scoped_timer s{t}; + usleep(200 * 1000); + } + assert(200000 < t.as_usec() && t.as_usec() < 201000); + assert(200 < t.as_msec() && t.as_msec() < 201); + assert(0.200 < t.as_sec() && t.as_sec() < 0.201); kShowTime(); return 0; -- cgit v1.2.3