Check ratios in fixed rate sampler. (#502)

master
Juraj Oršulić 2017-10-04 13:15:35 +02:00 committed by Wolfgang Hess
parent 9c81a01608
commit b1b0750e5b
2 changed files with 10 additions and 6 deletions

View File

@ -16,10 +16,15 @@
#include "cartographer/common/fixed_ratio_sampler.h"
#include "glog/logging.h"
namespace cartographer {
namespace common {
FixedRatioSampler::FixedRatioSampler(const double ratio) : ratio_(ratio) {}
FixedRatioSampler::FixedRatioSampler(const double ratio) : ratio_(ratio) {
CHECK_GT(ratio, 0.);
CHECK_LE(ratio, 1.);
}
FixedRatioSampler::~FixedRatioSampler() {}

View File

@ -29,11 +29,10 @@ TEST(FixedRatioSamplerTest, AlwaysTrue) {
}
}
TEST(FixedRatioSamplerTest, AlwaysFalse) {
FixedRatioSampler fixed_ratio_sampler(0.);
for (int i = 0; i < 100; ++i) {
EXPECT_FALSE(fixed_ratio_sampler.Pulse());
}
TEST(FixedRatioSamplerTest, NonSensicalRatio) {
EXPECT_DEATH(FixedRatioSampler(0.), "ratio");
EXPECT_DEATH(FixedRatioSampler(2.), "ratio");
EXPECT_DEATH(FixedRatioSampler(-0.1), "ratio");
}
TEST(FixedRatioSamplerTest, SometimesTrue) {