Skip to content

Commit fbd4437

Browse files
committed
'more unit test for selection sort
1 parent f1e8735 commit fbd4437

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/jssort.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var jssort = jssort || {};
3434
}
3535
}
3636
};
37+
38+
jss.insertionSort = function(a, lo, hi, compare){
39+
40+
};
3741

3842
})(jssort);
3943

test/selection-sort-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,26 @@ describe("Selection Sort", function() {
1212
expect(a[i-1]).not.to.above(a[i]);
1313
}
1414
});
15+
16+
it("should sort ascedingly using the provided comparer", function() {
17+
18+
var a = [[3, 2.3], [4, 3.1], [5, 1.1], [1, 4.2], [2, 4.2], [4, 5.3], [6, 7.4], [8, 5.1], [9, 1.9], [3, 1.2], [4, 3.4], [67, 6.7], [34, 3], [53, 5], [44, 4.2], [2, 0]];
19+
jssort.selectionSort(a, undefined, undefined, function(a1, a2){
20+
return a1[1] - a2[1];
21+
});
22+
for(var i = 1; i < a.length; ++i){
23+
expect(a[i-1][1]).not.to.above(a[i][1]);
24+
}
25+
});
26+
27+
28+
it("should sort ascedingly partially from index 3 to index 10 when no compare function is provided", function() {
29+
30+
var a = [3, 4, 5, 1, 2, 4, 6, 8, 9, 3, 4, 67, 34, 53, 44, 2];
31+
jssort.selectionSort(a, 3, 10);
32+
for(var i = 4; i <= 10; ++i){
33+
expect(a[i-1]).not.to.above(a[i]);
34+
}
35+
});
1536
});
1637
});

0 commit comments

Comments
 (0)