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)); }
public void Contains_WhenItemHasBeenAdded_ShouldReturnTrue() { var filter = new CountingBloomFilter <int>(50, 0.02); filter.Add(42); Assert.True(filter.Contains(42)); }
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 Contains_WithFreshFilter_ShouldReturnFalse() { return(Prop.ForAll(Arb.Default.Int32(), testData => { var filter = new CountingBloomFilter <int>(50, 0.02, ByteConverter); return (!filter.Contains(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 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 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 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); }
public void Contains_WithFreshFilter_ShouldReturnFalse() { var filter = new CountingBloomFilter <int>(50, 0.02); Assert.False(filter.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(); })); }