Sha256: 800b8a3415544fac3a50ed96c945fef2dd4e8973ca7c73330346ffc149c9e399

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 KB

Contents

require 'test_helper'

class BloomFilterTest < Test::Unit::TestCase
  context "with a bloom filter" do
    setup do
      @bloom_filter = BloomFilter.new(1000, 3)
    end
    
    should "not claim anything is in the set when its empty" do
      assert !@bloom_filter.include?("hello world")
    end
    
    should "claim an item we just added is in the set" do
      @bloom_filter.add("hello world")
      assert @bloom_filter.include?("hello world")
    end
    
    should "dump into a string" do
      assert @bloom_filter.dump.is_a?(String)
    end
    
    should "a loaded set should claim the element we just added is in the set" do
      @bloom_filter.add("hello world")
      loaded = BloomFilter.load(@bloom_filter.dump)
      assert loaded.include?("hello world")
    end
    
    should "replace itself with another filter" do
      @bloom_filter.add("hello world")
      replacement = BloomFilter.new(1000, 3)
      io = StringIO.new(replacement.dump)
      @bloom_filter.replace(io)
      assert !@bloom_filter.include?("hello world")
    end
    
    should "allow chaining of adding" do
      @bloom_filter << "hello" << "world"
      assert @bloom_filter.include?("hello")
      assert @bloom_filter.include?("world")
    end
    
    should "intersect with an array" do
      @bloom_filter << "hello" << "world"
      assert_equal ["hello", "world"], @bloom_filter & ["hello", "world", "bye", "moon"]
    end
  end
  
  should "create a new filter from the dumped file of another" do
    bloom_filter = BloomFilter.new(1000, 3)
    bloom_filter.add("hello world")
    bloom_filter_2 = BloomFilter.load(bloom_filter.dump)
    assert bloom_filter_2.include?("hello world")
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bloom_filter-0.6.6 test/bloom_filter_test.rb
bloom_filter-0.6.5 test/bloom_filter_test.rb
bloom_filter-0.6.4 test/bloom_filter_test.rb
bloom_filter-0.6.3 test/bloom_filter_test.rb
bloom_filter-0.6.2 test/bloom_filter_test.rb
bloom_filter-0.6.1 test/bloom_filter_test.rb
bloom_filter-0.6.0 test/bloom_filter_test.rb