Skip to content

Commit db3caea

Browse files
Added test cases for LongestValidParentheses
1 parent c2b3931 commit db3caea

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Dynamic-Programming/LongestValidParentheses.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
find the length of the longest valid (well-formed) parentheses substring.
66
*/
77

8-
const longestValidParentheses = (s) => {
8+
export const longestValidParentheses = (s) => {
99
const n = s.length
1010
const stack = []
1111

@@ -33,11 +33,3 @@ const longestValidParentheses = (s) => {
3333
res.push(0)
3434
return Math.max(...res)
3535
}
36-
37-
const main = () => {
38-
console.log(longestValidParentheses(')()())')) // output -> 4
39-
console.log(longestValidParentheses('')) // output -> 0
40-
console.log(longestValidParentheses('(()')) // output -> 2
41-
}
42-
43-
main()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { longestValidParentheses } from '../LongestValidParentheses'
2+
3+
describe('longestValidParentheses', () => {
4+
it('expects to return 0 as longest valid parentheses substring', () => {
5+
expect(longestValidParentheses('')).toBe(0)
6+
})
7+
8+
it('expects to return 2 as longest valid parentheses substring', () => {
9+
expect(longestValidParentheses('(()')).toBe(2)
10+
})
11+
12+
it('expects to return 2 as longest valid parentheses substring', () => {
13+
expect(longestValidParentheses(')()())')).toBe(4)
14+
})
15+
16+
it('expects to return 2 as longest valid parentheses substring', () => {
17+
expect(longestValidParentheses('(((')).toBe(0)
18+
})
19+
})

0 commit comments

Comments
 (0)