mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00
merge: Add test case and fix HeapSort Algorithm (#969)
This commit is contained in:
@ -38,4 +38,5 @@ export function heapSort (input) {
|
||||
|
||||
heapRoot(input, 0)
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
19
Sorts/test/HeapSortV2.test.js
Normal file
19
Sorts/test/HeapSortV2.test.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { heapSort } from '../HeapSortV2'
|
||||
|
||||
test('The heapSort of the array [4, 3, 2, 1] is [1, 2, 3, 4]', () => {
|
||||
const arr = [4, 3, 2, 1]
|
||||
const res = heapSort(arr)
|
||||
expect(res).toEqual([1, 2, 3, 4])
|
||||
})
|
||||
|
||||
test('The heapSort of the array [] is []', () => {
|
||||
const arr = []
|
||||
const res = heapSort(arr)
|
||||
expect(res).toEqual([])
|
||||
})
|
||||
|
||||
test('The heapSort of the array [41, 31, 32, 31] is [31, 31, 32, 41]', () => {
|
||||
const arr = [41, 31, 32, 31]
|
||||
const res = heapSort(arr)
|
||||
expect(res).toEqual([31, 31, 32, 41])
|
||||
})
|
Reference in New Issue
Block a user