Skip to content

Commit

Permalink
# Factorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 20, 2024
1 parent 28ff036 commit 9037fd5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions kyu_7/factorial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Factorial."""

Check notice on line 1 in kyu_7/factorial/__init__.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_7/factorial/__init__.py#L1

Final newline missing (missing-final-newline)

Check notice on line 1 in kyu_7/factorial/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

kyu_7/factorial/__init__.py#L1

Final newline missing
5 changes: 4 additions & 1 deletion kyu_7/factorial/factorial.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Sum of Numbers
Solution for -> Factorial.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


def factorial(n: int) -> int:
"""
Factorial function.
A function to calculate factorial for a given input.
If input is below 0 or above 12 throw an exception
of type ValueError (Python).
Expand Down
36 changes: 15 additions & 21 deletions kyu_7/factorial/test_factorial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Sum of Numbers
Test for -> Factorial.
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_7.factorial.factorial import factorial

Expand All @@ -25,13 +27,16 @@
url='https://www.codewars.com/kata/54ff0d1f355cfd20e60001fc',
name='Source/Kata')
class FactorialTestCase(unittest.TestCase):
"""
Testing 'factorial' function
"""
"""Testing 'factorial' function."""

def test_factorial(self):
@parameterized.expand([
(0, 1, "factorial for 0 is 1"),
(1, 1, "factorial for 1 is 1"),
(2, 2, "factorial for 2 is 2"),
(3, 6, "factorial for 3 is 6")])
def test_factorial(self, n, expected, msg):
"""
Testing 'factorial' function
Testing 'factorial' function.
In mathematics, the factorial of a non-negative integer n,
denoted by n!, is the product of all positive integers less
Expand All @@ -53,18 +58,7 @@ def test_factorial(self):
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable-msg=R0801
with allure.step("Enter a number and verify the output"):
data: tuple = (
(0, 1, "factorial for 0 is 1"),
(1, 1, "factorial for 1 is 1"),
(2, 2, "factorial for 2 is 2"),
(3, 6, "factorial for 3 is 6"))

for n, expected, msg in data:
print_log(n=n,
expected=expected,
msg=msg)

self.assertEqual(expected,
factorial(n),
msg)
with allure.step(f"Enter a number n: {n} "
f"and verify the expected output: {expected}."):
print_log(n=n, expected=expected, msg=msg)
self.assertEqual(expected, factorial(n), msg)

0 comments on commit 9037fd5

Please sign in to comment.