Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93bfe97

Browse files
committed
Add test cases for sorting negative numbers and zeros.
1 parentd82958d commit93bfe97

File tree

10 files changed

+40
-2
lines changed

10 files changed

+40
-2
lines changed

‎src/algorithms/sorting/SortTester.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const sortedArr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
22
exportconstreverseArr=[20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1];
33
exportconstnotSortedArr=[15,8,5,12,10,1,16,9,11,7,20,3,2,6,17,18,4,13,14,19];
44
exportconstequalArr=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
5+
exportconstnegativeArr=[-1,0,5,-10,20,13,-7,3,2,-3];
6+
exportconstnegativeArrSorted=[-10,-7,-3,-1,0,2,3,5,13,20];
57

68
exportclassSortTester{
79
statictestSort(SortingClass){
@@ -18,6 +20,11 @@ export class SortTester {
1820
expect(sorter.sort(equalArr)).toEqual(equalArr);
1921
}
2022

23+
statictestNegativeNumbersSort(SortingClass){
24+
constsorter=newSortingClass();
25+
expect(sorter.sort(negativeArr)).toEqual(negativeArrSorted);
26+
}
27+
2128
statictestSortWithCustomComparator(SortingClass){
2229
constcallbacks={
2330
compareCallback:(a,b)=>{

‎src/algorithms/sorting/bubble-sort/__test__/BubbleSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('BubbleSort', () => {
2626
SortTester.testSortStability(BubbleSort);
2727
});
2828

29+
it('should sort negative numbers',()=>{
30+
SortTester.testNegativeNumbersSort(BubbleSort);
31+
});
32+
2933
it('should visit EQUAL array element specified number of times',()=>{
3034
SortTester.testAlgorithmTimeComplexity(
3135
BubbleSort,

‎src/algorithms/sorting/counting-sort/CountingSort.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export default class CountingSort extends Sort {
66
*@param {number} [biggestElement]
77
*/
88
sort(originalArray,biggestElement=0){
9-
// Detect biggest element in array in order to build in order to build
10-
// number bucket array later.
9+
// Detect biggest element in array in order to build number bucket array later.
1110
letdetectedBiggestElement=biggestElement;
1211
if(!detectedBiggestElement){
1312
originalArray.forEach((element)=>{

‎src/algorithms/sorting/heap-sort/__test__/HeapSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ describe('HeapSort', () => {
2424
SortTester.testSortWithCustomComparator(HeapSort);
2525
});
2626

27+
it('should sort negative numbers',()=>{
28+
SortTester.testNegativeNumbersSort(HeapSort);
29+
});
30+
2731
it('should visit EQUAL array element specified number of times',()=>{
2832
SortTester.testAlgorithmTimeComplexity(
2933
HeapSort,

‎src/algorithms/sorting/insertion-sort/__test__/InsertionSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('InsertionSort', () => {
2626
SortTester.testSortStability(InsertionSort);
2727
});
2828

29+
it('should sort negative numbers',()=>{
30+
SortTester.testNegativeNumbersSort(InsertionSort);
31+
});
32+
2933
it('should visit EQUAL array element specified number of times',()=>{
3034
SortTester.testAlgorithmTimeComplexity(
3135
InsertionSort,

‎src/algorithms/sorting/merge-sort/__test__/MergeSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('MergeSort', () => {
2626
SortTester.testSortStability(MergeSort);
2727
});
2828

29+
it('should sort negative numbers',()=>{
30+
SortTester.testNegativeNumbersSort(MergeSort);
31+
});
32+
2933
it('should visit EQUAL array element specified number of times',()=>{
3034
SortTester.testAlgorithmTimeComplexity(
3135
MergeSort,

‎src/algorithms/sorting/quick-sort/__test__/QuickSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('QuickSort', () => {
2626
SortTester.testSortStability(QuickSort);
2727
});
2828

29+
it('should sort negative numbers',()=>{
30+
SortTester.testNegativeNumbersSort(QuickSort);
31+
});
32+
2933
it('should visit EQUAL array element specified number of times',()=>{
3034
SortTester.testAlgorithmTimeComplexity(
3135
QuickSort,

‎src/algorithms/sorting/quick-sort/__test__/QuickSortInPlace.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ describe('QuickSortInPlace', () => {
2222
SortTester.testSortWithCustomComparator(QuickSortInPlace);
2323
});
2424

25+
it('should sort negative numbers',()=>{
26+
SortTester.testNegativeNumbersSort(QuickSortInPlace);
27+
});
28+
2529
it('should visit EQUAL array element specified number of times',()=>{
2630
SortTester.testAlgorithmTimeComplexity(
2731
QuickSortInPlace,

‎src/algorithms/sorting/selection-sort/__test__/SelectionSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ describe('SelectionSort', () => {
2222
SortTester.testSortWithCustomComparator(SelectionSort);
2323
});
2424

25+
it('should sort negative numbers',()=>{
26+
SortTester.testNegativeNumbersSort(SelectionSort);
27+
});
28+
2529
it('should visit EQUAL array element specified number of times',()=>{
2630
SortTester.testAlgorithmTimeComplexity(
2731
SelectionSort,

‎src/algorithms/sorting/shell-sort/__test__/ShellSort.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ describe('ShellSort', () => {
2222
SortTester.testSortWithCustomComparator(ShellSort);
2323
});
2424

25+
it('should sort negative numbers',()=>{
26+
SortTester.testNegativeNumbersSort(ShellSort);
27+
});
28+
2529
it('should visit EQUAL array element specified number of times',()=>{
2630
SortTester.testAlgorithmTimeComplexity(
2731
ShellSort,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp