示例#1
0
        public void TestDeletableTestAndRemove()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

            // 'a' is not in the filter.
            if (d.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }

            d.Add(A_BYTES);

            // 'a' is now in the filter.
            if (!d.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'a' is no longer in the filter.
            if (d.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }
        }
示例#2
0
        public void TestDeletableTestAndAdd()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

            // 'a' is not in the filter.
            if (d.Test(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }

            var addedF = d.Add(A_BYTES);

            Assert.AreSame(d, addedF, "Returned CountingBloomFilter should be the same instance");

            // 'a' is now in the filter.
            if (!d.Test(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'a' is still in the filter.
            if (!d.TestAndAdd(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'b' is not in the filter.
            if (d.TestAndAdd(B_BYTES))
            {
                Assert.Fail("'b' should not be a member");
            }

            // 'a' is still in the filter.
            if (!d.Test(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'b' is now in the filter.
            if (!d.Test(B_BYTES))
            {
                Assert.Fail("'b' should be a member");
            }

            // 'c' is not in the filter.
            if (d.Test(C_BYTES))
            {
                Assert.Fail("'c' should not be a member");
            }

            for (int i = 0; i < 1000000; i++)
            {
                d.TestAndAdd(Encoding.ASCII.GetBytes(i.ToString()));
            }

            // 'x' should be a false positive.
            if (!d.Test(X_BYTES))
            {
                Assert.Fail("'x' should be a member");
            }
        }