mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
97631ec362
* c++ RateKeeper * add to files_common * use util::random_int * improve monotor_time * remove ~ratekeeper old-commit-hash: 3eef63af9b4f4a25bc4c3a0d6ad450bba9f62205
18 lines
523 B
C++
18 lines
523 B
C++
#define CATCH_CONFIG_MAIN
|
|
#include "catch2/catch.hpp"
|
|
#include "common/ratekeeper.h"
|
|
#include "common/timing.h"
|
|
#include "common/util.h"
|
|
|
|
TEST_CASE("RateKeeper") {
|
|
float freq = GENERATE(10, 50, 100);
|
|
RateKeeper rk("Test RateKeeper", freq);
|
|
for (int i = 0; i < freq; ++i) {
|
|
double begin = seconds_since_boot();
|
|
util::sleep_for(util::random_int(0, 1000.0 / freq - 1));
|
|
bool lagged = rk.keepTime();
|
|
REQUIRE(std::abs(seconds_since_boot() - begin - (1 / freq)) < 1e-3);
|
|
REQUIRE(lagged == false);
|
|
}
|
|
}
|