-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinarySearch.test.js
33 lines (31 loc) · 1006 Bytes
/
binarySearch.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { lowerBound, upperBound } = require('./binarySearch');
describe('lowerBound', () => {
test.each`
arr | target | expected
${[1, 2, 3]} | ${2} | ${1}
${[1, 2, 3]} | ${2.5} | ${2}
${[]} | ${2} | ${0}
${[1, 2, 2, 2, 2, 3]} | ${2} | ${1}
${[1, 2, 3]} | ${-1} | ${0}
${[1, 2, 3]} | ${4} | ${3}
`(
'lowerBound($arr, $target) returns $expected',
({ arr, target, expected }) =>
expect(lowerBound(arr, target)).toBe(expected)
);
});
describe('upperBound', () => {
test.each`
arr | target | expected
${[1, 2, 3]} | ${2} | ${2}
${[1, 2, 3]} | ${2.5} | ${2}
${[]} | ${2} | ${0}
${[1, 2, 2, 2, 2, 3]} | ${2} | ${5}
${[1, 2, 3]} | ${-1} | ${0}
${[1, 2, 3]} | ${4} | ${3}
`(
'upperBound($arr, $target) returns $expected',
({ arr, target, expected }) =>
expect(upperBound(arr, target)).toBe(expected)
);
});