Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/common/fixed_ratio_sampler.h"
00018
00019 #include "gtest/gtest.h"
00020
00021 namespace cartographer {
00022 namespace common {
00023 namespace {
00024
00025 TEST(FixedRatioSamplerTest, AlwaysTrue) {
00026 FixedRatioSampler fixed_ratio_sampler(1.);
00027 for (int i = 0; i < 100; ++i) {
00028 EXPECT_TRUE(fixed_ratio_sampler.Pulse());
00029 }
00030 }
00031
00032 TEST(FixedRatioSamplerTest, AlwaysFalse) {
00033 FixedRatioSampler fixed_ratio_sampler(0.);
00034 for (int i = 0; i < 100; ++i) {
00035 EXPECT_FALSE(fixed_ratio_sampler.Pulse());
00036 }
00037 }
00038
00039 TEST(FixedRatioSamplerTest, NonSensicalRatio) {
00040 EXPECT_DEATH(FixedRatioSampler(2.), "ratio");
00041 EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio");
00042 }
00043
00044 TEST(FixedRatioSamplerTest, SometimesTrue) {
00045 FixedRatioSampler fixed_ratio_sampler(0.5);
00046 for (int i = 0; i < 100; ++i) {
00047 EXPECT_EQ(i % 2 == 0, fixed_ratio_sampler.Pulse());
00048 }
00049 }
00050
00051 TEST(FixedRatioSamplerTest, FirstPulseIsTrue) {
00052
00053 FixedRatioSampler fixed_ratio_sampler(1e-20);
00054 EXPECT_TRUE(fixed_ratio_sampler.Pulse());
00055 for (int i = 0; i < 100; ++i) {
00056 EXPECT_FALSE(fixed_ratio_sampler.Pulse());
00057 }
00058 }
00059
00060 }
00061 }
00062 }