diff --git a/bloomfilter.js b/bloomfilter.js index eb81cbd..e3d1bae 100644 --- a/bloomfilter.js +++ b/bloomfilter.js @@ -42,7 +42,7 @@ }; BloomFilter.prototype.add = function(v) { - var l = this.locations(v), + var l = this.locations(v + ""), i = -1, k = this.k, buckets = this.buckets; @@ -50,7 +50,7 @@ }; BloomFilter.prototype.test = function(v) { - var l = this.locations(v), + var l = this.locations(v + ""), i = -1, k = this.k, b, diff --git a/test/bloomfilter-test.js b/test/bloomfilter-test.js index 73971fe..3b0675e 100644 --- a/test/bloomfilter-test.js +++ b/test/bloomfilter-test.js @@ -30,9 +30,9 @@ suite.addBatch({ }, "basic uint32": function() { var f = new BloomFilter(1000, 4), - n1 = "\u100", - n2 = "\u101", - n3 = "\u103"; + n1 = "\u0100", + n2 = "\u0101", + n3 = "\u0103"; f.add(n1); assert.equal(f.test(n1), true); assert.equal(f.test(n2), false); @@ -42,6 +42,12 @@ suite.addBatch({ var f = new BloomFilter(20, 10); f.add("abc"); assert.equal(f.test("wtf"), false); + }, + "works with integer types": function() { + var f = new BloomFilter(1000, 4); + f.add(1); + assert.equal(f.test(1), true); + assert.equal(f.test(2), false); } } });