diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-02 00:19:41 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-08-31 19:41:45 +0200 |
commit | a28790b91d89002edb27dd1bc3997b1d03a94d7e (patch) | |
tree | d396bb0042b2c923ea450d3e536198d68685b233 /test/timer.cc | |
parent | 58bae306abde95da78f698408ac9d580d5a2b1d7 (diff) | |
download | cpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.tar.gz cpp-utils-a28790b91d89002edb27dd1bc3997b1d03a94d7e.zip |
timer: add assertions to test
Diffstat (limited to 'test/timer.cc')
-rw-r--r-- | test/timer.cc | 18 |
1 files changed, 18 insertions, 0 deletions
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 <timer.h> #include <unistd.h> +#include <cassert> #include <cstdio> 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; |