forked from SiZapPaaiGwat/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickselect.spec.js
More file actions
31 lines (24 loc) · 895 Bytes
/
quickselect.spec.js
File metadata and controls
31 lines (24 loc) · 895 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
29
30
31
var quickselect = require('../../src/searching/quickselect').quickselect;
describe('quickselect', function () {
'use strict';
it('should be defined as function', function () {
expect(typeof quickselect).toBe('function');
});
it('should work with empty array', function () {
expect(quickselect([], 1)).toBe(undefined);
});
it('should find the only element in the list', function () {
expect(quickselect([1], 0)).toBe(1);
});
it('should return undefined if the list is smaller than the index',
function () {
expect(quickselect([2, 1], 3)).toBeUndefined();
});
it('should find the element if in sorted order', function () {
expect(quickselect([1, 2], 0)).toBe(1);
expect(quickselect([1, 2], 1)).toBe(2);
});
it('should fine the element if not in sorted order', function () {
expect(quickselect([2, 1, 9, 6], 3)).toBe(9);
});
});