OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/metrics/histogram.h" | 5 #include "base/metrics/histogram.h" |
6 | 6 |
7 #include <climits> | 7 #include <climits> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 Histogram* histogram = static_cast<Histogram*>( | 224 Histogram* histogram = static_cast<Histogram*>( |
225 CustomHistogram::FactoryGet("2BucketsCustomHistogram", custom_ranges, | 225 CustomHistogram::FactoryGet("2BucketsCustomHistogram", custom_ranges, |
226 HistogramBase::kNoFlags)); | 226 HistogramBase::kNoFlags)); |
227 const BucketRanges* ranges = histogram->bucket_ranges(); | 227 const BucketRanges* ranges = histogram->bucket_ranges(); |
228 ASSERT_EQ(3u, ranges->size()); | 228 ASSERT_EQ(3u, ranges->size()); |
229 EXPECT_EQ(0, ranges->range(0)); | 229 EXPECT_EQ(0, ranges->range(0)); |
230 EXPECT_EQ(4, ranges->range(1)); | 230 EXPECT_EQ(4, ranges->range(1)); |
231 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2)); | 231 EXPECT_EQ(HistogramBase::kSampleType_MAX, ranges->range(2)); |
232 } | 232 } |
233 | 233 |
234 // Test the MultiAdd Function | |
bengr
2015/07/28 17:18:10
Function -> function.
| |
235 TEST_F(HistogramTest, MultiAddTest) { | |
236 const size_t kBucketCount = 50; | |
237 Histogram* histogram = static_cast<Histogram*>( | |
238 Histogram::FactoryGet("MultiAddHistogram", 10, 100, kBucketCount, | |
239 HistogramBase::kNoFlags)); | |
240 | |
241 histogram->MultiAdd(20, 15); | |
242 histogram->MultiAdd(30, 14); | |
243 | |
244 scoped_ptr<SampleVector> samples = histogram->SnapshotSampleVector(); | |
245 EXPECT_EQ(29, samples->TotalCount()); | |
246 EXPECT_EQ(15, samples->GetCount(20)); | |
247 EXPECT_EQ(14, samples->GetCount(30)); | |
248 | |
249 histogram->MultiAdd(20, 25); | |
250 histogram->MultiAdd(30, 24); | |
251 | |
252 scoped_ptr<SampleVector> samples2 = histogram->SnapshotSampleVector(); | |
253 EXPECT_EQ(78, samples2->TotalCount()); | |
254 EXPECT_EQ(40, samples2->GetCount(20)); | |
255 EXPECT_EQ(38, samples2->GetCount(30)); | |
256 | |
257 } | |
258 | |
234 // Make sure histogram handles out-of-bounds data gracefully. | 259 // Make sure histogram handles out-of-bounds data gracefully. |
235 TEST_F(HistogramTest, BoundsTest) { | 260 TEST_F(HistogramTest, BoundsTest) { |
236 const size_t kBucketCount = 50; | 261 const size_t kBucketCount = 50; |
237 Histogram* histogram = static_cast<Histogram*>( | 262 Histogram* histogram = static_cast<Histogram*>( |
238 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, | 263 Histogram::FactoryGet("Bounded", 10, 100, kBucketCount, |
239 HistogramBase::kNoFlags)); | 264 HistogramBase::kNoFlags)); |
240 | 265 |
241 // Put two samples "out of bounds" above and below. | 266 // Put two samples "out of bounds" above and below. |
242 histogram->Add(5); | 267 histogram->Add(5); |
243 histogram->Add(-50); | 268 histogram->Add(-50); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 // CustomHistogram needs at least 1 valid range. | 528 // CustomHistogram needs at least 1 valid range. |
504 custom_ranges.clear(); | 529 custom_ranges.clear(); |
505 custom_ranges.push_back(0); | 530 custom_ranges.push_back(0); |
506 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, | 531 EXPECT_DEATH(CustomHistogram::FactoryGet("BadRangesCustom3", custom_ranges, |
507 HistogramBase::kNoFlags), | 532 HistogramBase::kNoFlags), |
508 ""); | 533 ""); |
509 } | 534 } |
510 #endif | 535 #endif |
511 | 536 |
512 } // namespace base | 537 } // namespace base |
OLD | NEW |