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

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

Issue 419683014: Randomly select a single rappor sample when more than one is collected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 RapporMetric metric("MyRappor", kTestRapporParameters, 0); 42 RapporMetric metric("MyRappor", kTestRapporParameters, 0);
43 43
44 const ByteVector report = metric.GetReport( 44 const ByteVector report = metric.GetReport(
45 HmacByteVectorGenerator::GenerateEntropyInput()); 45 HmacByteVectorGenerator::GenerateEntropyInput());
46 EXPECT_EQ(16u, report.size()); 46 EXPECT_EQ(16u, report.size());
47 } 47 }
48 48
49 TEST(RapporMetricTest, GetReportStatistics) { 49 TEST(RapporMetricTest, GetReportStatistics) {
50 RapporMetric metric("MyStatsRappor", kTestStatsRapporParameters, 0); 50 RapporMetric metric("MyStatsRappor", kTestStatsRapporParameters, 0);
51 51
52 for (char i = 0; i < 50; i++) { 52 ByteVector real_bits(kTestStatsRapporParameters.bloom_filter_size_bytes);
53 metric.AddSample(base::StringPrintf("%d", i)); 53 // Set 152 bits (19 bytes)
54 for (char i = 0; i < 19; i++) {
55 real_bits[i] = 0xff;
54 } 56 }
55 const ByteVector real_bits = metric.bytes(); 57 metric.SetBytesForTesting(real_bits);
56 const int real_bit_count = CountBits(real_bits); 58 const int real_bit_count = CountBits(real_bits);
57 EXPECT_EQ(real_bit_count, 152); 59 EXPECT_EQ(real_bit_count, 152);
58 60
59 const std::string secret = HmacByteVectorGenerator::GenerateEntropyInput(); 61 const std::string secret = HmacByteVectorGenerator::GenerateEntropyInput();
60 const ByteVector report = metric.GetReport(secret); 62 const ByteVector report = metric.GetReport(secret);
61 63
62 // For the bits we actually set in the Bloom filter, get a count of how 64 // For the bits we actually set in the Bloom filter, get a count of how
63 // many of them reported true. 65 // many of them reported true.
64 ByteVector from_true_reports = report; 66 ByteVector from_true_reports = report;
65 // Real bits AND report bits. 67 // Real bits AND report bits.
(...skipping 23 matching lines...) Expand all
89 // stats.binom(152, 0.65625).ppf(0.999995) = 124 91 // stats.binom(152, 0.65625).ppf(0.999995) = 124
90 EXPECT_LE(true_from_true_count, 124); 92 EXPECT_LE(true_from_true_count, 124);
91 93
92 // stats.binom(248, 0.59375).ppf(.000005) = 113 94 // stats.binom(248, 0.59375).ppf(.000005) = 113
93 EXPECT_GT(true_from_false_count, 113); 95 EXPECT_GT(true_from_false_count, 113);
94 // stats.binom(248, 0.59375).ppf(.999995) = 181 96 // stats.binom(248, 0.59375).ppf(.999995) = 181
95 EXPECT_LE(true_from_false_count, 181); 97 EXPECT_LE(true_from_false_count, 181);
96 } 98 }
97 99
98 } // namespace rappor 100 } // namespace rappor
OLDNEW
« components/rappor/rappor_metric.cc ('K') | « components/rappor/rappor_metric.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698