Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / comparefn-sort-stability.js
blob5cdab104f844c430697dda3bf28dec544ccd900d
1 description(
2 "This tests that sort(compareFn) is a stable sort."
3 );
5 function clone(source, target) {
6 for (i = 0; i < source.length; i++) {
7 target[i] = source[i];
11 var arr = [];
12 arr[0] = new Number(1);
13 arr[1] = new Number(2);
14 arr[2] = new Number(1);
15 arr[3] = new Number(2);
17 var sortArr = [];
18 clone(arr, sortArr);
19 sortArr.sort(function(a,b) { return a - b; });
21 shouldBe('arr[0]', 'sortArr[0]');
22 shouldBe('arr[1]', 'sortArr[2]');
23 shouldBe('arr[2]', 'sortArr[1]');
24 shouldBe('arr[3]', 'sortArr[3]');
26 // Just try again...
27 sortArr.sort(function(a,b) { return a - b; });
28 shouldBe('arr[0]', 'sortArr[0]');
29 shouldBe('arr[1]', 'sortArr[2]');
30 shouldBe('arr[2]', 'sortArr[1]');
31 shouldBe('arr[3]', 'sortArr[3]');