Content-Length: 3084 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1660.patch
thub.com
From 89f3773b36971e9746383e983ef233f1de79c9ab Mon Sep 17 00:00:00 2001
From: Piotr Idzik
Date: Sat, 11 May 2024 19:24:21 +0000
Subject: [PATCH 1/2] tests: add tests of `LongestIncreasingSubsequence`
---
.../LongestIncreasingSubsequence.js | 3 +++
.../tests/LongestIncreasingSubsequence.test.js | 16 ++++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
diff --git a/Dynamic-Programming/LongestIncreasingSubsequence.js b/Dynamic-Programming/LongestIncreasingSubsequence.js
index b9319db586..b8e1847cd8 100644
--- a/Dynamic-Programming/LongestIncreasingSubsequence.js
+++ b/Dynamic-Programming/LongestIncreasingSubsequence.js
@@ -6,6 +6,9 @@
// Return the length of the Longest Increasing Subsequence, given array x
function longestIncreasingSubsequence(x) {
const length = x.length
+ if (length == 0) {
+ return 0
+ }
const dp = Array(length).fill(1)
let res = 1
diff --git a/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js b/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
new file mode 100644
index 0000000000..09a9e1c6aa
--- /dev/null
+++ b/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
@@ -0,0 +1,16 @@
+import { longestIncreasingSubsequence } from '../LongestIncreasingSubsequence'
+
+describe('Testing longestIncreasingSubsequence', () => {
+ it.each([
+ [[], 0],
+ [[1], 1],
+ [[1, 2], 2],
+ [[1, 2, 2, 2, 2], 2],
+ [[1, 0, 2], 2],
+ [[1, 10, 2, 30], 3],
+ [[5, 8, 3, 7, 9, 1], 3],
+ [[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], 6]
+ ])('check with %j', (input, expected) => {
+ expect(longestIncreasingSubsequence(input)).toBe(expected)
+ })
+})
From 03db547514911a56238ccd31c7d8589ceb1e8343 Mon Sep 17 00:00:00 2001
From: Piotr Idzik
Date: Sun, 12 May 2024 13:24:12 +0000
Subject: [PATCH 2/2] tests: add more test cases
---
.../tests/LongestIncreasingSubsequence.test.js | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js b/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
index 09a9e1c6aa..9a8024aa95 100644
--- a/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
+++ b/Dynamic-Programming/tests/LongestIncreasingSubsequence.test.js
@@ -4,11 +4,19 @@ describe('Testing longestIncreasingSubsequence', () => {
it.each([
[[], 0],
[[1], 1],
+ [[2, 2], 1],
+ [[3, 3, 3], 1],
+ [[4, 4, 4, 4], 1],
[[1, 2], 2],
[[1, 2, 2, 2, 2], 2],
[[1, 0, 2], 2],
[[1, 10, 2, 30], 3],
[[5, 8, 3, 7, 9, 1], 3],
+ [[10, 9, 2, 5, 3, 7, 101, 18], 4],
+ [[10, 10, 9, 9, 2, 2, 5, 5, 3, 3, 7, 7, 101, 101, 18, 18], 4],
+ [[0, 1, 0, 3, 2, 3], 4],
+ [[1, 1, 2, 2, 2], 2],
+ [[1, 1, 2, 2, 2, 3, 3, 3, 3], 3],
[[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], 6]
])('check with %j', (input, expected) => {
expect(longestIncreasingSubsequence(input)).toBe(expected)
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/TheAlgorithms/JavaScript/pull/1660.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy