forked from benthemonkey/source-map
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest-quick-sort.js
45 lines (34 loc) · 1.15 KB
/
test-quick-sort.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*/
var quickSort = require('../lib/quick-sort').quickSort;
function numberCompare(a, b) {
return a - b;
}
exports['test sorting sorted array'] = function (assert) {
var ary = [0,1,2,3,4,5,6,7,8,9];
var quickSorted = ary.slice();
quickSort(quickSorted, numberCompare);
assert.equal(JSON.stringify(ary),
JSON.stringify(quickSorted));
};
exports['test sorting reverse-sorted array'] = function (assert) {
var ary = [9,8,7,6,5,4,3,2,1,0];
var quickSorted = ary.slice();
quickSort(quickSorted, numberCompare);
assert.equal(JSON.stringify(ary.sort(numberCompare)),
JSON.stringify(quickSorted));
};
exports['test sorting unsorted array'] = function (assert) {
var ary = [];
for (var i = 0; i < 10; i++) {
ary.push(Math.random());
}
var quickSorted = ary.slice();
quickSort(quickSorted, numberCompare);
assert.equal(JSON.stringify(ary.sort(numberCompare)),
JSON.stringify(quickSorted));
};