-
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.
Merge pull request #576 from iKostanOrg/kyu7
Merge pull request #575 from iKostanOrg/master
- Loading branch information
Showing
7 changed files
with
265 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,38 @@ | ||
# Complete The Pattern #5 - Even Ladder | ||
|
||
## Description | ||
|
||
You have to write a function pattern which creates the following pattern | ||
up to `n/2` number of lines. | ||
|
||
If `n <= 1` then it should return `""` (i.e. empty string). | ||
|
||
If any odd number is passed as argument then the pattern should last up to | ||
the largest even number which is smaller than the passed odd number. | ||
|
||
|
||
## Examples | ||
|
||
```bash | ||
n = 8: | ||
|
||
22 | ||
4444 | ||
666666 | ||
88888888 | ||
|
||
n = 5: | ||
|
||
22 | ||
4444 | ||
``` | ||
|
||
### Note | ||
|
||
There are no spaces in the pattern. | ||
|
||
### Hint | ||
|
||
Use `\n` in string to jump to next line. | ||
|
||
[Source](https://www.codewars.com/kata/55749101ae1cf7673800003e) |
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 @@ | ||
"""Complete The Pattern #5 - Even Ladder.""" |
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,25 @@ | ||
""" | ||
Solution for -> Complete The Pattern #5 - Even Ladder. | ||
Created by Egor Kostan. | ||
GitHub: https://github.com/ikostan | ||
""" | ||
|
||
def pattern(n: int) -> str: | ||
""" | ||
'pattern' function. | ||
Create the pattern up to n/2 number of lines. | ||
:param n: | ||
:return: | ||
""" | ||
# If n <= 1 then it should return "" (i.e. empty string). | ||
if n < 2: | ||
return '' | ||
# If any odd number is passed as argument then the pattern | ||
# should last up to the largest even number which is smaller | ||
# than the passed odd number. | ||
# Note: There are no spaces in the pattern.lines.append() | ||
# Use \n in string to jump to next line. | ||
lines: list = [(f'{i}' * i) for i in range(2, n + 1, 2)] | ||
return '\n'.join(lines) |
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,94 @@ | ||
""" | ||
Test for -> Complete The Pattern #5 - Even Ladder. | ||
Created by Egor Kostan. | ||
GitHub: https://github.com/ikostan | ||
""" | ||
|
||
# ASCII FUNDAMENTALS | ||
|
||
import unittest | ||
import allure # pylint: disable=import-error | ||
from parameterized import parameterized | ||
from utils.log_func import print_log | ||
from kyu_7.complete_the_pattern_5_even_ladder.solution import pattern | ||
|
||
|
||
# pylint: disable-msg=R0801 | ||
@allure.epic('7 kyu') | ||
@allure.parent_suite('Beginner') | ||
@allure.suite("Fundamentals") | ||
@allure.sub_suite("Unit Tests") | ||
@allure.feature("Lists") | ||
@allure.story('Complete The Pattern #5 - Even Ladder') | ||
@allure.tag('ASCII', | ||
'FUNDAMENTALS') | ||
@allure.link( | ||
url='https://www.codewars.com/kata/55749101ae1cf7673800003e', | ||
name='Source/Kata') | ||
# pylint: enable-msg=R0801 | ||
class PatternTestCase(unittest.TestCase): | ||
"""Testing pattern function.""" | ||
|
||
@parameterized.expand([ | ||
(2, "22"), | ||
(1, ""), | ||
(5, "22\n4444"), | ||
(6, "22\n4444\n666666"), | ||
(0, ""), | ||
(-25, "")]) | ||
def test_pattern(self, n, expected): | ||
""" | ||
Basic test case for pattern func. | ||
:return: | ||
""" | ||
# pylint: disable-msg=R0801 | ||
allure.dynamic.title("Basic test case for pattern func.") | ||
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>" | ||
"If n <= 1 then it should return "" (i.e. empty string)." | ||
"</p>" | ||
"<p>" | ||
"If any odd number is passed as argument then the pattern " | ||
"should last up to the largest even number which is smaller " | ||
"than the passed odd number." | ||
"</p>") | ||
# pylint: enable-msg=R0801 | ||
with allure.step(f"Enter test number (n): {n} " | ||
f"and verify the output: {expected}"): | ||
result = pattern(n) | ||
print_log(n=n, expected=expected, result=result) | ||
self.assertEqual(expected, result, msg=expected) | ||
|
||
@parameterized.expand([ | ||
(8, "22\n4444\n666666\n88888888")]) | ||
def test_pattern_has_no_spaces(self, n, expected): | ||
""" | ||
Output should not have any spaces.. | ||
:return: | ||
""" | ||
# pylint: disable-msg=R0801 | ||
allure.dynamic.title("Test no spaces in output.") | ||
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>" | ||
"There are no spaces in the pattern." | ||
"</p>") | ||
# pylint: enable-msg=R0801 | ||
with allure.step(f"Enter test number (n): {n} " | ||
"and verify the output has no spaces."): | ||
result = pattern(n) | ||
print_log(n=n, expected=expected, result=result) | ||
self.assertEqual(result, expected) | ||
self.assertEqual(result.count(' '), 0) |
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,60 @@ | ||
""" | ||
Test for -> Logical Calculator ValueError. | ||
Created by Egor Kostan. | ||
GitHub: https://github.com/ikostan | ||
""" | ||
|
||
# FUNDAMENTALS ARRAYS | ||
|
||
import unittest | ||
import allure | ||
import pytest | ||
from kyu_8.logical_calculator.logical_calculator \ | ||
import logical_calc | ||
|
||
|
||
# pylint: disable=R0801 | ||
@allure.epic('8 kyu') | ||
@allure.parent_suite('Beginner') | ||
@allure.suite("Data Structures") | ||
@allure.sub_suite("Unit Tests") | ||
@allure.feature("Lists") | ||
@allure.story('Logical Calculator') | ||
@allure.tag('FUNDAMENTALS', | ||
'ARRAYS' | ||
"ValueError") | ||
@allure.link( | ||
url='https://www.codewars.com/kata/57096af70dad013aa200007b', | ||
name='Source/Kata') | ||
# pylint: enable=R0801 | ||
class LogicalCalculatorValueErrorTestCase(unittest.TestCase): | ||
"""Testing ValueError.""" | ||
|
||
def test_logical_calc_value_error(self): | ||
""" | ||
Testing ValueError for logical_calc function. | ||
:return: | ||
""" | ||
# pylint: disable=R0801 | ||
allure.dynamic.title("Testing ValueError for logical_calc 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>" | ||
"Test Python Exception Handling Using 'pytest.raises'." | ||
"</p>") | ||
# pylint: enable=R0801 | ||
with allure.step("Pass an array with invalid operator."): | ||
arr: list = [] | ||
op: str = 'RO' # invalid operator | ||
operators: list = ['AND', 'OR', 'XOR'] | ||
err = (f'ERROR: {op} is not a valid operator. ' | ||
f'Please use one of the followings: {operators}') | ||
with pytest.raises(ValueError) as calc_err: | ||
logical_calc(arr, op) | ||
self.assertEqual(str(calc_err.value), err) |