| 1 | /* |
| 2 | * timer_util_test.hpp |
| 3 | * |
| 4 | * Created on: Jul 11, 2015 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef TIMER_UTIL_TEST_HPP_ |
| 9 | #define TIMER_UTIL_TEST_HPP_ |
| 10 | |
| 11 | #include "timer.hpp" |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE( timer_test ) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE( timer_use ) |
| 16 | { |
| 17 | //! [timer usage and behavior] |
| 18 | timer t; |
| 19 | |
| 20 | // start the timer |
| 21 | t.start(); |
| 22 | |
| 23 | sleep(1); |
| 24 | |
| 25 | // get the elapsed real time and cpu time without stop |
| 26 | BOOST_REQUIRE_CLOSE(t.getwct(),1.0,20.0); |
| 27 | BOOST_REQUIRE_SMALL(t.getcputime(),10.0); |
| 28 | |
| 29 | sleep(1); |
| 30 | |
| 31 | // stop the timer |
| 32 | t.stop(); |
| 33 | |
| 34 | sleep(1); |
| 35 | |
| 36 | // unusefull |
| 37 | t.stop(); |
| 38 | |
| 39 | // get the cpu time and real time |
| 40 | t.getcputime(); |
| 41 | t.getwct(); |
| 42 | |
| 43 | // get the elapsed real time and cpu time without stop |
| 44 | BOOST_REQUIRE_CLOSE(t.getwct(),2.0,20.0); |
| 45 | BOOST_REQUIRE_SMALL(t.getcputime(),10.0); |
| 46 | |
| 47 | t.reset(); |
| 48 | |
| 49 | BOOST_REQUIRE_CLOSE(t.getwct(),0.0,20.0); |
| 50 | BOOST_REQUIRE_SMALL(t.getcputime(),10.0); |
| 51 | |
| 52 | //! [timer usage and behavior] |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_SUITE_END() |
| 56 | |
| 57 | |
| 58 | #endif /* TIMER_UTIL_TEST_HPP_ */ |
| 59 | |