fixed_ratio_sampler_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(FixedRatioSamplerTest, AlwaysTrue) {
26  FixedRatioSampler fixed_ratio_sampler(1.);
27  for (int i = 0; i < 100; ++i) {
28  EXPECT_TRUE(fixed_ratio_sampler.Pulse());
29  }
30 }
31 
32 TEST(FixedRatioSamplerTest, AlwaysFalse) {
33  FixedRatioSampler fixed_ratio_sampler(0.);
34  for (int i = 0; i < 100; ++i) {
35  EXPECT_FALSE(fixed_ratio_sampler.Pulse());
36  }
37 }
38 
39 TEST(FixedRatioSamplerTest, NonSensicalRatio) {
40  EXPECT_DEATH(FixedRatioSampler(2.), "ratio");
41  EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio");
42 }
43 
44 TEST(FixedRatioSamplerTest, SometimesTrue) {
45  FixedRatioSampler fixed_ratio_sampler(0.5);
46  for (int i = 0; i < 100; ++i) {
47  EXPECT_EQ(i % 2 == 0, fixed_ratio_sampler.Pulse());
48  }
49 }
50 
51 TEST(FixedRatioSamplerTest, FirstPulseIsTrue) {
52  // Choose a very very small positive number for the ratio.
53  FixedRatioSampler fixed_ratio_sampler(1e-20);
54  EXPECT_TRUE(fixed_ratio_sampler.Pulse());
55  for (int i = 0; i < 100; ++i) {
56  EXPECT_FALSE(fixed_ratio_sampler.Pulse());
57  }
58 }
59 
60 } // namespace
61 } // namespace common
62 } // namespace cartographer
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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