rate_timer_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/common/rate_timer.h"
00018 
00019 #include "gtest/gtest.h"
00020 
00021 namespace cartographer {
00022 namespace common {
00023 namespace {
00024 
00025 TEST(RateTimerTest, ComputeRate) {
00026   RateTimer<> rate_timer(common::FromSeconds(1.));
00027   common::Time time = common::FromUniversal(42);
00028   for (int i = 0; i < 100; ++i) {
00029     rate_timer.Pulse(time);
00030     time += common::FromSeconds(0.1);
00031   }
00032   EXPECT_NEAR(10., rate_timer.ComputeRate(), 1e-3);
00033 }
00034 
00035 struct SimulatedClock {
00036   using rep = std::chrono::steady_clock::rep;
00037   using period = std::chrono::steady_clock::period;
00038   using duration = std::chrono::steady_clock::duration;
00039   using time_point = std::chrono::steady_clock::time_point;
00040 
00041   static time_point time;
00042   static time_point now() noexcept { return time; }
00043 };
00044 
00045 SimulatedClock::time_point SimulatedClock::time;
00046 
00047 TEST(RateTimerTest, ComputeWallTimeRateRatio) {
00048   common::Time time = common::FromUniversal(42);
00049   RateTimer<SimulatedClock> rate_timer(common::FromSeconds(1.));
00050   for (int i = 0; i < 100; ++i) {
00051     rate_timer.Pulse(time);
00052     time += common::FromSeconds(0.1);
00053     SimulatedClock::time +=
00054         std::chrono::duration_cast<SimulatedClock::duration>(
00055             std::chrono::duration<double>(0.05));
00056   }
00057   EXPECT_NEAR(2., rate_timer.ComputeWallTimeRateRatio(), 1e-3);
00058 }
00059 
00060 }  // namespace
00061 }  // namespace common
00062 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35