From 80ec8e7c375bf0fbb6f474870719af10ccb50b4a Mon Sep 17 00:00:00 2001 From: Ankush263 Date: Thu, 31 Mar 2022 15:42:47 +0530 Subject: [PATCH] Add test case and fix pigeonHoleSort Algorithm --- Sorts/PigeonHoleSort.js | 1 + Sorts/test/pigeonHoleSort.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Sorts/test/pigeonHoleSort.test.js diff --git a/Sorts/PigeonHoleSort.js b/Sorts/PigeonHoleSort.js index 333027c68c..30c1bcb813 100644 --- a/Sorts/PigeonHoleSort.js +++ b/Sorts/PigeonHoleSort.js @@ -29,4 +29,5 @@ export function pigeonHoleSort (arr) { arr[index++] = j + min } } + return arr } diff --git a/Sorts/test/pigeonHoleSort.test.js b/Sorts/test/pigeonHoleSort.test.js new file mode 100644 index 0000000000..6816051c3b --- /dev/null +++ b/Sorts/test/pigeonHoleSort.test.js @@ -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]) +}) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy