Skip to content

Commit

Permalink
# Easy Line
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 20, 2024
1 parent fa76728 commit 28ff036
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 64 deletions.
1 change: 1 addition & 0 deletions kyu_7/easy_line/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Easy Line."""
11 changes: 7 additions & 4 deletions kyu_7/easy_line/easyline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> Easy Line
Solution for -> Easy Line.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -9,10 +10,11 @@

def easy_line(n: int):
"""
Easy line function.
The function will take n (with: n>= 0) as parameter
and will return the sum of the squares of the binomial
coefficients on line n.
coefficients with line 'n'.
:param n: the line number (with: n>= 0)
:return:
"""
Expand All @@ -33,7 +35,8 @@ def easy_line(n: int):

def calc_combination_per_row_item(row: int, i: int) -> int:
"""
Generates a specific combination from Pascal's Triangle row by specified index
Generate specific combination from Pascal's Triangle row by specified index.
:param row: row
:param i: index
:return:
Expand Down
109 changes: 49 additions & 60 deletions kyu_7/easy_line/test_easyline.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Test for -> Easy Line
Test for -> Easy Line.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""

import unittest
import pytest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_7.easy_line.easyline import easy_line, calc_combination_per_row_item

Expand All @@ -28,20 +30,23 @@
# pylint: enable=R0801
class EasyLineTestCase(unittest.TestCase):
"""
Testing 'easyline' function.
We want to calculate the sum of the squares of the binomial
coefficients on a given line with a function called easyline
coefficients on a given line with a function called 'easyline'
(or easyLine or easy-line).
Can you write a program which calculate easyline(n) where n
Can you write a program which calculate 'easyline(n)' where 'n'
is the line number?
The function will take n (with: n>= 0) as parameter and will
return the sum of the squares of the binomial coefficients on line n.
return the sum of the squares of the binomial coefficients with line 'n'.
"""

def test_easy_line_exception(self):
"""
Testing easy line function exception
Testing easy line function exception.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -66,9 +71,19 @@ def test_easy_line_exception(self):
self.assertRaises(ValueError, easy_line(n))
self.assertEqual(error_txt, error.value)

def test_calc_combinations_per_row(self):
@parameterized.expand([
(0, 0, 1),
(1, 1, 1),
(2, 1, 2),
(3, 2, 3),
(4, 3, 4),
(5, 4, 5),
(6, 5, 6),
(7, 6, 7)])
def test_calc_combinations_per_row(self, n, i, expected):
"""
Testing calc_combinations_per_row function
Testing calc_combinations_per_row function.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -85,34 +100,28 @@ def test_calc_combinations_per_row(self):
"combination per that row "
"coefficients on line n.</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
(0, 0, 1),
(1, 1, 1),
(2, 1, 2),
(3, 2, 3),
(4, 3, 4),
(5, 4, 5),
(6, 5, 6),
(7, 6, 7))

for data in test_data:
n: int = data[0]
i: int = data[1]
expected: int = data[2]
actual: int = calc_combination_per_row_item(n, i)

with allure.step(f"Enter row number ({n}) "
f"and assert expected ({expected}) "
f"vs actual ({actual})."):
print_log(n=n,
actual=actual,
expected=expected)

self.assertEqual(expected, actual)

def test_easy_line(self):
actual: int = calc_combination_per_row_item(n, i)
with allure.step(f"Enter row number ({n}) "
f"and assert expected ({expected}) "
f"vs actual ({actual})."):
print_log(n=n, actual=actual, expected=expected)
self.assertEqual(expected, actual)

@parameterized.expand([
(0, 1),
(1, 2),
(4, 70),
(7, 3432),
(13, 10400600),
(17, 2333606220),
(19, 35345263800),
(22, 2104098963720),
(24, 32247603683100),
(50, 100891344545564193334812497256)])
def test_easy_line(self, n, expected):
"""
Testing easy_line function
Testing easy_line function with various test data.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -128,29 +137,9 @@ def test_easy_line(self):
"and must return the sum of the squares of the binomial "
"coefficients on line n.</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
(0, 1),
(1, 2),
(4, 70),
(7, 3432),
(13, 10400600),
(17, 2333606220),
(19, 35345263800),
(22, 2104098963720),
(24, 32247603683100),
(50, 100891344545564193334812497256))

for data in test_data:
n: int = data[0]
expected: int = data[1]
actual: int = easy_line(n)

with allure.step(f"Enter line number ({n}) "
f"and assert expected ({expected}) "
f"vs actual ({actual})."):

print_log(n=n,
actual=actual,
expected=expected)

self.assertEqual(expected, actual)
actual: int = easy_line(n)
with allure.step(f"Enter line number ({n}) "
f"and assert expected ({expected}) "
f"vs actual ({actual})."):
print_log(n=n, actual=actual, expected=expected)
self.assertEqual(expected, actual)

0 comments on commit 28ff036

Please sign in to comment.