Example #1
0
        public void Add_WithCounterAtMaxValue_ShouldRemainConstant()
        {
            var filter = new CountingBloomFilter <int>(50, 0.01);

            while (filter.CounterAt(42) < byte.MaxValue)
            {
                filter.Add(42);
            }
            filter.Add(42); // one additional add to attempt to roll over byte.maxvalue
            Assert.True(filter.Contains(42));
        }
        public void Remove_RemovedItemIsNotPresent()
        {
            CountingBloomFilter bf = new CountingBloomFilter(10, 0.001);

            bf.Add("a");
            bf.Add("a");

            Assert.IsTrue(bf.IsPresent("a"));

            bf.Remove("a");

            Assert.IsFalse(bf.IsPresent("a"));
        }
Example #3
0
        public void Remove_WithItemInCollection_ShouldReturnTrue()
        {
            var filter = new CountingBloomFilter <int>(100, 0.2);

            filter.Add(27);
            Assert.True(filter.Remove(27));
        }
Example #4
0
        public void Contains_WhenItemHasBeenAdded_ShouldReturnTrue()
        {
            var filter = new CountingBloomFilter <int>(50, 0.02);

            filter.Add(42);
            Assert.True(filter.Contains(42));
        }
Example #5
0
        public void AddAndCheck_WhenItemHasBeenAddedBefore_ShouldReturnTrue()
        {
            var filter = new CountingBloomFilter <int>(50, 0.02);

            filter.Add(42);
            Assert.True(filter.AddAndCheck(42));
        }
Example #6
0
        public void Remove_WithItemInCollection_ShouldRemoveItemFromCollection()
        {
            var filter = new CountingBloomFilter <int>(100, 0.2);

            filter.Add(27);
            filter.Remove(27);
            Assert.False(filter.Contains(27));
        }
 public Property Remove_WithItemInCollection_ShouldReturnTrue()
 {
     return(Prop.ForAll(Arb.Default.Int32(), testData =>
     {
         var filter = new CountingBloomFilter <int>(100, 0.2, ByteConverter);
         filter.Add(testData);
         return filter.Remove(testData).ToProperty();
     }));
 }
 public Property Contains_WhenItemHasBeenAdded_ShouldReturnTrue()
 {
     return(Prop.ForAll(Arb.Default.Int32(), testData =>
     {
         var filter = new CountingBloomFilter <int>(50, 0.02, ByteConverter);
         filter.Add(testData);
         return filter.Contains(testData).ToProperty();
     }));
 }
 public Property AddAndCheck_WhenItemHasBeenAddedBefore_ShouldReturnTrue()
 {
     return(Prop.ForAll(Arb.Default.Int32(), testData =>
     {
         var filter = new CountingBloomFilter <int>(50, 0.02, ByteConverter);
         filter.Add(testData);
         (filter.AddAndCheck(testData)).ToProperty();
     }));
 }
Example #10
0
        public void CountingBloomFilter()
        {
            CountingBloomFilter <int> filter = new CountingBloomFilter <int>(10, 2);

            Assert.IsFalse(filter.Add(10));
            Assert.IsTrue(filter.Contains(10));
            Assert.IsTrue(filter.Remove(10));
            Assert.IsFalse(filter.Contains(10));
        }
        public void CountingBloomFilter()
        {
            CountingBloomFilter<int> filter = new CountingBloomFilter<int>(10, 2);

            Assert.IsFalse(filter.Add(10));
            Assert.IsTrue(filter.Contains(10));
            Assert.IsTrue(filter.Remove(10));
            Assert.IsFalse(filter.Contains(10));
        }
Example #12
0
        public void Contains_With5PercentFalsePositives_ShouldHaveLessThan5PercentErrors(int stepRange, double errorRate)
        {
            var filter = new CountingBloomFilter <int>(stepRange, errorRate);

            foreach (var num in Enumerable.Range(1, stepRange))
            {
                filter.Add(num);
            }

            var errorCount = Enumerable.Range(stepRange + 1, stepRange * 2).Count(num => filter.Contains(num));

            Assert.InRange(errorCount, 0d, errorRate * stepRange);
        }
Example #13
0
 public void Contains_WhenItemHasBeenAdded_AndFilterHasBeenSerializedAndUnserialized_ShouldReturnTrue()
 {
     using (var stream = new MemoryStream())
     {
         var filterOld = new CountingBloomFilter <int>(50, 0.02);
         filterOld.Add(42);
         IFormatter formatter = new BinaryFormatter();
         formatter.Serialize(stream, filterOld);
         stream.Flush();
         stream.Position = 0;
         CountingBloomFilter <int> filterNew = (CountingBloomFilter <int>)formatter.Deserialize(stream);
         Assert.True(filterNew.Contains(42));
     }
 }
 public Property Contains_With5PercentFalsePositives_ShouldHaveLessThan5PercentErrors()
 {
     return(Prop.ForAll(Arb.From(Gen.Choose(1, 5000)), Arb.From(Gen.Choose(1, 99)), (stepRange, errorRate) =>
     {
         var filter = new CountingBloomFilter <int>(stepRange, errorRate / 100d, ByteConverter);
         foreach (var num in Enumerable.Range(1, stepRange))
         {
             filter.Add(num);
         }
         var errorCount = Enumerable.Range(stepRange + 1, stepRange * 2).Count(num => filter.Contains(num));
         var highError = errorRate * stepRange;
         (0 <= errorCount && errorCount <= highError).ToProperty();
     }));
 }
Example #15
0
        public void RollbackWhenRemovingANonExistantItem()
        {
            var a = new CountingBloomFilter <int>(1000, 0.01f);

            for (var i = 0; i < 1000; i++)
            {
                a.Add(i);
            }

            byte[] copy = (byte[])a.Array.Clone();

            Assert.IsFalse(a.Remove(1001));

            for (int i = 0; i < a.Array.Length; i++)
            {
                Assert.AreEqual(a.Array[i], copy[i]);
            }
        }
        public void Remove_RemovedItemIsNotPresent()
        {
            CountingBloomFilter bf = new CountingBloomFilter(10, 0.001);
            bf.Add("a");
            bf.Add("a");

            Assert.IsTrue(bf.IsPresent("a"));

            bf.Remove("a");

            Assert.IsFalse(bf.IsPresent("a"));
        }