コード例 #1
0
TEST(BloomFilterTest, NumEntriesAndFalsePositiveRate)
{
  BloomFilter* bf = BloomFilter::for_num_entries_and_fp_prob(2, 0.0001);

  bf->add("Kermit");
  bf->add("MissPiggy");

  EXPECT_TRUE(bf->check("Kermit"));
  EXPECT_TRUE(bf->check("MissPiggy"));
  EXPECT_FALSE(bf->check("Gonzo"));
  EXPECT_FALSE(bf->check("Animal"));

  delete bf; bf = nullptr;
}
コード例 #2
0
TEST(BloomFilterTest, JsonDeserialize3rdParty)
{
  // A bloom filter that conforms to the JSON API but was generated by an
  // independent 3rd party implementation. It contains the strings "Kermit" and
  // "MissPiggy".
  const std::string json =
    "{\"bitmap\":\"J+i5Mg==\",\"total_bits\":32,\"bits_per_entry\":12,"
     "\"hash0\":{\"k0\":6547054200929830170,\"k1\":9813628641652032020},"
     "\"hash1\":{\"k0\":15888472079188754020,\"k1\":14822504794822470401}}";

  BloomFilter* bf = BloomFilter::from_json(json);

  EXPECT_NE(bf, nullptr);
  EXPECT_TRUE(bf->check("Kermit"));
  EXPECT_TRUE(bf->check("MissPiggy"));
  EXPECT_FALSE(bf->check("Gonzo"));
  EXPECT_FALSE(bf->check("Animal"));

  delete bf; bf = nullptr;
}
コード例 #3
0
TEST(BloomFilterTest, JsonDeserializeExtraFields)
{
  // A bloom filter that contains some additional fields that our implementation
  // does not recognize. This should be accepted, as it represents a
  // backwards-compatible change to the filter.
  const std::string json =
    "{\"bitmap\":\"J+i5Mg==\",\"total_bits\":32,\"bits_per_entry\":12,"
     "\"hash0\":{\"k0\":6547054200929830170,\"k1\":9813628641652032020},"
     "\"hash1\":{\"k0\":15888472079188754020,\"k1\":14822504794822470401},"
     "\"future\": \"unknown\"}";

  BloomFilter* bf = BloomFilter::from_json(json);

  EXPECT_NE(bf, nullptr);
  EXPECT_TRUE(bf->check("Kermit"));
  EXPECT_TRUE(bf->check("MissPiggy"));
  EXPECT_FALSE(bf->check("Gonzo"));
  EXPECT_FALSE(bf->check("Animal"));

  delete bf; bf = nullptr;
}