Skip to content

Commit

Permalink
Merge pull request #576 from iKostanOrg/kyu7
Browse files Browse the repository at this point in the history
Merge pull request #575 from iKostanOrg/master
  • Loading branch information
ikostan authored Dec 25, 2024
2 parents 2f84a83 + 10e9323 commit 763f6bf
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 35 deletions.
72 changes: 37 additions & 35 deletions kyu_7/README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions kyu_7/coloured_triangles/test_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def test_triangle(self, string, expected):
:return:
"""
# pylint: disable-msg=R0801
allure.dynamic.title("Basic test case for triangle 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></p>")
# pylint: enable-msg=R0801
with allure.step(f"Enter test string: {string} "
f"and verify the output: {expected}"):
result = triangle(string)
Expand Down
38 changes: 38 additions & 0 deletions kyu_7/complete_the_pattern_5_even_ladder/README.md
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)
1 change: 1 addition & 0 deletions kyu_7/complete_the_pattern_5_even_ladder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Complete The Pattern #5 - Even Ladder."""
25 changes: 25 additions & 0 deletions kyu_7/complete_the_pattern_5_even_ladder/solution.py
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)
94 changes: 94 additions & 0 deletions kyu_7/complete_the_pattern_5_even_ladder/test_pattern.py
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)
60 changes: 60 additions & 0 deletions kyu_8/logical_calculator/test_logical_calculator_error.py
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)

0 comments on commit 763f6bf

Please sign in to comment.