-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathMetaBinarySearch.test.js
More file actions
28 lines (23 loc) · 867 Bytes
/
MetaBinarySearch.test.js
File metadata and controls
28 lines (23 loc) · 867 Bytes
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
import { metaBinarySearch } from '../MetaBinarySearch'
describe('Meta Binary Search', () => {
test('returns index for found numeric element', () => {
expect(metaBinarySearch([2, 5, 8, 12, 16, 23, 38], 23)).toBe(5)
})
test('returns -1 when numeric element is missing', () => {
expect(metaBinarySearch([2, 5, 8, 12, 16, 23, 38], 9)).toBe(-1)
})
test('works with sorted strings', () => {
expect(metaBinarySearch(['alpha', 'beta', 'delta', 'omega'], 'delta')).toBe(
2
)
})
test('returns index for a matching element in a single-element array', () => {
expect(metaBinarySearch([7], 7)).toBe(0)
})
test('returns -1 on empty input', () => {
expect(metaBinarySearch([], 1)).toBe(-1)
})
test('returns index for a matching element in a single-element array', () => {
expect(metaBinarySearch([7], 7)).toBe(0)
})
})