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

Side by Side Diff: components/rappor/rappor_metric_unittest.cc

Issue 509203002: Create a mechanism for reporting rappor metrics from non-UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « components/rappor/rappor_metric.cc ('k') | components/rappor/rappor_parameters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/rappor/rappor_metric.h" 5 #include "components/rappor/rappor_metric.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace rappor { 13 namespace rappor {
14 14
15 const RapporParameters kTestRapporParameters = { 15 const RapporParameters kTestRapporParameters = {
16 1 /* Num cohorts */, 16 1 /* Num cohorts */,
17 16 /* Bloom filter size bytes */, 17 16 /* Bloom filter size bytes */,
18 4 /* Bloom filter hash count */, 18 4 /* Bloom filter hash count */,
19 PROBABILITY_75 /* Fake data probability */, 19 PROBABILITY_75 /* Fake data probability */,
20 PROBABILITY_50 /* Fake one probability */, 20 PROBABILITY_50 /* Fake one probability */,
21 PROBABILITY_75 /* One coin probability */, 21 PROBABILITY_75 /* One coin probability */,
22 PROBABILITY_50 /* Zero coin probability */}; 22 PROBABILITY_50 /* Zero coin probability */,
23 FINE_LEVEL /* Reporting level (not used) */};
23 24
24 const RapporParameters kTestStatsRapporParameters = { 25 const RapporParameters kTestStatsRapporParameters = {
25 1 /* Num cohorts */, 26 1 /* Num cohorts */,
26 50 /* Bloom filter size bytes */, 27 50 /* Bloom filter size bytes */,
27 4 /* Bloom filter hash count */, 28 4 /* Bloom filter hash count */,
28 PROBABILITY_75 /* Fake data probability */, 29 PROBABILITY_75 /* Fake data probability */,
29 PROBABILITY_50 /* Fake one probability */, 30 PROBABILITY_50 /* Fake one probability */,
30 PROBABILITY_75 /* One coin probability */, 31 PROBABILITY_75 /* One coin probability */,
31 PROBABILITY_50 /* Zero coin probability */}; 32 PROBABILITY_50 /* Zero coin probability */,
33 FINE_LEVEL /* Reporting level (not used) */};
32 34
33 // Check for basic syntax and use. 35 // Check for basic syntax and use.
34 TEST(RapporMetricTest, BasicMetric) { 36 TEST(RapporMetricTest, BasicMetric) {
35 RapporMetric testMetric("MyRappor", kTestRapporParameters, 0); 37 RapporMetric testMetric("MyRappor", kTestRapporParameters, 0);
36 testMetric.AddSample("Bar"); 38 testMetric.AddSample("Bar");
37 EXPECT_EQ(0x80, testMetric.bytes()[1]); 39 EXPECT_EQ(0x80, testMetric.bytes()[1]);
38 } 40 }
39 41
40 TEST(RapporMetricTest, GetReport) { 42 TEST(RapporMetricTest, GetReport) {
41 RapporMetric metric("MyRappor", kTestRapporParameters, 0); 43 RapporMetric metric("MyRappor", kTestRapporParameters, 0);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // stats.binom(152, 0.65625).ppf(0.999995) = 124 92 // stats.binom(152, 0.65625).ppf(0.999995) = 124
91 EXPECT_LE(true_from_true_count, 124); 93 EXPECT_LE(true_from_true_count, 124);
92 94
93 // stats.binom(248, 0.59375).ppf(.000005) = 113 95 // stats.binom(248, 0.59375).ppf(.000005) = 113
94 EXPECT_GT(true_from_false_count, 113); 96 EXPECT_GT(true_from_false_count, 113);
95 // stats.binom(248, 0.59375).ppf(.999995) = 181 97 // stats.binom(248, 0.59375).ppf(.999995) = 181
96 EXPECT_LE(true_from_false_count, 181); 98 EXPECT_LE(true_from_false_count, 181);
97 } 99 }
98 100
99 } // namespace rappor 101 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/rappor_metric.cc ('k') | components/rappor/rappor_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698