Skip to content

Commit

Permalink
# Sum of Digits / Digital Root
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent 29d8688 commit 77dc370
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions kyu_6/sum_of_digits_digital_root/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Sum of Digits / Digital Root."""
4 changes: 2 additions & 2 deletions kyu_6/sum_of_digits_digital_root/digital_root.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> Sum of Digits / Digital Root
Solution for -> Sum of Digits / Digital Root.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -14,7 +15,6 @@ def digital_root(n: int) -> int:
If that value has more than one digit, continue reducing
in this way until a single-digit number is produced. This
is only applicable to the natural numbers.
:param n:
:return:
"""
Expand Down
32 changes: 16 additions & 16 deletions kyu_6/sum_of_digits_digital_root/test_digital_root.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Sum of Digits / Digital Root
Test for -> Sum of Digits / Digital Root.
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.sum_of_digits_digital_root.digital_root \
import digital_root
Expand All @@ -27,10 +29,15 @@
url='https://www.codewars.com/kata/541c8630095125aba6000c00',
name='Source/Kata')
class DigitalRootTestCase(unittest.TestCase):
"""
Testing digital_root function
"""
def test_digital_root(self):
"""Testing digital_root function."""

@parameterized.expand([
(16, 7),
(456, 6),
(942, 6),
(132189, 6),
(493193, 2)])
def test_digital_root(self, n, expected):
"""
In this kata, you must create a digital root function.
Expand All @@ -51,14 +58,7 @@ def test_digital_root(self):
'<h3>Test Description:</h3>'
"<p></p>")
# pylint: enable-msg=R0801
with allure.step("Enter a number and verify the output"):
test_data: tuple = (
(16, 7),
(456, 6),
(942, 6),
(132189, 6),
(493193, 2))

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

0 comments on commit 77dc370

Please sign in to comment.