Skip to content

Commit

Permalink
# Century From Year
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 22, 2024
1 parent 8f11948 commit 99ac469
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions kyu_8/century_from_year/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Century From Year."""
6 changes: 4 additions & 2 deletions kyu_8/century_from_year/century.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Solution for -> Century From Year
Solution for -> Century From Year.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def century(year: int) -> int:
"""
Given a year, return the century it is in
Given a year, return the century it is in.
:param year: int
:return: int
"""
Expand Down
58 changes: 30 additions & 28 deletions kyu_8/century_from_year/test_century.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Century From Year
Test for -> Century From Year.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -9,6 +10,7 @@

import unittest
import allure
from parameterized import parameterized
from kyu_8.century_from_year.century import century
from utils.log_func import print_log

Expand All @@ -32,45 +34,45 @@
# pylint: enable-msg=R0801
class CenturyTestCase(unittest.TestCase):
"""
Testing century function.
The first century spans from the year 1 up to and
including the year 100, The second - from the year
101 up to and including the year 200, etc.
"""

def test_century(self):
@parameterized.expand([
(1705, 18, 'Testing for year 1705'),
(1900, 19, 'Testing for year 1900'),
(1601, 17, 'Testing for year 1601'),
(2000, 20, 'Testing for year 2000'),
(356, 4, 'Testing for year 356'),
(89, 1, 'Testing for year 89')])
def test_century(self, year, expected, message):
"""
Testing century function
Testing century function with various test data.
:return:
"""
# pylint: disable-msg=R0801
allure.dynamic.title("Testing century 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">'
'<img src="'
'https://www.codewars.com/users/myFirstCode/badges/large'
'">'
'<h3>Test Description:</h3>'
"<p>Given a year, the function should return the century it is in."
"<p>Given a year, the function should return "
"the century it is in."
"</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
(1705, 18, 'Testing for year 1705'),
(1900, 19, 'Testing for year 1900'),
(1601, 17, 'Testing for year 1601'),
(2000, 20, 'Testing for year 2000'),
(356, 4, 'Testing for year 356'),
(89, 1, 'Testing for year 89'))

for year, expected, message in test_data:
result: int = century(year)

with allure.step(f"Enter test year ({year}) and verify "
f"the output ({result}) "
f"vs expected ({expected})"):

print_log(year=year,
result=result,
expected=expected,
message=message)

self.assertEqual(expected,
result)
result: int = century(year)
with allure.step(f"Enter test year ({year}) and verify "
f"the output ({result}) "
f"vs expected ({expected})"):
print_log(year=year,
result=result,
expected=expected,
message=message)
self.assertEqual(expected, result)

0 comments on commit 99ac469

Please sign in to comment.