Skip to content

Commit 47da00e

Browse files
committed
Improve coverage
1 parent 9143da7 commit 47da00e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/search/binary.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ module.exports = binary;
2323
function binary(array, value) {
2424
var low = -1;
2525
var high = array.length;
26+
var midpoint;
2627

2728
while (high - low > 1) {
28-
var midpoint = high + low >> 1;
29+
midpoint = high + low >> 1;
2930

3031
if (array[midpoint] > value) {
3132
high = midpoint;
3233
} else if (array[midpoint] < value) {
3334
low = midpoint;
3435
} else {
35-
return array[midpoint] === value ? value : undefined;
36+
break
3637
}
3738
}
39+
40+
return array[midpoint] === value ? value : undefined;
3841
}

lib/search/test/binary-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var test = require('tape');
22
var binary = require('../binary');
33

44
test('binary(array, value)', function (t) {
5+
t.equal(binary([]), undefined, 'should return undefined');
6+
t.equal(binary([1, 10], 0), undefined, 'should return undefined');
57
t.equal(binary([1, 2, 3, 4, 5], 3), 3, 'should return 3');
68
t.equal(binary(['a', 'b', 'c', 'd', 'e', 'f'], 'd'), 'd', 'should return d');
79
t.end();

lib/search/test/linear-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var test = require('tape');
22
var linear = require('../linear');
33

44
test('linear(array, value)', function (t) {
5+
t.equal(linear([]), undefined, 'should return undefined');
6+
t.equal(linear([1, 10], 0), undefined, 'should return undefined');
57
t.equal(linear([1, 2, 3, 4, 5], 3), 3, 'should return 3');
68
t.equal(linear(['c', 'a', 'b'], 'a'), 'a', 'should return a');
79
t.equal(linear(['foo', 'bar', 'baz'], 'foo'), 'foo', 'should return foo');

0 commit comments

Comments
 (0)