rate_timer_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "gtest/gtest.h"
20 
21 namespace cartographer {
22 namespace common {
23 namespace {
24 
25 TEST(RateTimerTest, ComputeRate) {
26  RateTimer<> rate_timer(common::FromSeconds(1.));
28  for (int i = 0; i < 100; ++i) {
29  rate_timer.Pulse(time);
30  time += common::FromSeconds(0.1);
31  }
32  EXPECT_NEAR(10., rate_timer.ComputeRate(), 1e-3);
33 }
34 
35 struct SimulatedClock {
36  using rep = std::chrono::steady_clock::rep;
37  using period = std::chrono::steady_clock::period;
38  using duration = std::chrono::steady_clock::duration;
39  using time_point = std::chrono::steady_clock::time_point;
40 
41  static time_point time;
42  static time_point now() noexcept { return time; }
43 };
44 
45 SimulatedClock::time_point SimulatedClock::time;
46 
47 TEST(RateTimerTest, ComputeWallTimeRateRatio) {
49  RateTimer<SimulatedClock> rate_timer(common::FromSeconds(1.));
50  for (int i = 0; i < 100; ++i) {
51  rate_timer.Pulse(time);
52  time += common::FromSeconds(0.1);
53  SimulatedClock::time +=
54  std::chrono::duration_cast<SimulatedClock::duration>(
55  std::chrono::duration<double>(0.05));
56  }
57  EXPECT_NEAR(2., rate_timer.ComputeWallTimeRateRatio(), 1e-3);
58 }
59 
60 } // namespace
61 } // namespace common
62 } // namespace cartographer
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
static time_point time
Duration FromSeconds(const double seconds)
Definition: time.cc:24
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58