merge: Add test case and fix pigeonHoleSort Algorithm (#967)

This commit is contained in:
Ankush263
2022-04-01 12:28:43 +05:30
committed by GitHub
parent 871a49f3cd
commit 6f33f990f2
2 changed files with 20 additions and 0 deletions

View File

@ -29,4 +29,5 @@ export function pigeonHoleSort (arr) {
arr[index++] = j + min
}
}
return arr
}

View 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])
})