diff options
author | Josh Blum | 2013-06-11 17:55:31 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-11 17:55:31 -0700 |
commit | c73eb9bf1954135372b1cc8e7b21d7cc0cdfd489 (patch) | |
tree | c68ba6daf09021df58c6ae11f18bb3dc36e88eae /tests | |
parent | 8ff889a8160bdf61739066c74c469ca2bcad093e (diff) | |
download | sandhi-c73eb9bf1954135372b1cc8e7b21d7cc0cdfd489.tar.gz sandhi-c73eb9bf1954135372b1cc8e7b21d7cc0cdfd489.tar.bz2 sandhi-c73eb9bf1954135372b1cc8e7b21d7cc0cdfd489.zip |
gras: reverted chrono changes w/ 32-bit math fix
The seconds * ticks per second math was 32 bit,
because UL follows the system width, we needed long long.
* for loop for heartier unit testing
* use get_tps rather than duplicate const number
Diffstat (limited to 'tests')
-rw-r--r-- | tests/chrono_time_test.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/chrono_time_test.cpp b/tests/chrono_time_test.cpp index 80c80ab..d7f76ad 100644 --- a/tests/chrono_time_test.cpp +++ b/tests/chrono_time_test.cpp @@ -8,16 +8,21 @@ BOOST_AUTO_TEST_CASE(test_chrono_time) { - gras::time_ticks_t t0 = gras::time_now(); - boost::this_thread::sleep(boost::posix_time::seconds(1)); - gras::time_ticks_t t1 = gras::time_now(); + for (size_t trial_i = 0; trial_i < 100; trial_i++) + { + const double sleep_secs = 0.01 + trial_i*0.0001; + gras::time_ticks_t t0 = gras::time_now(); + boost::this_thread::sleep(boost::posix_time::milliseconds(long(sleep_secs*1000))); + gras::time_ticks_t t1 = gras::time_now(); - std::cout << "t0 " << t0 << std::endl; - std::cout << "t1 " << t1 << std::endl; - BOOST_CHECK(t1 > t0); + std::cout << "t0 " << t0 << std::endl; + std::cout << "t1 " << t1 << std::endl; + BOOST_CHECK(t1 > t0); - const double delta_time = double(t1-t0)/gras::time_tps(); - std::cout << "delta_time " << delta_time << std::endl; - //this check allows +/- 0.5 seconds -- so it should always pass - BOOST_CHECK(delta_time < 1.5 and delta_time > 0.5); + const double delta_time = double(t1-t0)/gras::time_tps(); + std::cout << "delta_time " << delta_time << std::endl; + const double low_margin = sleep_secs - sleep_secs/2; + const double high_margin = sleep_secs + sleep_secs/2; + BOOST_CHECK(delta_time < high_margin and delta_time > low_margin); + } } |