Skip to content

Commit

Permalink
# Duplicate Encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent 0e8ff85 commit 255dd84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions kyu_6/duplicate_encoder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Duplicate Encoder."""
6 changes: 4 additions & 2 deletions kyu_6/duplicate_encoder/duplicate_encode.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
Solution for -> Duplicate Encoder
Solution for -> Duplicate Encoder.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""


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
Expand All @@ -18,7 +21,6 @@ def duplicate_encode(word: str) -> str:
:param word:
:return:
"""

result: str = ''
word = ''.join(char.lower() for char in word)

Expand Down
34 changes: 17 additions & 17 deletions kyu_6/duplicate_encoder/test_duplicate_encode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Test for -> Duplicate Encoder
Test for -> Duplicate Encoder.
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.duplicate_encoder.duplicate_encode \
import duplicate_encode
Expand All @@ -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
Expand All @@ -47,13 +53,7 @@ def test_duplicate_encode(self):
'<h3>Test Description:</h3>'
"<p></p>")
# 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))

0 comments on commit 255dd84

Please sign in to comment.