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

Commit 42faf96

Browse files
committed
Start Rewriting
1 parent e469e09 commit 42faf96

16 files changed

+196
-355
lines changed

Diff for: __tests__/SortedArray.spec.ts

-88
This file was deleted.

Diff for: __tests__/binarySearch.spec.ts

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
import { binarySearch } from '../src/binarySearch';
2-
import { compareNumbers } from '../src/compareNumbers';
1+
import { binarySearch, defaultComparator } from '../src/helpers';
32

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;
3+
describe('Binary search function', () => {
4+
it('Should return [1, true]', () => {
5+
const EXPECTED_INDEX = 1;
6+
const [index, found] = binarySearch(
7+
[1, 2, 3, 4, 5],
8+
2,
9+
defaultComparator,
10+
);
911

10-
expect(binarySearch(ARRAY, SEARCH_ELEMENT, compareNumbers)).toBe(EXPECTED_INDEX);
12+
expect(index).toBe(EXPECTED_INDEX);
13+
expect(found).toBeTruthy();
1114
})
12-
it('Search near index', () => {
13-
const ARRAY = [0, 1, 2, 4, 5, 6, 7, 8, 9];
14-
const SEARCH_ELEMENT = 3;
15+
16+
it('Should return [-1, false]', () => {
17+
const EXPECTED_INDEX = -1;
18+
const [index, found] = binarySearch(
19+
[1, 2, 3, 4, 5],
20+
10,
21+
defaultComparator,
22+
);
23+
24+
expect(index).toBe(EXPECTED_INDEX);
25+
expect(found).toBeFalsy();
26+
})
27+
28+
it('Should return index of nearest element', () => {
1529
const EXPECTED_INDEX = 3;
30+
const [index, found] = binarySearch(
31+
[1, 2, 3, 5, 6],
32+
4,
33+
defaultComparator,
34+
true,
35+
);
1636

17-
expect(binarySearch(ARRAY, SEARCH_ELEMENT, compareNumbers, true)).toBe(EXPECTED_INDEX);
37+
expect(index).toBe(EXPECTED_INDEX);
38+
expect(found).toBeFalsy();
1839
})
19-
})
40+
})

Diff for: __tests__/bubbleSort.spec.ts

-11
This file was deleted.

Diff for: __tests__/insertion.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SortedArray } from '../src/SortedArray';
2+
import { defaultComparator } from "../src/helpers";
3+
4+
describe('Insertion in sorted array', () => {
5+
const sortedArray = new SortedArray([1, 3, 4], defaultComparator);
6+
7+
it('', () => {
8+
const EXPECTED_INDEX = 1;
9+
const index = sortedArray.insert(2);
10+
11+
expect(index).toBe(EXPECTED_INDEX);
12+
})
13+
})

0 commit comments

Comments
 (0)