mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
_.barrier + tests
This commit is contained in:
@@ -137,4 +137,22 @@ $(document).ready(function() {
|
||||
equals(composed('moe'), 'hi: moe!', 'in this case, the functions are also commutative');
|
||||
});
|
||||
|
||||
test("functions: barrier", function() {
|
||||
var testBarrier = function(barrierAmount, timesCalled) {
|
||||
var barrierCalled = 0;
|
||||
var barrier = _.barrier(function(){ barrierCalled++; }, barrierAmount);
|
||||
|
||||
|
||||
while (timesCalled--) {
|
||||
barrier();
|
||||
}
|
||||
|
||||
return barrierCalled;
|
||||
}
|
||||
|
||||
equals(testBarrier(5, 5), 1, "barrier(N) should fire after being called N times");
|
||||
equals(testBarrier(5, 4), 0, "barrier(N) should not fire unless called N times");
|
||||
equals(testBarrier(5, 6), 1, "barrier(N) should fire only once even if called more than N times");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user