From dbcafc2ab3c60e4919455df396f996715b429329 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Fri, 20 Dec 2024 03:05:03 -0800 Subject: [PATCH] # Help Bob count letters and digits --- .../__init__.py | 1 + .../count_letters_and_digits.py | 5 ++- .../test_count_letters_and_digits.py | 44 ++++++++----------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/kyu_7/help_bob_count_letters_and_digits/__init__.py b/kyu_7/help_bob_count_letters_and_digits/__init__.py index e69de29bb2d..6a43dcb8bb7 100644 --- a/kyu_7/help_bob_count_letters_and_digits/__init__.py +++ b/kyu_7/help_bob_count_letters_and_digits/__init__.py @@ -0,0 +1 @@ +"""Help Bob count letters and digits.""" diff --git a/kyu_7/help_bob_count_letters_and_digits/count_letters_and_digits.py b/kyu_7/help_bob_count_letters_and_digits/count_letters_and_digits.py index c392c6ea86b..3c8ceabe119 100644 --- a/kyu_7/help_bob_count_letters_and_digits/count_letters_and_digits.py +++ b/kyu_7/help_bob_count_letters_and_digits/count_letters_and_digits.py @@ -1,5 +1,6 @@ """ Solution for -> Help Bob count letters and digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,8 +8,8 @@ def count_letters_and_digits(s: str) -> int: """ - A method that can determine how many - letters and digits are in a given string. + A method that can determine how many letters and digits are in a given string. + :param s: :return: """ diff --git a/kyu_7/help_bob_count_letters_and_digits/test_count_letters_and_digits.py b/kyu_7/help_bob_count_letters_and_digits/test_count_letters_and_digits.py index b4d04b9d967..fcc38672024 100644 --- a/kyu_7/help_bob_count_letters_and_digits/test_count_letters_and_digits.py +++ b/kyu_7/help_bob_count_letters_and_digits/test_count_letters_and_digits.py @@ -1,5 +1,6 @@ """ Test for -> Help Bob count letters and digits. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -8,6 +9,7 @@ import unittest import allure +from parameterized import parameterized from utils.log_func import print_log from kyu_7.help_bob_count_letters_and_digits.count_letters_and_digits \ import (count_letters_and_digits) @@ -25,13 +27,18 @@ url='https://www.codewars.com/kata/5738f5ea9545204cec000155', name='Source/Kata') class CalculateTestCase(unittest.TestCase): - """ - Testing count_letters_and_digits function - """ - - def test_count_letters_and_digits(self): + """Testing count_letters_and_digits function.""" + + @parameterized.expand([ + ('n!!ice!!123', 7), + ('de?=?=tttes!!t', 8), + ('', 0), + ('!@#$%^&`~.', 0), + ('u_n_d_e_r__S_C_O_R_E', 10)]) + def test_count_letters_and_digits(self, s, expected): """ - Testing the function with various test data + Testing the function with various test data. + :return: """ # pylint: disable-msg=R0801 @@ -45,22 +52,9 @@ def test_count_letters_and_digits(self): "
Test a method that can determine how many letters " "and digits are in a given string.
") # pylint: enable-msg=R0801 - test_data: tuple = ( - ('n!!ice!!123', 7), - ('de?=?=tttes!!t', 8), - ('', 0), - ('!@#$%^&`~.', 0), - ('u_n_d_e_r__S_C_O_R_E', 10)) - - for s, expected in test_data: - actual_result: int = count_letters_and_digits(s) - with allure.step(f"Enter string ({s}) and verify the " - f"expected output ({expected}) vs " - f"actual result ({actual_result})"): - - print_log(s=s, - expected=expected, - result=actual_result) - - self.assertEqual(expected, - actual_result) + actual_result: int = count_letters_and_digits(s) + with allure.step(f"Enter string ({s}) and verify the " + f"expected output ({expected}) vs " + f"actual result ({actual_result})"): + print_log(s=s, expected=expected,result=actual_result) + self.assertEqual(expected, actual_result)