Skip to content

Instantly share code, notes, and snippets.

@inexplicable
Created April 2, 2013 03:34
Show Gist options
  • Save inexplicable/5289726 to your computer and use it in GitHub Desktop.
Save inexplicable/5289726 to your computer and use it in GitHub Desktop.
a unit test of #nextSetBit method using mocha & should.js
describe("#nextSetBit", function(){
var i = 0;
var bits = new BitSet();
it("should set 1 million times fast", function(done){
var begin = new Date().getTime();
for(var i = 0; i < 1000000; i += 1){
bits.set(i);
}
(new Date().getTime() - begin).should.be.below(50);
done();
});
it("should clear half a million times fast", function(done){
var begin = new Date().getTime();
for(var i = 0; i < 1000000; i += 2){
bits.clear(i);
}
(new Date().getTime() - begin).should.be.below(50);
done();
});
it("should nextSetBit fast", function(done){
var begin = new Date().getTime();
for(var i = 0; i < 1000000; i += 1){
(bits.nextSetBit(i)).should.equal(i & 1 ? i : i + 1);
}
(new Date().getTime() - begin).should.be.below(700);
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment