mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
merge: Add test case and fix pigeonHoleSort Algorithm (#967)
This commit is contained in:
@ -29,4 +29,5 @@ export function pigeonHoleSort (arr) {
|
|||||||
arr[index++] = j + min
|
arr[index++] = j + min
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return arr
|
||||||
}
|
}
|
||||||
|
19
Sorts/test/pigeonHoleSort.test.js
Normal file
19
Sorts/test/pigeonHoleSort.test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { pigeonHoleSort } from '../PigeonHoleSort'
|
||||||
|
|
||||||
|
test('The pigeonHoleSort of the array [1, 4, 3, 2] is [1, 2, 3, 4]', () => {
|
||||||
|
const arr = [1, 4, 3, 2]
|
||||||
|
const res = pigeonHoleSort(arr)
|
||||||
|
expect(res).toEqual([1, 2, 3, 4])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('The pigeonHoleSort of the array [5, 4, 1, 2] is [1, 2, 4, 5]', () => {
|
||||||
|
const arr = [5, 4, 1, 2]
|
||||||
|
const res = pigeonHoleSort(arr)
|
||||||
|
expect(res).toEqual([1, 2, 4, 5])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('The pigeonHoleSort of the array [18, 31, 29, 35, 11] is [11, 18, 29, 31, 35]', () => {
|
||||||
|
const arr = [18, 31, 29, 35, 11]
|
||||||
|
const res = pigeonHoleSort(arr)
|
||||||
|
expect(res).toEqual([11, 18, 29, 31, 35])
|
||||||
|
})
|
Reference in New Issue
Block a user