This source file includes following definitions.
- TEST
- TEST
#include "components/rappor/bloom_filter.h"
#include "components/rappor/byte_vector_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace rappor {
TEST(BloomFilterTest, TinyFilter) {
BloomFilter filter(1u, 4u, 0u);
EXPECT_EQ(1u, filter.bytes().size());
EXPECT_EQ(0x00, filter.bytes()[0]);
filter.AddString("Test");
EXPECT_EQ(0x2a, filter.bytes()[0]);
filter.AddString("Test");
EXPECT_EQ(0x2a, filter.bytes()[0]);
BloomFilter filter2(1u, 4u, 0u);
EXPECT_EQ(0x00, filter2.bytes()[0]);
filter2.AddString("Bar");
EXPECT_EQ(0xa8, filter2.bytes()[0]);
filter.AddString("Bar");
EXPECT_EQ(0xaa, filter.bytes()[0]);
}
TEST(BloomFilterTest, HugeFilter) {
BloomFilter filter(500u, 1u, 0xabdef123);
EXPECT_EQ(500u, filter.bytes().size());
EXPECT_EQ(0, CountBits(filter.bytes()));
filter.AddString("Bar");
EXPECT_EQ(1, CountBits(filter.bytes()));
filter.AddString("Bar");
EXPECT_EQ(1, CountBits(filter.bytes()));
}
}