Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: base/metrics/sparse_histogram_unittest.cc

Issue 11022002: Add SampleMap and use it in SparseHistogram (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address more comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/sample_map.h"
8 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 13
13 class SparseHistogramTest : public testing::Test { 14 class SparseHistogramTest : public testing::Test {
14 protected: 15 protected:
15 scoped_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) { 16 scoped_ptr<SparseHistogram> NewSparseHistogram(const std::string& name) {
16 return scoped_ptr<SparseHistogram>(new SparseHistogram(name)); 17 return scoped_ptr<SparseHistogram>(new SparseHistogram(name));
17 } 18 }
18 }; 19 };
19 20
20 TEST_F(SparseHistogramTest, BasicTest) { 21 TEST_F(SparseHistogramTest, BasicTest) {
21 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1")); 22 scoped_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse1"));
22 std::map<HistogramBase::Sample, HistogramBase::Count> sample; 23 scoped_ptr<SampleMap> snapshot(histogram->SnapshotSamples());
23 histogram->SnapshotSample(&sample); 24 EXPECT_EQ(0, snapshot->TotalCount());
24 25 EXPECT_EQ(0, snapshot->sum());
25 ASSERT_EQ(0u, sample.size());
26 26
27 histogram->Add(100); 27 histogram->Add(100);
28 histogram->SnapshotSample(&sample); 28 scoped_ptr<SampleMap> snapshot1(histogram->SnapshotSamples());
29 ASSERT_EQ(1u, sample.size()); 29 EXPECT_EQ(1, snapshot1->TotalCount());
30 EXPECT_EQ(1, sample[100]); 30 EXPECT_EQ(1, snapshot1->GetCount(100));
31 31
32 histogram->Add(100); 32 histogram->Add(100);
33 histogram->Add(101); 33 histogram->Add(101);
34 histogram->SnapshotSample(&sample); 34 scoped_ptr<SampleMap> snapshot2(histogram->SnapshotSamples());
35 ASSERT_EQ(2u, sample.size()); 35 EXPECT_EQ(3, snapshot2->TotalCount());
36 EXPECT_EQ(2, sample[100]); 36 EXPECT_EQ(2, snapshot2->GetCount(100));
37 EXPECT_EQ(1, sample[101]); 37 EXPECT_EQ(1, snapshot2->GetCount(101));
38 } 38 }
39 39
40 } // namespace base 40 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698