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

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

Issue 188103004: C++ Readability review for holte (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed comments Created 6 years, 9 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 // Change for readability
6
5 #include "components/rappor/rappor_metric.h" 7 #include "components/rappor/rappor_metric.h"
6 8
7 #include <stdlib.h> 9 #include <stdlib.h>
8 10
9 #include "base/rand_util.h" 11 #include "base/rand_util.h"
10 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 14
13 namespace rappor { 15 namespace rappor {
14 16
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 for (char i = 0; i < 50; i++) { 54 for (char i = 0; i < 50; i++) {
53 metric.AddSample(base::StringPrintf("%d", i)); 55 metric.AddSample(base::StringPrintf("%d", i));
54 } 56 }
55 ByteVector real_bits = metric.bytes(); 57 ByteVector real_bits = metric.bytes();
56 int real_bit_count = CountBits(real_bits); 58 int real_bit_count = CountBits(real_bits);
57 EXPECT_EQ(real_bit_count, 152); 59 EXPECT_EQ(real_bit_count, 152);
58 60
59 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput(); 61 std::string secret = HmacByteVectorGenerator::GenerateEntropyInput();
60 ByteVector report = metric.GetReport(secret); 62 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.
66 ByteVectorMerge(real_bits, real_bits, &from_true_reports); 68 ByteVectorMerge(real_bits, real_bits, &from_true_reports);
67 int true_from_true_count = CountBits(from_true_reports); 69 int true_from_true_count = CountBits(from_true_reports);
68 70
69 // For the bits we didn't set in the bloom filter, get a count of how 71 // For the bits we didn't set in the Bloom filter, get a count of how
70 // many of them reported true. 72 // many of them reported true.
71 ByteVector from_false_reports = report; 73 ByteVector from_false_reports = report;
72 ByteVectorOr(real_bits, &from_false_reports); 74 ByteVectorOr(real_bits, &from_false_reports);
73 int true_from_false_count = CountBits(from_false_reports) - real_bit_count; 75 int true_from_false_count = CountBits(from_false_reports) - real_bit_count;
74 76
75 // The probability of a true bit being true after redaction = 77 // The probability of a true bit being true after redaction =
76 // [fake_prob]*[fake_true_prob] + (1-[fake_prob]) = 78 // [fake_prob]*[fake_true_prob] + (1-[fake_prob]) =
77 // .75 * .5 + (1-.75) = .625 79 // .75 * .5 + (1-.75) = .625
78 // The probablity of a false bit being true after redaction = 80 // The probablity of a false bit being true after redaction =
79 // [fake_prob]*[fake_true_prob] = .375 81 // [fake_prob]*[fake_true_prob] = .375
80 // The probability of a bit reporting true = 82 // The probability of a bit reporting true =
81 // [redacted_prob] * [one_coin_prob:.75] + 83 // [redacted_prob] * [one_coin_prob:.75] +
82 // (1-[redacted_prob]) * [zero_coin_prob:.5] = 84 // (1-[redacted_prob]) * [zero_coin_prob:.5] =
83 // 0.65625 for true bits 85 // 0.65625 for true bits
84 // 0.59375 for false bits 86 // 0.59375 for false bits
85 87
86 // stats.binom(152, 0.65625).ppf(0.000005) = 73 88 // stats.binom(152, 0.65625).ppf(0.000005) = 73
87 EXPECT_GT(true_from_true_count, 73); 89 EXPECT_GT(true_from_true_count, 73);
88 // stats.binom(152, 0.65625).ppf(0.999995) = 124 90 // stats.binom(152, 0.65625).ppf(0.999995) = 124
89 EXPECT_LE(true_from_true_count, 124); 91 EXPECT_LE(true_from_true_count, 124);
90 92
91 // stats.binom(248, 0.59375).ppf(.000005) = 113 93 // stats.binom(248, 0.59375).ppf(.000005) = 113
92 EXPECT_GT(true_from_false_count, 113); 94 EXPECT_GT(true_from_false_count, 113);
93 // stats.binom(248, 0.59375).ppf(.999995) = 181 95 // stats.binom(248, 0.59375).ppf(.999995) = 181
94 EXPECT_LE(true_from_false_count, 181); 96 EXPECT_LE(true_from_false_count, 181);
95 } 97 }
96 98
97 } // namespace rappor 99 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698