mirror of
https://github.com/harivansh-afk/veet-code.git
synced 2026-04-17 17:03:29 +00:00
clanker: test-veet (run)
This commit is contained in:
parent
c4d74aca3e
commit
684a9c5e3a
6 changed files with 253 additions and 0 deletions
37
problems/medium/valid-parentheses/solution.py
Normal file
37
problems/medium/valid-parentheses/solution.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"""
|
||||
Valid Parentheses
|
||||
|
||||
You're building a syntax checker for a code editor. Before running
|
||||
any code, the editor needs to verify that all brackets are properly
|
||||
matched and nested. Given a string containing only parentheses,
|
||||
square brackets, and curly braces, determine if the input is valid.
|
||||
|
||||
A string is valid if:
|
||||
- Open brackets are closed by the same type of bracket
|
||||
- Open brackets are closed in the correct order
|
||||
- Every close bracket has a corresponding open bracket
|
||||
|
||||
Example 1:
|
||||
Input: s = "([]){}"
|
||||
Output: True
|
||||
Explanation: All brackets are properly matched and nested
|
||||
|
||||
Example 2:
|
||||
Input: s = "([)]"
|
||||
Output: False
|
||||
Explanation: The square bracket closes before the parenthesis
|
||||
|
||||
Example 3:
|
||||
Input: s = "{{"
|
||||
Output: False
|
||||
Explanation: Opening braces are never closed
|
||||
|
||||
Constraints:
|
||||
- 0 <= len(s) <= 10^4
|
||||
- s consists only of characters '(){}[]'
|
||||
"""
|
||||
|
||||
|
||||
def is_valid(s: str) -> bool:
|
||||
"""Return True if the bracket string is valid, False otherwise."""
|
||||
pass # Your implementation here
|
||||
51
problems/medium/valid-parentheses/tests.py
Normal file
51
problems/medium/valid-parentheses/tests.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
"""Tests for valid-parentheses."""
|
||||
import pytest
|
||||
from solution import is_valid
|
||||
|
||||
|
||||
class TestBasicCases:
|
||||
"""Test basic functionality with typical inputs."""
|
||||
|
||||
def test_example_one(self):
|
||||
"""Test first example from problem description."""
|
||||
assert is_valid("([]){}") is True
|
||||
|
||||
def test_example_two(self):
|
||||
"""Test second example from problem description."""
|
||||
assert is_valid("([)]") is False
|
||||
|
||||
def test_example_three(self):
|
||||
"""Test third example from problem description."""
|
||||
assert is_valid("{{") is False
|
||||
|
||||
def test_simple_pairs(self):
|
||||
"""Test simple matched pairs."""
|
||||
assert is_valid("()") is True
|
||||
assert is_valid("[]") is True
|
||||
assert is_valid("{}") is True
|
||||
|
||||
|
||||
class TestEdgeCases:
|
||||
"""Test edge cases and boundary conditions."""
|
||||
|
||||
def test_empty_string(self):
|
||||
"""Test with empty input."""
|
||||
assert is_valid("") is True
|
||||
|
||||
def test_single_bracket(self):
|
||||
"""Test with a single unmatched bracket."""
|
||||
assert is_valid("(") is False
|
||||
assert is_valid("]") is False
|
||||
|
||||
def test_deeply_nested(self):
|
||||
"""Test with deeply nested brackets."""
|
||||
assert is_valid("{[({[]})]}") is True
|
||||
|
||||
def test_close_before_open(self):
|
||||
"""Test closing bracket appearing before any opener."""
|
||||
assert is_valid(")(") is False
|
||||
|
||||
def test_mismatched_types(self):
|
||||
"""Test opening one type and closing another."""
|
||||
assert is_valid("{)") is False
|
||||
assert is_valid("[}") is False
|
||||
Loading…
Add table
Add a link
Reference in a new issue