From 0659586414e8dbd7f8fc17f5749130485515b1d9 Mon Sep 17 00:00:00 2001 From: Ankush263 Date: Thu, 24 Mar 2022 15:19:36 +0530 Subject: [PATCH] Fix GnomeSort algorithm and Add test case to it --- Sorts/GnomeSort.js | 1 + Sorts/test/GnomeSort.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Sorts/test/GnomeSort.test.js diff --git a/Sorts/GnomeSort.js b/Sorts/GnomeSort.js index 59f68b33ca..281b96afa4 100644 --- a/Sorts/GnomeSort.js +++ b/Sorts/GnomeSort.js @@ -19,6 +19,7 @@ export function gnomeSort (items) { i = Math.max(1, i - 1) } } + return items } // Implementation of gnomeSort diff --git a/Sorts/test/GnomeSort.test.js b/Sorts/test/GnomeSort.test.js new file mode 100644 index 0000000000..a769ebcc54 --- /dev/null +++ b/Sorts/test/GnomeSort.test.js @@ -0,0 +1,19 @@ +import { gnomeSort } from '../GnomeSort' + +test('The gnomeSort of the array [5, 4, 3, 2, 1] is [1, 2, 3, 4, 5]', () => { + const arr = [5, 4, 3, 2, 1] + const res = gnomeSort(arr) + expect(res).toEqual([1, 2, 3, 4, 5]) +}) + +test('The gnomeSort of the array [-5, 4, -3, 2, -1] is [-5, -3, -1, 2, 4]', () => { + const arr = [-5, 4, -3, 2, -1] + const res = gnomeSort(arr) + expect(res).toEqual([-5, -3, -1, 2, 4]) +}) + +test('The gnomeSort of the array [15, 4, -13, 2, -11] is [-13, -11, 2, 4, 15]', () => { + const arr = [15, 4, -13, 2, -11] + const res = gnomeSort(arr) + expect(res).toEqual([-13, -11, 2, 4, 15]) +}) 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