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

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

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « components/rappor/bloom_filter.cc ('k') | components/rappor/byte_vector_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/rappor/bloom_filter.h"
6
7 #include "components/rappor/byte_vector_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace rappor {
11
12 TEST(BloomFilterTest, TinyFilter) {
13 BloomFilter filter(1u, 4u, 0u);
14
15 // Size is 1 and it's initially empty
16 EXPECT_EQ(1u, filter.bytes().size());
17 EXPECT_EQ(0x00, filter.bytes()[0]);
18
19 // "Test" has a self-collision, and only sets 3 bits.
20 filter.AddString("Test");
21 EXPECT_EQ(0x2a, filter.bytes()[0]);
22
23 // Adding the same value shouldn't change anything.
24 filter.AddString("Test");
25 EXPECT_EQ(0x2a, filter.bytes()[0]);
26
27 BloomFilter filter2(1u, 4u, 0u);
28 EXPECT_EQ(0x00, filter2.bytes()[0]);
29 filter2.AddString("Bar");
30 EXPECT_EQ(0xa8, filter2.bytes()[0]);
31
32 // Adding a colliding string should just set new bits.
33 filter.AddString("Bar");
34 EXPECT_EQ(0xaa, filter.bytes()[0]);
35 }
36
37 TEST(BloomFilterTest, HugeFilter) {
38 // Create a 500 bit filter, and use a large seed offset to see if anything
39 // breaks.
40 BloomFilter filter(500u, 1u, 0xabdef123);
41
42 // Size is 500 and it's initially empty
43 EXPECT_EQ(500u, filter.bytes().size());
44 EXPECT_EQ(0, CountBits(filter.bytes()));
45
46 filter.AddString("Bar");
47 EXPECT_EQ(1, CountBits(filter.bytes()));
48
49 // Adding the same value shouldn't change anything.
50 filter.AddString("Bar");
51 EXPECT_EQ(1, CountBits(filter.bytes()));
52 }
53
54 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/bloom_filter.cc ('k') | components/rappor/byte_vector_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698