-
Notifications
You must be signed in to change notification settings - Fork 5
Utility Functions #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
labrocadabro
wants to merge
23
commits into
Prometheus-Swarm:main
Choose a base branch
from
koii-network:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−0
Open
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a47383f
Start draft PR
momstrosity ca136ef
Add string reversal function with type checking
momstrosity 84c6548
Add comprehensive tests for string reversal function
momstrosity 324659a
Add pytest to requirements
momstrosity b0d46fe
Reimplement string reversal without slice or reverse methods
momstrosity d7d0bde
Update tests for string reversal function
momstrosity 40815f3
Start draft PR
momstrosity 206cfc6
Add string reversal function with type checking
momstrosity 7a82265
Add comprehensive tests for string reversal function
momstrosity f38750b
Implement string reversal using manual two-pointer technique
momstrosity d40c662
Start draft PR
momstrosity 09769f7
Merged branch pr-28-momstrosity-task-tester for PR https://github.com…
momstrosity 9c35a6d
Merged branch pr-29-momstrosity-task-tester for PR https://github.com…
momstrosity a81a741
Merge pull request #2 from momstrosity/3517d487-faee-4a89-88b4-d34ac3…
labrocadabro 26dda78
Start draft PR
labrocadabro ee87224
Merge pull request #11 from labrocadabro/7e96f47f-31f9-4800-9996-ecaf…
labrocadabro 2938bd7
Start draft PR
labrocadabro a5cc007
Merge pull request #13 from labrocadabro/6038cff7-2b13-464c-8831-190b…
labrocadabro 00a7f51
Start draft PR
laura-ct 154c648
Resolve merge conflicts in test_string_reversal.py
laura-ct cc17bb9
Merge pull request #15 from laura-ct/c7c94660-6ed3-492a-8fa9-2c17450f…
labrocadabro dfefc4d
Start draft PR
laura-ct 9c7c393
Merge pull request #16 from laura-ct/1345ac0c-13e0-4a31-8168-035534dd…
labrocadabro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pytest |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| def reverse_string(input_string): | ||
| """ | ||
| 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") | ||
|
|
||
| # 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| def reverse_string(input_string): | ||
| """ | ||
| 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") | ||
|
|
||
| # 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import pytest | ||
| from src.string_reversal import reverse_string | ||
|
|
||
| def test_reverse_standard_string(): | ||
| """Test reversing a standard string.""" | ||
| assert reverse_string("hello") == "olleh" | ||
|
|
||
| def test_reverse_empty_string(): | ||
| """Test reversing an empty string.""" | ||
| assert reverse_string("") == "" | ||
|
|
||
| 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"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Note about duplicate functionality
This function provides the same functionality as
reverse_stringinstring_utils.pybut with a different implementation. Consider:reverse_string_swapvsreverse_string_iterate)🏁 Script executed:
Length of output: 391
Consolidate duplicate
reverse_stringimplementationsYou currently have two equivalent functions:
src/string_utils.py→reverse_string(imported bytests/test_string_utils.py)src/string_reversal.py→reverse_string(imported bytests/test_string_reversal.py)Both provide identical behavior. To reduce duplication and simplify maintenance, choose one of the following:
• Merge into a single implementation (e.g. keep it in
src/string_utils.py) and update both test files to import from that module.• Rename one of the functions to clarify its approach (for example,
reverse_string_swapvs.reverse_string_iterative) and update its test accordingly.Please update the implementation and adjust imports in:
src/string_utils.pysrc/string_reversal.pytests/test_string_utils.pytests/test_string_reversal.py