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  static constexpr bool is_steady = true;
41 
42  static time_point time;
43  static time_point now() noexcept { return time; }
44 };
45 
46 SimulatedClock::time_point SimulatedClock::time;
47 
48 TEST(RateTimerTest, ComputeWallTimeRateRatio) {
50  RateTimer<SimulatedClock> rate_timer(common::FromSeconds(1.));
51  for (int i = 0; i < 100; ++i) {
52  rate_timer.Pulse(time);
53  time += common::FromSeconds(0.1);
54  SimulatedClock::time +=
55  std::chrono::duration_cast<SimulatedClock::duration>(
56  std::chrono::duration<double>(0.05));
57  }
58  EXPECT_NEAR(2., rate_timer.ComputeWallTimeRateRatio(), 1e-3);
59 }
60 
61 } // namespace
62 } // namespace common
63 } // 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
static constexpr bool is_steady


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:39