Skip to content

Commit ff30add

Browse files
committed
adding pytest module
1 parent fb84dda commit ff30add

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"leetcode-master"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
# solution by rubix-coder
22
class SolutionValidParenthesis:
3-
def isValid(self, s: str) -> bool:
3+
def isValid( s: str) -> bool:
44
stack = []
55
bracket_map = {')': '(', '}': '{', ']': '['}
6+
print(f"Bracket map -> {bracket_map}")
67
for char in s:
8+
print(f"Char in string -> {char}")
79
if char in bracket_map:
10+
print(f"char in bracket map -> {char}")
811
top_element = stack.pop() if stack else '#'
12+
print(f"top element -> {top_element}")
913
if bracket_map[char] != top_element:
14+
print(f"Return false as {bracket_map[char]} not in {top_element}")
1015
return False
1116
else:
1217
stack.append(char)
18+
print(f"Updated stack -> {stack}")
19+
print("Return ! stack..")
1320
return not stack
21+
22+
result = SolutionValidParenthesis.isValid(s="((({{{{[[]]}}}})))")
23+
print(result)

test/__pycache__/adder.cpython-38.pyc

322 Bytes
Binary file not shown.
Binary file not shown.

test/adder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# adder.py
2+
def add(a, b):
3+
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):
4+
raise TypeError("Both arguments must be numbers")
5+
return a + b

test/test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
from adder import add
3+
def test_add_integers():
4+
assert add(1, 2) == 3
5+
assert add(-1, 1) == 0
6+
assert add(-1, -1) == -2
7+
8+
def test_add_floats():
9+
assert add(1.5, 2.5) == 4.0
10+
assert add(1.1, 2.2) == pytest.approx(3.3)
11+
12+
def test_add_strings():
13+
with pytest.raises(TypeError):
14+
add('a', 'b')

0 commit comments

Comments
 (0)