Skip to content

Commit 89f3773

Browse files
committed
tests: add tests of LongestIncreasingSubsequence
1 parent 6fe21d2 commit 89f3773

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: Dynamic-Programming/LongestIncreasingSubsequence.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// Return the length of the Longest Increasing Subsequence, given array x
77
function longestIncreasingSubsequence(x) {
88
const length = x.length
9+
if (length == 0) {
10+
return 0
11+
}
912
const dp = Array(length).fill(1)
1013

1114
let res = 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { longestIncreasingSubsequence } from '../LongestIncreasingSubsequence'
2+
3+
describe('Testing longestIncreasingSubsequence', () => {
4+
it.each([
5+
[[], 0],
6+
[[1], 1],
7+
[[1, 2], 2],
8+
[[1, 2, 2, 2, 2], 2],
9+
[[1, 0, 2], 2],
10+
[[1, 10, 2, 30], 3],
11+
[[5, 8, 3, 7, 9, 1], 3],
12+
[[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], 6]
13+
])('check with %j', (input, expected) => {
14+
expect(longestIncreasingSubsequence(input)).toBe(expected)
15+
})
16+
})

0 commit comments

Comments
 (0)