Check ratios in fixed rate sampler. (#502)
							parent
							
								
									9c81a01608
								
							
						
					
					
						commit
						b1b0750e5b
					
				|  | @ -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() {} | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue