Skip to content

Commit

Permalink
Valid Braces
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Nov 25, 2024
1 parent 40b9719 commit 42b1b6d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kyu_6/valid_braces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Valid Braces

## Description

Write a function that takes a string of braces, and determines if the order
of the braces is valid. It should return true if the string is valid, and
false if it's invalid.

This Kata is similar to the Valid Parentheses Kata, but introduces new characters:
`brackets []`, and curly `braces {}`.

All input strings will be nonempty, and will only consist of parentheses,
brackets and curly braces: `()[]{}`.

## What is considered Valid?

A string of braces is considered valid if all braces are matched with the correct brace.

Examples:

```bash
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```

[Source](https://www.codewars.com/kata/5277c8a221e209d3f6000b56)
Empty file added kyu_6/valid_braces/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions kyu_6/valid_braces/test_valid_braces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""
Test for -> Unique In Order
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""

# Algorithms

import unittest
import allure
from utils.log_func import print_log
from kyu_6.valid_braces.valid_braces import valid_braces


# pylint: disable-msg=R0801
@allure.epic('6 kyu')
@allure.parent_suite('Novice')
@allure.suite("Fundamentals")
@allure.sub_suite("Unit Tests")
@allure.feature("Algorithms")
@allure.story('Unique In Order')
@allure.tag('FUNDAMENTALS',
'ALGORITHMS')
@allure.link(
url='https://www.codewars.com/kata/5277c8a221e209d3f6000b56',
name='Source/Kata')
# pylint: enable-msg=R0801
class ValidBracesTestCase(unittest.TestCase):
"""
Testing the 'valid_braces' function
"""
def test_valid_braces(self):
"""
Testing the 'valid_braces' function
with various test data
:return:
"""
# pylint: disable-msg=R0801
allure.dynamic.title("Testing the 'valid_braces' function")
allure.dynamic.severity(allure.severity_level.NORMAL)
allure.dynamic.description_html(
'<h3>Codewars badge:</h3>'
'<img src="https://www.codewars.com/users/myFirstCode'
'/badges/large">'
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable-msg=R0801
# pylint: disable=line-too-long
with allure.step("Pass test data and verify the output"):
data: tuple = (
("(){}[]", True),
("([{}])", True),
("(}", False),
("[(])", False),
("[({})](]", False),
("()", True),
("[]", True),
("[(])", False),
("{}", True),
("{}()[]", True),
("([{}])", True),
("([}{])", False),
("{}({})[]", True),
("(({{[[]]}}))", True),
("(((({{", False),
(")(}{][", False),
("())({}}{()][][", False)
)
# pylint: enable=line-too-long
for string, expected in data:
print_log(string=string, expected=expected)
self.assertEqual(expected, valid_braces(string))
18 changes: 18 additions & 0 deletions kyu_6/valid_braces/valid_braces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Test for -> Unique In Order
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def valid_braces(string: str) -> bool:

Check notice on line 8 in kyu_6/valid_braces/valid_braces.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_6/valid_braces/valid_braces.py#L8

Unused argument 'string' (unused-argument)

Check warning on line 8 in kyu_6/valid_braces/valid_braces.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

kyu_6/valid_braces/valid_braces.py#L8

Unused argument 'string'
"""
A function that takes a string of braces, and determines if the order
of the braces is valid. It should return true if the string is valid,
and false if it's invalid.
:param string:
:return:
"""
result: bool = False

return result

0 comments on commit 42b1b6d

Please sign in to comment.