-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 codefactor.io / CodeFactorkyu_6/valid_braces/valid_braces.py#L8
|
||
""" | ||
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 |