Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kyu6: Valid Braces #542

Merged
merged 21 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kyu_6/unique_in_order/test_unique_in_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# pylint: disable-msg=R0801
@allure.epic('6 kyu')
@allure.parent_suite('Novice')
@allure.suite("Advanced Language Features")
@allure.suite("Fundamentals")
@allure.sub_suite("Unit Tests")
@allure.feature("Algorithms")
@allure.story('Unique In Order')
Expand Down
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'
ikostan marked this conversation as resolved.
Show resolved Hide resolved
ikostan marked this conversation as resolved.
Show resolved Hide resolved
ikostan marked this conversation as resolved.
Show resolved Hide resolved
ikostan marked this conversation as resolved.
Show resolved Hide resolved
"""
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
Loading