Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/__pycache__/string_utils.cpython-312.pyc
Binary file not shown.
6 changes: 5 additions & 1 deletion src/string_reversal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def reverse_string(input_string):
def reverse_string(input_string: str) -> str:
"""
Reverse the given input string manually, without using slice notation or reverse().

Expand All @@ -15,6 +15,10 @@ def reverse_string(input_string):
if not isinstance(input_string, str):
raise TypeError("Input must be a string")

# Handle empty string case
if not input_string:
return ""

# Convert string to list of characters
chars = list(input_string)

Expand Down
6 changes: 5 additions & 1 deletion src/string_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def reverse_string(input_string):
def reverse_string(input_string: str) -> str:
"""
Reverse the given string using a manual character-by-character approach.

Expand All @@ -15,6 +15,10 @@ def reverse_string(input_string):
if not isinstance(input_string, str):
raise TypeError("Input must be a string")

# Handle empty string case
if not input_string:
return ""

# Use list to manually reverse the string
reversed_chars = []
for i in range(len(input_string) - 1, -1, -1):
Expand Down
Binary file modified tests/__pycache__/test_string_utils.cpython-312-pytest-8.3.5.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_string_reversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
def test_reverse_standard_string():
"""Test reversing a standard string."""
assert reverse_string("hello") == "olleh"
assert reverse_string("python") == "nohtyp"

def test_reverse_empty_string():
"""Test reversing an empty string."""
assert reverse_string("") == ""

def test_reverse_single_char_string():
"""Test reversing a single character string."""
assert reverse_string("a") == "a"

def test_reverse_palindrome():
"""Test reversing a palindrome string."""
assert reverse_string("racecar") == "racecar"
Expand Down