From ccf5dc37fc5287206e1cc77fe3dcee8e37b0e1fb Mon Sep 17 00:00:00 2001 From: Ankush263 Date: Sun, 27 Mar 2022 15:26:03 +0530 Subject: [PATCH] Add test case and fix the OddEvenSort Algorithm --- 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 ee4950f4ae..c3d46a24be 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 0000000000..1885e4a779 --- /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]) +})