From d6a327a9886ba550909055c00fba4a526060c760 Mon Sep 17 00:00:00 2001 From: Ankush263 <86042508+Ankush263@users.noreply.github.com> Date: Sun, 27 Mar 2022 22:45:46 +0530 Subject: [PATCH] merge: Add test case and fix the OddEvenSort Algorithm (#955) --- Sorts/OddEvenSort.js | 1 + Sorts/test/OddEvenSort.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Sorts/test/OddEvenSort.test.js diff --git a/Sorts/OddEvenSort.js b/Sorts/OddEvenSort.js index ee4950f4a..c3d46a24b 100644 --- a/Sorts/OddEvenSort.js +++ b/Sorts/OddEvenSort.js @@ -30,4 +30,5 @@ export function oddEvenSort (arr) { } } } + return arr } diff --git a/Sorts/test/OddEvenSort.test.js b/Sorts/test/OddEvenSort.test.js new file mode 100644 index 000000000..1885e4a77 --- /dev/null +++ b/Sorts/test/OddEvenSort.test.js @@ -0,0 +1,25 @@ +import { oddEvenSort } from '../OddEvenSort' + +test('The OddEvenSort of the array [5, 4, 3, 2, 1] is [1, 2, 3, 4, 5]', () => { + const arr = [5, 4, 3, 2, 1] + const res = oddEvenSort(arr) + expect(res).toEqual([1, 2, 3, 4, 5]) +}) + +test('The OddEvenSort of the array [] is []', () => { + const arr = [] + const res = oddEvenSort(arr) + expect(res).toEqual([]) +}) + +test('The OddEvenSort of the array [10, 14, 12, 20] is [10, 12, 14, 20]', () => { + const arr = [10, 14, 12, 20] + const res = oddEvenSort(arr) + expect(res).toEqual([10, 12, 14, 20]) +}) + +test('The OddEvenSort of the array [166, 169, 144] is [144, 166, 169]', () => { + const arr = [166, 169, 144] + const res = oddEvenSort(arr) + expect(res).toEqual([144, 166, 169]) +})