Skip to content

Commit d47555b

Browse files
authored
merge: Add test case and fix HeapSort Algorithm (#969)
1 parent c21ad2c commit d47555b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sorts/HeapSortV2.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export function heapSort (input) {
3838

3939
heapRoot(input, 0)
4040
}
41+
return input
4142
}

Sorts/test/HeapSortV2.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { heapSort } from '../HeapSortV2'
2+
3+
test('The heapSort of the array [4, 3, 2, 1] is [1, 2, 3, 4]', () => {
4+
const arr = [4, 3, 2, 1]
5+
const res = heapSort(arr)
6+
expect(res).toEqual([1, 2, 3, 4])
7+
})
8+
9+
test('The heapSort of the array [] is []', () => {
10+
const arr = []
11+
const res = heapSort(arr)
12+
expect(res).toEqual([])
13+
})
14+
15+
test('The heapSort of the array [41, 31, 32, 31] is [31, 31, 32, 41]', () => {
16+
const arr = [41, 31, 32, 31]
17+
const res = heapSort(arr)
18+
expect(res).toEqual([31, 31, 32, 41])
19+
})

0 commit comments

Comments
 (0)