From 255dd84a7a15f89957b10345e6222128167e4a5a Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Tue, 17 Dec 2024 03:09:46 -0800 Subject: [PATCH] # Duplicate Encoder --- kyu_6/duplicate_encoder/__init__.py | 1 + kyu_6/duplicate_encoder/duplicate_encode.py | 6 ++-- .../test_duplicate_encode.py | 34 +++++++++---------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/kyu_6/duplicate_encoder/__init__.py b/kyu_6/duplicate_encoder/__init__.py index e69de29bb2d..7fec16bb903 100644 --- a/kyu_6/duplicate_encoder/__init__.py +++ b/kyu_6/duplicate_encoder/__init__.py @@ -0,0 +1 @@ +"""Duplicate Encoder.""" diff --git a/kyu_6/duplicate_encoder/duplicate_encode.py b/kyu_6/duplicate_encoder/duplicate_encode.py index b9a4e1e7a3a..ca9870b9ca4 100644 --- a/kyu_6/duplicate_encoder/duplicate_encode.py +++ b/kyu_6/duplicate_encoder/duplicate_encode.py @@ -1,5 +1,6 @@ """ -Solution for -> Duplicate Encoder +Solution for -> Duplicate Encoder. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -7,6 +8,8 @@ def duplicate_encode(word: str) -> str: """ + Duplicate Encoder. + Converts a string to a new string where each character in the new string is "(" if that character appears only once in the original @@ -18,7 +21,6 @@ def duplicate_encode(word: str) -> str: :param word: :return: """ - result: str = '' word = ''.join(char.lower() for char in word) diff --git a/kyu_6/duplicate_encoder/test_duplicate_encode.py b/kyu_6/duplicate_encoder/test_duplicate_encode.py index 9b1dc61390d..84337bbe123 100644 --- a/kyu_6/duplicate_encoder/test_duplicate_encode.py +++ b/kyu_6/duplicate_encoder/test_duplicate_encode.py @@ -1,5 +1,6 @@ """ -Test for -> Duplicate Encoder +Test for -> Duplicate Encoder. + 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_6.duplicate_encoder.duplicate_encode \ import duplicate_encode @@ -28,13 +30,17 @@ name='Source/Kata') # pylint: enable-msg=R0801 class DuplicateEncodeTestCase(unittest.TestCase): - """ - Testing duplicate_encode function - """ - def test_duplicate_encode(self): + """Testing duplicate_encode function.""" + + @parameterized.expand([ + ("din", "((("), + ("recede", "()()()"), + ("Success", ")())())"), + ("(( @", "))((")]) + def test_duplicate_encode(self, string, expected): """ - Testing duplicate_encode function - with various test inputs + Testing duplicate_encode function with various test inputs. + :return: """ # pylint: disable-msg=R0801 @@ -47,13 +53,7 @@ def test_duplicate_encode(self): '

Test Description:

' "

") # pylint: enable-msg=R0801 - with allure.step("Enter test string and verify the output"): - test_data: tuple = ( - ("din", "((("), - ("recede", "()()()"), - ("Success", ")())())"), - ("(( @", "))((")) - - for string, expected in test_data: - print_log(string=string, expected=expected) - self.assertEqual(expected, duplicate_encode(string)) + with allure.step(f"Enter test string: {string} " + f"and verify the output: {expected}."): + print_log(string=string, expected=expected) + self.assertEqual(expected, duplicate_encode(string))