Skip to content

Commit

Permalink
Add test cases for .bsearchIndex() find-any mode
Browse files Browse the repository at this point in the history
  • Loading branch information
arnellebalane committed Jan 31, 2019
1 parent da46fd9 commit 5a9db73
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions methods/bsearchIndex/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,27 @@ test('find-minimum mode: return null if no item makes the condition return true'
t.is(bsearchIndex([1], x => x < 0), null);
t.is(bsearchIndex([0, 4, 7, 10, 12], x => x >= 100), null);
});

test('find-any mode: return any item that makes the condition return 0', t => {
t.true([1, 2].includes(bsearchIndex(
[0, 4, 7, 10, 12],
x => 1 - Math.floor(x / 4)
)));

t.true([1].includes(bsearchIndex(
[1, 2, 3, 4, 5],
x => 2 - x
)));
});

test('find-any mode: return null if no item makes the condition return 0', t => {
t.is(bsearchIndex([1, 2, 3], () => 1), null);
t.is(bsearchIndex([1, 2, 3], () => -1), null);
t.is(
bsearchIndex(
[0, 4, 7, 10, 12],
x => 4 - Math.floor(x / 2)
),
null
);
});

0 comments on commit 5a9db73

Please sign in to comment.