Permalink
Browse files

Merge pull request #14 from billywatson/use_better_error_message

use BloomFilter::NotSameConfigurationError instead of ArgumentError
  • Loading branch information...
2 parents ba20cc9 + 76c1dcd commit 3cc543a46abf4c9ab24a9060288464e043a7c62f @igrigorik igrigorik committed Apr 27, 2012
Showing with 6 additions and 4 deletions.
  1. +5 −3 lib/bloomfilter/native.rb
  2. +1 −1 spec/native_spec.rb
@@ -1,7 +1,9 @@
module BloomFilter
+ BloomFilter::ConfigurationMismatch = Class.new(ArgumentError)
+
class Native < Filter
attr_reader :bf
-
+
def initialize(opts = {})
@opts = {
:size => 100,
@@ -45,7 +47,7 @@ def set_bits
# It assumes that both filters have the same size -
# if this is not true +ArgumentError+ is raised.
def &(o)
- raise ArgumentError.new() unless same_parameters?(o)
+ raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
result.instance_variable_set(:@bf,@bf.&(o.bf))
result
@@ -55,7 +57,7 @@ def &(o)
# It assumes that both filters have the same size -
# if this is not true +ArgumentError+ is raised.
def |(o)
- raise ArgumentError.new() unless same_parameters?(o)
+ raise BloomFilter::ConfigurationMismatch.new unless same_parameters?(o)
result = self.class.new
result.instance_variable_set(:@bf,@bf.|(o.bf))
result
View
@@ -78,7 +78,7 @@
bf2 = Native.new(:size => 20)
bf2.insert("test")
- proc {bf1 & bf2}.should raise_error(ArgumentError)
+ proc {bf1 & bf2}.should raise_error(BloomFilter::ConfigurationMismatch)
end
it "should return union with other filter" do

0 comments on commit 3cc543a

Please sign in to comment.