Skip to content

Commit 8fed565

Browse files
committed
add tests for javascript quick-sort
1 parent e3995fc commit 8fed565

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/javascript/quick-sort.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ var assert = require('assert');
44
var quickSort = require('../../solutions/javascript/quick-sort');
55

66
describe('Quick Sort', function(){
7-
var unsorted = [9, 8, 7, 6, 5, 4, 3, 2, 1];
8-
var sorted = [1, 2, 3, 4, 5, 6, 7, 8, 9];
7+
8+
it('handles empty list', function() {
9+
var results = quickSort([]);
10+
assert(Array.isArray(results), 'Expected result to be array');
11+
assert(results.length === 0, 'Expected array to be empty');
12+
});
13+
14+
it('handles list of one', function() {
15+
var results = quickSort([1]);
16+
assert.deepEqual(results, [1], 'Expected arrays to match');
17+
});
918

1019
it('sorts an array of numbers', function() {
20+
var unsorted = [9, 8, 7, 6, 5, 4, 3, 2, 1];
21+
var sorted = [1, 2, 3, 4, 5, 6, 7, 8, 9];
1122
var results = quickSort(unsorted);
1223
assert.deepEqual(results, sorted, 'Expected arrays to match');
1324
});
@@ -20,4 +31,11 @@ describe('Quick Sort', function(){
2031
assert.deepEqual(results, sorted, 'Expected arrays to match');
2132
});
2233

34+
it('leaves input array intact', function() {
35+
var words = ['apple','beta','carrot'];
36+
quickSort(words);
37+
assert(words.length === 3);
38+
});
39+
40+
2341
});

0 commit comments

Comments
 (0)