Created
April 2, 2013 03:34
-
-
Save inexplicable/5289726 to your computer and use it in GitHub Desktop.
a unit test of #nextSetBit method using mocha & should.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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