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

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
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 "testing/gtest/include/gtest/gtest.h"
8
9 namespace rappor {
10
11 TEST(BloomFilterTest, TinyFilter) {
12 BloomFilter filter(1u, 4u, 0u);
13
14 // Size is 1 and it's initially empty
15 EXPECT_EQ(1u, filter.bytes().size());
16 EXPECT_EQ(0x00, filter.bytes()[0]);
17
18 // "Test" has a self-collision, and only sets 3 bits.
19 filter.AddString("Test");
20 EXPECT_EQ(0x2a, filter.bytes()[0]);
21
22 // Adding the same value shouldn't change anything.
23 filter.AddString("Test");
24 EXPECT_EQ(0x2a, filter.bytes()[0]);
25
26 BloomFilter filter2(1u, 4u, 0u);
27 EXPECT_EQ(0x00, filter2.bytes()[0]);
28 filter2.AddString("Bar");
29 EXPECT_EQ(0xa8, filter2.bytes()[0]);
30
31 // Adding a colliding string should just set new bits.
32 filter.AddString("Bar");
33 EXPECT_EQ(0xaa, filter.bytes()[0]);
34 }
35
36 TEST(BloomFilterTest, HugeFilter) {
37 BloomFilter filter(500u, 1u, 0u);
38
39 // Size is 500 and it's initially empty
40 EXPECT_EQ(500u, filter.bytes().size());
41 EXPECT_EQ(0, CountBits(filter.bytes()));
42
43 filter.AddString("Bar");
44 EXPECT_EQ(1, CountBits(filter.bytes()));
45
46 // Adding the same value shouldn't change anything.
47 filter.AddString("Bar");
48 EXPECT_EQ(1, CountBits(filter.bytes()));
Ilya Sherman 2014/02/13 01:39:03 nit: Please directly #include the header where Cou
Steven Holte 2014/02/13 05:11:12 Done.
49 }
50
51 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698