forked from exercism/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-search.spec.js
More file actions
27 lines (21 loc) · 959 Bytes
/
Copy pathbinary-search.spec.js
File metadata and controls
27 lines (21 loc) · 959 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
import { BinarySearch } from './binary-search';
describe('BinarySearch', () => {
const sortedArray = [1, 2, 3, 4, 5, 6];
const sortedArrayOfOddLength = [0, 1, 2, 2, 3, 10, 12];
const unsortedArray = [10, 2, 5, 1];
it('should require a sorted array', () => {
const invalidBinarySearch = new BinarySearch(unsortedArray);
const validBinarySearch = new BinarySearch(sortedArray);
expect(typeof invalidBinarySearch.array).toEqual('undefined');
expect(Array.isArray(validBinarySearch.array)).toEqual(true);
});
xtest('should find the correct index of an included value', () => {
expect(new BinarySearch(sortedArray).indexOf(3)).toEqual(2);
});
xtest('should search the middle of the array', () => {
expect(new BinarySearch(sortedArrayOfOddLength).indexOf(2)).toEqual(3);
});
xtest('should return -1 for a value not in the array', () => {
expect(new BinarySearch(sortedArray).indexOf(10)).toEqual(-1);
});
});