Skip to content

Commit 2f80d34

Browse files
committed
Add tests for quick select
1 parent 2dbfc5d commit 2f80d34

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/searching/quickselect.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var quickselect = require('../../src/searching/quickselect').quickselect;
2+
3+
describe('quickselect', function () {
4+
'use strict';
5+
6+
it('should be defined as function', function () {
7+
expect(typeof quickselect).toBe('function');
8+
});
9+
10+
it('should work with empty array', function () {
11+
expect(quickselect([], 1)).toBe(undefined);
12+
});
13+
14+
it('should find the only element in the list', function () {
15+
expect(quickselect([1], 0)).toBe(1);
16+
});
17+
18+
it('should return undefined if the list is smaller than the index',
19+
function () {
20+
expect(quickselect([2, 1], 3)).toBeUndefined();
21+
});
22+
23+
it('should find the element if in sorted order', function () {
24+
expect(quickselect([1, 2], 0)).toBe(1);
25+
expect(quickselect([1, 2], 1)).toBe(2);
26+
});
27+
28+
it('should fine the element if not in sorted order', function () {
29+
expect(quickselect([2, 1, 9, 6], 3)).toBe(9);
30+
});
31+
});

0 commit comments

Comments
 (0)