예제 #1
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));
        }
예제 #2
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));
        }
예제 #3
0
        public void Contains_WhenItemHasBeenAdded_ShouldReturnTrue()
        {
            var filter = new CountingBloomFilter <int>(50, 0.02);

            filter.Add(42);
            Assert.True(filter.Contains(42));
        }
예제 #4
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));
        }
예제 #5
0
 public Property Contains_WithFreshFilter_ShouldReturnFalse()
 {
     return(Prop.ForAll(Arb.Default.Int32(), testData =>
     {
         var filter = new CountingBloomFilter <int>(50, 0.02, ByteConverter);
         return (!filter.Contains(testData)).ToProperty();
     }));
 }
예제 #6
0
 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();
     }));
 }
예제 #7
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));
        }
예제 #8
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));
     }
 }
예제 #9
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);
        }
예제 #10
0
        public void Contains_WithFreshFilter_ShouldReturnFalse()
        {
            var filter = new CountingBloomFilter <int>(50, 0.02);

            Assert.False(filter.Contains(42));
        }
예제 #11
0
 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();
     }));
 }