31 lines
1.3 KiB
C++
31 lines
1.3 KiB
C++
// Standalone numerical regression: no robot, ROS graph or filter execution.
|
|||
|
|
#include <sensor_timestamp.h>
|
||
|
|
#include <sensor_time_rate_limiter.h>
|
||
|
|
#include <cassert>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
int main()
|
||
|
|
{
|
||
|
|
int previously_truncated = 0;
|
||
|
|
for (std::int64_t frame = 0; frame < 6000; ++frame) {
|
||
|
|
const std::int64_t expected = frame * 100000000 + 99000000;
|
||
|
|
const double stamp = frame * .1 + .099;
|
||
|
|
const auto old = static_cast<std::int64_t>(std::floor(stamp)) * 1000000000 +
|
||
|
|
static_cast<std::uint32_t>((stamp - std::floor(stamp)) * 1e9);
|
||
|
|
previously_truncated += old != expected;
|
||
|
|
assert(point_lio::rounded_sensor_time_ns(stamp) == expected);
|
||
|
|
}
|
||
|
|
assert(previously_truncated > 0);
|
||
|
|
assert(point_lio::rounded_sensor_time_ns(38.319) == INT64_C(38319000000));
|
||
|
|
assert(point_lio::rounded_sensor_time_ns(.9999999996) == INT64_C(1000000000));
|
||
|
|
assert(point_lio::rounded_sensor_time_ns(1.0000000004) == INT64_C(1000000000));
|
||
|
|
point_lio::SensorTimeRateLimiter limiter;
|
||
|
|
assert(limiter.should_publish(.090,100));
|
||
|
|
assert(!limiter.should_publish(.099,100));
|
||
|
|
assert(limiter.should_publish(.099,100,true));
|
||
|
|
assert(!limiter.should_publish(.099,100,true));
|
||
|
|
assert(limiter.should_publish(.109,100));
|
||
|
|
std::cout << "6000 scan endpoint roundtrips and 3 boundary cases passed; old truncation mismatches: "
|
||
|
|
<< previously_truncated << '\n';
|
||
|
|
}
|