Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit 2b36d27

Browse files
committed
feat(test): ✅ add test for binary search
1 parent 6b90bfa commit 2b36d27

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

__tests__/binarySearch.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { binarySearch } from '../src/binarySearch';
2+
import { compareNumbers } from '../src/compareNumbers';
3+
4+
describe('Binary search', () => {
5+
it('Search in array of numbers', () => {
6+
const ARRAY = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
7+
const SEARCH_ELEMENT = 3;
8+
const EXPECTED_INDEX = 3;
9+
10+
expect(binarySearch(ARRAY, SEARCH_ELEMENT, compareNumbers)).toBe(EXPECTED_INDEX);
11+
})
12+
it('Search near index', () => {
13+
const ARRAY = [0, 1, 2, 4, 5, 6, 7, 8, 9];
14+
const SEARCH_ELEMENT = 3;
15+
const EXPECTED_INDEX = 3;
16+
17+
expect(binarySearch(ARRAY, SEARCH_ELEMENT, compareNumbers, true)).toBe(EXPECTED_INDEX);
18+
})
19+
})

0 commit comments

Comments
 (0)