Skip to content

Commit

Permalink
# Row of the odd triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent 2ad5d87 commit a18f2d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
1 change: 1 addition & 0 deletions kyu_6/row_of_the_odd_triangle/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Row of the odd triangle."""
11 changes: 8 additions & 3 deletions kyu_6/row_of_the_odd_triangle/odd_row.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Row of the odd triangle
Solution for -> Row of the odd triangle.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def odd_row(n: int) -> list:
"""
Odd row.
Given a triangle of consecutive odd numbers
finds the triangle's row knowing its index
(the rows are 1-indexed).
Expand All @@ -26,7 +29,8 @@ def odd_row(n: int) -> list:

def calc_first_number(n: int) -> int:
"""
Calculate first number in the row
Calculate first number in the row.
:param n:
:return:
"""
Expand All @@ -35,7 +39,8 @@ def calc_first_number(n: int) -> int:

def calc_last_number(n: int) -> int:
"""
Calculate last number in the row
Calculate last number in the row.
:param n:
:return:
"""
Expand Down
66 changes: 30 additions & 36 deletions kyu_6/row_of_the_odd_triangle/test_odd_row.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Row of the odd triangle
Test for -> Row of the odd triangle.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -8,6 +9,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_6.row_of_the_odd_triangle.odd_row import odd_row

Expand All @@ -26,12 +28,26 @@
name='Source/Kata')
# pylint: enable=R0801
class OddRowTestCase(unittest.TestCase):
"""
Testing odd_row function
"""
def test_odd_row(self):
"""Testing odd_row function."""

@parameterized.expand([
(1, [1]),
(2, [3, 5]),
(13, [157, 159, 161, 163, 165, 167, 169, 171,
173, 175, 177, 179, 181]),
(19, [343, 345, 347, 349, 351, 353, 355, 357,
359, 361, 363, 365, 367, 369, 371, 373,
375, 377, 379]),
(41, [1641, 1643, 1645, 1647, 1649, 1651, 1653,
1655, 1657, 1659, 1661, 1663, 1665, 1667,
1669, 1671, 1673, 1675, 1677, 1679, 1681,
1683, 1685, 1687, 1689, 1691, 1693, 1695,
1697, 1699, 1701, 1703, 1705, 1707, 1709,
1711, 1713, 1715, 1717, 1719, 1721])])
def test_odd_row(self, n, expected):
"""
Testing odd_row function with various test data
Testing odd_row function with various test data.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -45,33 +61,11 @@ def test_odd_row(self):
"<p>Given a triangle of consecutive odd numbers find "
"the triangle's row knowing its index (the rows are 1-indexed)</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
(1, [1]),
(2, [3, 5]),
(13, [157, 159, 161, 163, 165, 167, 169, 171,
173, 175, 177, 179, 181]),
(19, [343, 345, 347, 349, 351, 353, 355, 357,
359, 361, 363, 365, 367, 369, 371, 373,
375, 377, 379]),
(41, [1641, 1643, 1645, 1647, 1649, 1651, 1653,
1655, 1657, 1659, 1661, 1663, 1665, 1667,
1669, 1671, 1673, 1675, 1677, 1679, 1681,
1683, 1685, 1687, 1689, 1691, 1693, 1695,
1697, 1699, 1701, 1703, 1705, 1707, 1709,
1711, 1713, 1715, 1717, 1719, 1721]))

for n, expected in test_data:
actual_result = odd_row(n)

with allure.step(
f"Enter the triangle's row ({n}) and verify the "
f"expected output ({expected}) vs "
f"actual result ({actual_result})"):
# pylint: disable=R0801
print_log(n=n,
expected=expected,
result=actual_result)

self.assertEqual(expected,
actual_result)
# pylint: disable=R0801
actual_result = odd_row(n)
with allure.step(f"Enter the triangle's row ({n}) "
f"and verify the expected output ({expected}) "
f"vs actual result ({actual_result})"):
# pylint: disable=R0801
print_log(n=n, expected=expected, result=actual_result)
self.assertEqual(expected, actual_result)
# pylint: disable=R0801

0 comments on commit a18f2d2

Please sign in to comment.