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_map.h" |
| 6 |
5 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
6 #include "base/metrics/sample_map.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 namespace { | 11 namespace { |
11 | 12 |
12 TEST(SampleMapTest, AccumulateTest) { | 13 TEST(SampleMapTest, AccumulateTest) { |
13 SampleMap samples; | 14 SampleMap samples; |
14 | 15 |
15 samples.Accumulate(1, 100); | 16 samples.Accumulate(1, 100); |
16 samples.Accumulate(2, 200); | 17 samples.Accumulate(2, 200); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 EXPECT_EQ(3, max); | 80 EXPECT_EQ(3, max); |
80 EXPECT_EQ(200, count); | 81 EXPECT_EQ(200, count); |
81 | 82 |
82 it->Next(); | 83 it->Next(); |
83 it->Get(&min, &max, &count); | 84 it->Get(&min, &max, &count); |
84 EXPECT_EQ(4, min); | 85 EXPECT_EQ(4, min); |
85 EXPECT_EQ(5, max); | 86 EXPECT_EQ(5, max); |
86 EXPECT_EQ(-300, count); | 87 EXPECT_EQ(-300, count); |
87 | 88 |
88 it->Next(); | 89 it->Next(); |
| 90 EXPECT_TRUE(it->Done()); |
| 91 } |
| 92 |
| 93 TEST(SampleMapIteratorTest, SkipEmptyRanges) { |
| 94 SampleMap samples; |
| 95 samples.Accumulate(5, 1); |
| 96 samples.Accumulate(10, 2); |
| 97 samples.Accumulate(15, 3); |
| 98 samples.Accumulate(20, 4); |
| 99 samples.Accumulate(25, 5); |
| 100 |
| 101 SampleMap samples2; |
| 102 samples2.Accumulate(5, 1); |
| 103 samples2.Accumulate(20, 4); |
| 104 samples2.Accumulate(25, 5); |
| 105 |
| 106 samples.Subtract(samples2); |
| 107 |
| 108 scoped_ptr<SampleCountIterator> it = samples.Iterator(); |
| 109 EXPECT_FALSE(it->Done()); |
| 110 |
| 111 HistogramBase::Sample min; |
| 112 HistogramBase::Sample max; |
| 113 HistogramBase::Count count; |
| 114 |
89 it->Get(&min, &max, &count); | 115 it->Get(&min, &max, &count); |
90 EXPECT_EQ(5, min); | 116 EXPECT_EQ(10, min); |
91 EXPECT_EQ(6, max); | 117 EXPECT_EQ(11, max); |
92 EXPECT_EQ(0, count); | 118 EXPECT_EQ(2, count); |
| 119 |
| 120 it->Next(); |
| 121 EXPECT_FALSE(it->Done()); |
| 122 |
| 123 it->Get(&min, &max, &count); |
| 124 EXPECT_EQ(15, min); |
| 125 EXPECT_EQ(16, max); |
| 126 EXPECT_EQ(3, count); |
93 | 127 |
94 it->Next(); | 128 it->Next(); |
95 EXPECT_TRUE(it->Done()); | 129 EXPECT_TRUE(it->Done()); |
96 } | 130 } |
97 | 131 |
98 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 132 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
99 | 133 |
100 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { | 134 TEST(SampleMapIteratorDeathTest, IterateDoneTest) { |
101 SampleMap samples; | 135 SampleMap samples; |
102 | 136 |
(...skipping 11 matching lines...) Expand all Loading... |
114 samples.Accumulate(1, 100); | 148 samples.Accumulate(1, 100); |
115 it = samples.Iterator(); | 149 it = samples.Iterator(); |
116 EXPECT_FALSE(it->Done()); | 150 EXPECT_FALSE(it->Done()); |
117 } | 151 } |
118 | 152 |
119 #endif | 153 #endif |
120 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 154 // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
121 | 155 |
122 } // namespace | 156 } // namespace |
123 } // namespace base | 157 } // namespace base |
OLD | NEW |