| 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/sample_vector.h" | 5 #include "base/metrics/sample_vector.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); | 37 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); |
| 38 | 38 |
| 39 samples.Accumulate(5, -100); | 39 samples.Accumulate(5, -100); |
| 40 EXPECT_EQ(100, samples.GetCountAtIndex(1)); | 40 EXPECT_EQ(100, samples.GetCountAtIndex(1)); |
| 41 | 41 |
| 42 EXPECT_EQ(100, samples.sum()); | 42 EXPECT_EQ(100, samples.sum()); |
| 43 EXPECT_EQ(0, samples.redundant_count()); | 43 EXPECT_EQ(0, samples.redundant_count()); |
| 44 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); | 44 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 TEST(SampleVectorTest, Accumulate_LargeValuesDontOverflow) { |
| 48 // Custom buckets: [1, 250000000) [250000000, 500000000) |
| 49 BucketRanges ranges(3); |
| 50 ranges.set_range(0, 1); |
| 51 ranges.set_range(1, 250000000); |
| 52 ranges.set_range(2, 500000000); |
| 53 SampleVector samples(1, &ranges); |
| 54 |
| 55 samples.Accumulate(240000000, 200); |
| 56 samples.Accumulate(249999999, -300); |
| 57 EXPECT_EQ(-100, samples.GetCountAtIndex(0)); |
| 58 |
| 59 samples.Accumulate(250000000, 200); |
| 60 EXPECT_EQ(200, samples.GetCountAtIndex(1)); |
| 61 |
| 62 EXPECT_EQ(23000000300LL, samples.sum()); |
| 63 EXPECT_EQ(100, samples.redundant_count()); |
| 64 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); |
| 65 |
| 66 samples.Accumulate(250000000, -100); |
| 67 EXPECT_EQ(100, samples.GetCountAtIndex(1)); |
| 68 |
| 69 EXPECT_EQ(-1999999700LL, samples.sum()); |
| 70 EXPECT_EQ(0, samples.redundant_count()); |
| 71 EXPECT_EQ(samples.TotalCount(), samples.redundant_count()); |
| 72 } |
| 73 |
| 47 TEST(SampleVectorTest, AddSubtractTest) { | 74 TEST(SampleVectorTest, AddSubtractTest) { |
| 48 // Custom buckets: [0, 1) [1, 2) [2, 3) [3, INT_MAX) | 75 // Custom buckets: [0, 1) [1, 2) [2, 3) [3, INT_MAX) |
| 49 BucketRanges ranges(5); | 76 BucketRanges ranges(5); |
| 50 ranges.set_range(0, 0); | 77 ranges.set_range(0, 0); |
| 51 ranges.set_range(1, 1); | 78 ranges.set_range(1, 1); |
| 52 ranges.set_range(2, 2); | 79 ranges.set_range(2, 2); |
| 53 ranges.set_range(3, 3); | 80 ranges.set_range(3, 3); |
| 54 ranges.set_range(4, INT_MAX); | 81 ranges.set_range(4, INT_MAX); |
| 55 | 82 |
| 56 SampleVector samples1(1, &ranges); | 83 SampleVector samples1(1, &ranges); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 samples.Accumulate(2, 100); | 285 samples.Accumulate(2, 100); |
| 259 it = samples.Iterator(); | 286 it = samples.Iterator(); |
| 260 EXPECT_FALSE(it->Done()); | 287 EXPECT_FALSE(it->Done()); |
| 261 } | 288 } |
| 262 | 289 |
| 263 #endif | 290 #endif |
| 264 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 291 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
| 265 | 292 |
| 266 } // namespace | 293 } // namespace |
| 267 } // namespace base | 294 } // namespace base |
| OLD | NEW |