Exemple #1
0
        public void Contains_WhenItemHasBeenAdded_ShouldReturnTrue()
        {
            var filter = BloomFilter <int> .Create(50, 0.02);

            filter.Add(42);
            Assert.True(filter.Contains(42));
        }
Exemple #2
0
        public void Contains_With5PercentFalsePositives_ShouldHaveLessThan5PercentErrors(int stepRange, double errorRate)
        {
            var filter = BloomFilter <int> .Create(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);
        }
Exemple #3
0
        public void Contains_WhenItemHasBeenAdded_AndFilterHasBeenSerializedAndUnserialized_ShouldReturnTrue()
        {
            using (var stream = new MemoryStream())
            {
                var filterOld = BloomFilter <int> .Create(50, 0.02);

                filterOld.Add(42);
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, filterOld);
                stream.Flush();
                stream.Position = 0;
                BloomFilter <int> filterNew = (BloomFilter <int>)formatter.Deserialize(stream);
                Assert.True(filterNew.Contains(42));
            }
        }
Exemple #4
0
        public void FillRatio_WithNewFilter_ShouldBeZero()
        {
            var filter = BloomFilter <int> .Create(1000, 0.05);

            Assert.Equal(0d, filter.FillRatio);
        }
Exemple #5
0
        public void Contains_WithFreshFilter_ShouldReturnFalse()
        {
            var filter = BloomFilter <int> .Create(50, 0.02);

            Assert.False(filter.Contains(42));
        }
Exemple #6
0
        public void Create_WithValidParameters_ShouldReturnBloomFilter()
        {
            var filter = BloomFilter <int> .Create(50, 0.03, ByteConverter);

            Assert.NotNull(filter);
        }
Exemple #7
0
 public void Create_WithErrorRateGreaterThanOne_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => BloomFilter <int> .Create(100, 5, ByteConverter));
 }
Exemple #8
0
 public void Create_WithNegativeExpectedSize_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => BloomFilter <int> .Create(-100, 0.5, ByteConverter));
 }
Exemple #9
0
 public void Create_WithErrorRateLessThanZero_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => BloomFilter <int> .Create(100, -5));
 }
Exemple #10
0
 public void Create_WithZeroExpectedSize_ShouldThrowArgumentException()
 {
     Assert.Throws <ArgumentException>(() => BloomFilter <int> .Create(0, 0.5));
 }