ASSERT_FALSE(stor.zero());
}
-/**
- * Test that an assertion is thrown when no bucket size is provided before
- * sampling.
- */
-TEST(StatsDistStorDeathTest, NoBucketSize)
+/** Test that an assertion is thrown when bucket size is 0. */
+TEST(StatsDistStorDeathTest, BucketSize0)
{
- Stats::Counter val = 10;
- Stats::Counter num_samples = 5;
- Stats::DistStor::Params params;
- MockInfo info(¶ms);
- Stats::DistStor stor(&info);
- ASSERT_DEATH(stor.sample(val, num_samples), ".+");
+ testing::internal::CaptureStderr();
+ EXPECT_ANY_THROW(Stats::DistStor::Params params(0, 5, 0));
+ testing::internal::GetCapturedStderr();
}
/**
*/
TEST(StatsDistStorTest, ZeroReset)
{
- Stats::DistStor::Params params;
- params.bucket_size = 10;
+ Stats::DistStor::Params params(0, 99, 10);
MockInfo info(¶ms);
Stats::DistStor stor(&info);
Stats::Counter val = 10;
Stats::Counter size = 20;
Stats::DistData data;
- Stats::DistStor::Params params;
- params.bucket_size = 1;
- params.buckets = size;
+ Stats::DistStor::Params params(0, 19, 1);
MockInfo info(¶ms);
Stats::DistStor stor(&info);
/** Test setting and getting value from storage. */
TEST(StatsDistStorTest, SamplePrepareSingle)
{
- Stats::DistStor::Params params;
- params.min = 0;
- params.max = 99;
- params.bucket_size = 5;
- params.buckets = 20;
+ Stats::DistStor::Params params(0, 99, 5);
ValueSamples values[] = {{10, 5}};
int num_values = sizeof(values) / sizeof(ValueSamples);
/** Test setting and getting value from storage with multiple values. */
TEST(StatsDistStorTest, SamplePrepareMultiple)
{
- Stats::DistStor::Params params;
- params.min = 0;
- params.max = 99;
- params.bucket_size = 5;
- params.buckets = 20;
+ Stats::DistStor::Params params(0, 99, 5);
// There are 20 buckets: [0,5[, [5,10[, [10,15[, ..., [95,100[.
// We test that values that pass the maximum bucket value (1234, 12345678,
/** Test resetting storage. */
TEST(StatsDistStorTest, Reset)
{
- Stats::DistStor::Params params;
- params.min = 0;
- params.max = 99;
- params.bucket_size = 5;
- params.buckets = 20;
+ Stats::DistStor::Params params(0, 99, 5);
MockInfo info(¶ms);
Stats::DistStor stor(&info);
checkExpectedDistData(data, expected_data, true);
}
-/**
- * Test that an assertion is thrown when no bucket size is provided before
- * sampling.
- */
-TEST(StatsHistStorDeathTest, NoBucketSize)
+/** Test that an assertion is thrown when not enough buckets are provided. */
+TEST(StatsHistStorDeathTest, NotEnoughBuckets0)
{
- Stats::Counter val = 10;
- Stats::Counter num_samples = 5;
+ testing::internal::CaptureStderr();
+ EXPECT_ANY_THROW(Stats::HistStor::Params params(0));
+ testing::internal::GetCapturedStderr();
+}
- // If no bucket size is specified, it is 0 by default
- Stats::HistStor::Params params;
- MockInfo info(¶ms);
- Stats::HistStor stor(&info);
- ASSERT_DEATH(stor.sample(val, num_samples), ".+");
+/** Test that an assertion is thrown when not enough buckets are provided. */
+TEST(StatsHistStorDeathTest, NotEnoughBuckets1)
+{
+ testing::internal::CaptureStderr();
+ EXPECT_ANY_THROW(Stats::HistStor::Params params(1));
+ testing::internal::GetCapturedStderr();
}
/**
*/
TEST(StatsHistStorTest, ZeroReset)
{
- Stats::HistStor::Params params;
- params.buckets = 10;
+ Stats::HistStor::Params params(10);
MockInfo info(¶ms);
Stats::HistStor stor(&info);
Stats::Counter val = 10;
Stats::DistData data;
Stats::size_type sizes[] = {2, 10, 1234};
- // If no bucket size is specified, it is 0 by default
- {
- Stats::HistStor::Params params;
- MockInfo info(¶ms);
- Stats::HistStor stor(&info);
-
- ASSERT_EQ(stor.size(), 0);
- stor.prepare(&info, data);
- ASSERT_EQ(stor.size(), 0);
- stor.reset(&info);
- ASSERT_EQ(stor.size(), 0);
- stor.zero();
- ASSERT_EQ(stor.size(), 0);
- }
-
for (int i = 0; i < (sizeof(sizes) / sizeof(Stats::size_type)); i++) {
- Stats::HistStor::Params params;
- params.buckets = sizes[i];
+ Stats::HistStor::Params params(sizes[i]);
MockInfo info(¶ms);
Stats::HistStor stor(&info);
*/
TEST(StatsHistStorTest, SamplePrepareFit)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. The final buckets
// will be divided at:
*/
TEST(StatsHistStorTest, SamplePrepareSingleGrowUp)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. Since there
// are four buckets, and the highest value is 4, the bucket size will
*/
TEST(StatsHistStorTest, SamplePrepareMultipleGrowUp)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. Since there
// are four buckets, and the highest value is 4, the bucket size will
*/
TEST(StatsHistStorTest, SamplePrepareGrowDownOddBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 5;
+ Stats::HistStor::Params params(5);
// Setup expected data for the hand-carved values given. Since there
// is a negative value, the min bucket will change, and the bucket size
*/
TEST(StatsHistStorTest, SamplePrepareGrowDownEvenBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. Since there
// is a negative value, the min bucket will change, and the bucket size
*/
TEST(StatsHistStorTest, SamplePrepareGrowDownGrowOutOddBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 5;
+ Stats::HistStor::Params params(5);
// Setup expected data for the hand-carved values given. Since there
// is a negative value, the min bucket will change, and the bucket size
*/
TEST(StatsHistStorTest, SamplePrepareGrowDownGrowOutEvenBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. Since there
// is a negative value, the min bucket will change, and the bucket size
*/
TEST(StatsHistStorTest, SamplePrepareMultipleGrowOddBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 5;
+ Stats::HistStor::Params params(5);
// Setup expected data for the hand-carved values given. This adds quite
// a few positive and negative samples, and the bucket size will grow to
*/
TEST(StatsHistStorTest, SamplePrepareMultipleGrowEvenBuckets)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
// Setup expected data for the hand-carved values given. This adds quite
// a few positive and negative samples, and the bucket size will grow to
/** Test resetting storage. */
TEST(StatsHistStorTest, Reset)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
MockInfo info(¶ms);
Stats::HistStor stor(&info);
/** Test whether adding storages with different sizes triggers an assertion. */
TEST(StatsHistStorDeathTest, AddDifferentSize)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
MockInfo info(¶ms);
Stats::HistStor stor(&info);
- Stats::HistStor::Params params2;
- params2.buckets = 5;
+ Stats::HistStor::Params params2(5);
MockInfo info2(¶ms2);
Stats::HistStor stor2(&info2);
/** Test whether adding storages with different min triggers an assertion. */
TEST(StatsHistStorDeathTest, AddDifferentMin)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
MockInfo info(¶ms);
Stats::HistStor stor(&info);
stor.sample(-1, 3);
// On creation, the storage's min is zero
- Stats::HistStor::Params params2;
- params2.buckets = 4;
+ Stats::HistStor::Params params2(4);
MockInfo info2(¶ms2);
Stats::HistStor stor2(&info2);
/** Test merging two histograms. */
TEST(StatsHistStorTest, Add)
{
- Stats::HistStor::Params params;
- params.buckets = 4;
+ Stats::HistStor::Params params(4);
MockInfo info(¶ms);
// Setup first storage. Buckets are: