Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a47383f
Start draft PR
momstrosity May 9, 2025
ca136ef
Add string reversal function with type checking
momstrosity May 9, 2025
84c6548
Add comprehensive tests for string reversal function
momstrosity May 9, 2025
324659a
Add pytest to requirements
momstrosity May 9, 2025
b0d46fe
Reimplement string reversal without slice or reverse methods
momstrosity May 9, 2025
d7d0bde
Update tests for string reversal function
momstrosity May 9, 2025
40815f3
Start draft PR
momstrosity May 9, 2025
206cfc6
Add string reversal function with type checking
momstrosity May 9, 2025
7a82265
Add comprehensive tests for string reversal function
momstrosity May 9, 2025
f38750b
Implement string reversal using manual two-pointer technique
momstrosity May 9, 2025
d40c662
Start draft PR
momstrosity May 9, 2025
09769f7
Merged branch pr-28-momstrosity-task-tester for PR https://github.com…
momstrosity May 9, 2025
9c35a6d
Merged branch pr-29-momstrosity-task-tester for PR https://github.com…
momstrosity May 9, 2025
a81a741
Merge pull request #2 from momstrosity/3517d487-faee-4a89-88b4-d34ac3…
labrocadabro May 10, 2025
26dda78
Start draft PR
labrocadabro May 19, 2025
ee87224
Merge pull request #11 from labrocadabro/7e96f47f-31f9-4800-9996-ecaf…
labrocadabro May 19, 2025
2938bd7
Start draft PR
labrocadabro May 19, 2025
a5cc007
Merge pull request #13 from labrocadabro/6038cff7-2b13-464c-8831-190b…
labrocadabro May 19, 2025
00a7f51
Start draft PR
laura-ct May 21, 2025
154c648
Resolve merge conflicts in test_string_reversal.py
laura-ct May 21, 2025
cc17bb9
Merge pull request #15 from laura-ct/c7c94660-6ed3-492a-8fa9-2c17450f…
labrocadabro May 21, 2025
dfefc4d
Start draft PR
laura-ct May 22, 2025
9c7c393
Merge pull request #16 from laura-ct/1345ac0c-13e0-4a31-8168-035534dd…
labrocadabro May 22, 2025
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
Binary file added src/__pycache__/string_reversal.cpython-312.pyc
Binary file not shown.
Binary file added src/__pycache__/string_utils.cpython-312.pyc
Binary file not shown.
34 changes: 34 additions & 0 deletions src/string_reversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def reverse_string(input_string: str) -> str:
"""
Reverse the given input string manually, without using slice notation or reverse().

Args:
input_string (str): The string to be reversed.

Returns:
str: The reversed string.

Raises:
TypeError: If the input is not a string.
"""
# Check if input is a 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)

# Manually reverse the list of characters
left, right = 0, len(chars) - 1
while left < right:
# Swap characters from both ends
chars[left], chars[right] = chars[right], chars[left]
left += 1
right -= 1

# Convert list back to string and return
return ''.join(chars)
28 changes: 28 additions & 0 deletions src/string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def reverse_string(input_string: str) -> str:
"""
Reverse the given string using a manual character-by-character approach.

Args:
input_string (str): The string to be reversed.

Returns:
str: The reversed string.

Raises:
TypeError: If the input is not a string.
"""
# Type checking
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):
reversed_chars.append(input_string[i])

# Convert list back to string
return ''.join(reversed_chars)
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/test_string_reversal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
from src.string_reversal import reverse_string

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"

def test_reverse_with_spaces():
"""Test reversing a string with spaces."""
assert reverse_string("hello world") == "dlrow olleh"

def test_reverse_with_special_characters():
"""Test reversing a string with special characters."""
assert reverse_string("a1b2c3!@#") == "#@!3c2b1a"

def test_reverse_unicode_string():
"""Test reversing a string with Unicode characters."""
assert reverse_string("こんにちは") == "はちにんこ"

def test_invalid_input_type():
"""Test that a TypeError is raised for non-string inputs."""
with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(12345)

with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(None)

with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(["hello"])
38 changes: 38 additions & 0 deletions tests/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from src.string_utils import reverse_string

def test_reverse_string_basic():
"""Test basic string reversal."""
assert reverse_string("hello") == "olleh"
assert reverse_string("python") == "nohtyp"

def test_reverse_string_empty():
"""Test reversal of an empty string."""
assert reverse_string("") == ""

def test_reverse_string_with_spaces():
"""Test reversal of strings with spaces."""
assert reverse_string("hello world") == "dlrow olleh"

def test_reverse_string_special_chars():
"""Test reversal of strings with special characters."""
assert reverse_string("a!b@c#") == "#c@b!a"

def test_reverse_string_unicode():
"""Test reversal of unicode strings."""
assert reverse_string("こんにちは") == "はちにんこ"

def test_reverse_string_mixed_chars():
"""Test reversal of strings with mixed character types."""
assert reverse_string("Hello, World! 123") == "321 !dlroW ,olleH"

def test_reverse_string_invalid_input():
"""Test that a TypeError is raised for non-string inputs."""
with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(123)

with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(None)

with pytest.raises(TypeError, match="Input must be a string"):
reverse_string(["hello"])