From 68c359246ba8b938161ed4835bc73cca83653bc1 Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Sun, 9 Jun 2024 14:26:08 +0800 Subject: [PATCH 1/6] test: add edge cases and mixed number types for LocalMaximomPoint --- Data-Structures/Array/test/LocalMaximomPoint.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Data-Structures/Array/test/LocalMaximomPoint.test.js b/Data-Structures/Array/test/LocalMaximomPoint.test.js index db7d911949..c306852a8b 100644 --- a/Data-Structures/Array/test/LocalMaximomPoint.test.js +++ b/Data-Structures/Array/test/LocalMaximomPoint.test.js @@ -26,4 +26,14 @@ describe('LocalMaximumPoint tests', () => { const Array2 = [13, 16, 5, 41, 3, 2, 1] expect(LocalMaximomPoint(Array2)).toEqual(3) }) + + it('test with positive and negative numbers', () => { + const Array4 = [-4, -3, -2, -1, -5, 4, -1] + expect(LocalMaximomPoint(Array4)).toEqual(3) + }) + + it('test with floating-point numbers', () => { + const Array5 = [1.5, 3.5, 2.5, 0.5, -1.5, -3.5, -2.5] + expect(LocalMaximomPoint(Array5)).toEqual(1) + }) }) From fac10d072cb35ad24021a43b3c97d00d14327a31 Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Sun, 9 Jun 2024 14:30:23 +0800 Subject: [PATCH 2/6] test: rename test arrays for consistency in LocalMaximomPoint tests --- Data-Structures/Array/test/LocalMaximomPoint.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Data-Structures/Array/test/LocalMaximomPoint.test.js b/Data-Structures/Array/test/LocalMaximomPoint.test.js index c306852a8b..461a2b8c90 100644 --- a/Data-Structures/Array/test/LocalMaximomPoint.test.js +++ b/Data-Structures/Array/test/LocalMaximomPoint.test.js @@ -28,12 +28,12 @@ describe('LocalMaximumPoint tests', () => { }) it('test with positive and negative numbers', () => { - const Array4 = [-4, -3, -2, -1, -5, 4, -1] - expect(LocalMaximomPoint(Array4)).toEqual(3) + const Array2 = [-4, -3, -2, -1, -5, 4, -1] + expect(LocalMaximomPoint(Array2)).toEqual(3) }) it('test with floating-point numbers', () => { - const Array5 = [1.5, 3.5, 2.5, 0.5, -1.5, -3.5, -2.5] - expect(LocalMaximomPoint(Array5)).toEqual(1) + const Array2 = [1.5, 3.5, 2.5, 0.5, -1.5, -3.5, -2.5] + expect(LocalMaximomPoint(Array2)).toEqual(1) }) }) From cd4b59142102526aa48976f5a349d8b0a6d9a696 Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Sun, 9 Jun 2024 14:38:39 +0800 Subject: [PATCH 3/6] chore: remove redundant comment from LocalMaximomPoint tests --- Data-Structures/Array/test/LocalMaximomPoint.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Data-Structures/Array/test/LocalMaximomPoint.test.js b/Data-Structures/Array/test/LocalMaximomPoint.test.js index 461a2b8c90..9efd6bbfeb 100644 --- a/Data-Structures/Array/test/LocalMaximomPoint.test.js +++ b/Data-Structures/Array/test/LocalMaximomPoint.test.js @@ -12,7 +12,6 @@ describe('LocalMaximumPoint tests', () => { }) it('test boundary maximum points - should find first maximom point from the top', () => { - // Test a mix of number types (i.e., positive/negative, numbers with decimals, fractions) const Array = [13, 2, 3, 4, 5, 6, 12] expect(LocalMaximomPoint(Array)).toEqual(6) }) From cbfdd8e8e4d94d0b5a945dc415370e7cfbe81d15 Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Sun, 9 Jun 2024 14:47:27 +0800 Subject: [PATCH 4/6] fix: rename listIn to listInput and listOut to listOutput in QueueUsing2Stacks.js --- Data-Structures/Queue/QueueUsing2Stacks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data-Structures/Queue/QueueUsing2Stacks.js b/Data-Structures/Queue/QueueUsing2Stacks.js index 256f11060d..a8ad636fea 100644 --- a/Data-Structures/Queue/QueueUsing2Stacks.js +++ b/Data-Structures/Queue/QueueUsing2Stacks.js @@ -31,7 +31,7 @@ class Queue { } // display elements of the inputstack - listIn(output = (value) => console.log(value)) { + listInput(output = (value) => console.log(value)) { let i = 0 while (i < this.inputStack.length) { output(this.inputStack[i]) @@ -40,7 +40,7 @@ class Queue { } // display element of the outputstack - listOut(output = (value) => console.log(value)) { + listOutput(output = (value) => console.log(value)) { let i = 0 while (i < this.outputStack.length) { output(this.outputStack[i]) From d13cccd19725e13af9506443f1e0a9de5d5444fc Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Mon, 10 Jun 2024 16:21:52 +0800 Subject: [PATCH 5/6] chore: revert the unrelated changes of the PR --- Data-Structures/Queue/QueueUsing2Stacks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data-Structures/Queue/QueueUsing2Stacks.js b/Data-Structures/Queue/QueueUsing2Stacks.js index a8ad636fea..256f11060d 100644 --- a/Data-Structures/Queue/QueueUsing2Stacks.js +++ b/Data-Structures/Queue/QueueUsing2Stacks.js @@ -31,7 +31,7 @@ class Queue { } // display elements of the inputstack - listInput(output = (value) => console.log(value)) { + listIn(output = (value) => console.log(value)) { let i = 0 while (i < this.inputStack.length) { output(this.inputStack[i]) @@ -40,7 +40,7 @@ class Queue { } // display element of the outputstack - listOutput(output = (value) => console.log(value)) { + listOut(output = (value) => console.log(value)) { let i = 0 while (i < this.outputStack.length) { output(this.outputStack[i]) From ddeb0400e752e2f18d787b1093bcedda0daab9e7 Mon Sep 17 00:00:00 2001 From: Tae Kim Date: Mon, 10 Jun 2024 16:45:28 +0800 Subject: [PATCH 6/6] tests: replace the tests for LocalMaximomPoint test --- .../Array/test/LocalMaximomPoint.test.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Data-Structures/Array/test/LocalMaximomPoint.test.js b/Data-Structures/Array/test/LocalMaximomPoint.test.js index 9efd6bbfeb..25689964fd 100644 --- a/Data-Structures/Array/test/LocalMaximomPoint.test.js +++ b/Data-Structures/Array/test/LocalMaximomPoint.test.js @@ -26,13 +26,15 @@ describe('LocalMaximumPoint tests', () => { expect(LocalMaximomPoint(Array2)).toEqual(3) }) - it('test with positive and negative numbers', () => { - const Array2 = [-4, -3, -2, -1, -5, 4, -1] - expect(LocalMaximomPoint(Array2)).toEqual(3) + it('test inner points - repeated local maxima', () => { + const Array2 = [1, 5, 5, 5, 3, 2, 1] + const result = LocalMaximomPoint(Array2) + expect([1, 2, 3]).toContain(result) }) - it('test with floating-point numbers', () => { - const Array2 = [1.5, 3.5, 2.5, 0.5, -1.5, -3.5, -2.5] - expect(LocalMaximomPoint(Array2)).toEqual(1) + it('test inner points - alternating peaks and valleys', () => { + const Array2 = [1, 3, 2, 4, 3, 5, 4] + const result = LocalMaximomPoint(Array2) + expect([1, 3, 5]).toContain(result) }) })