From a47383ff5d706d80c3ba9f39e301ed6d2c9a89bc Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:05:05 +0000 Subject: [PATCH 01/11] Start draft PR From ca136efed5836afcfe850efc67a838acea57da66 Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:05:17 +0000 Subject: [PATCH 02/11] Add string reversal function with type checking --- src/string_utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/string_utils.py diff --git a/src/string_utils.py b/src/string_utils.py new file mode 100644 index 0000000..567d54d --- /dev/null +++ b/src/string_utils.py @@ -0,0 +1,19 @@ +def reverse_string(input_string): + """ + Reverse the given string. + + 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") + + # Return the reversed string + return input_string[::-1] \ No newline at end of file From 84c65489fbd303079a690f8f9d9f321db095414c Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:05:26 +0000 Subject: [PATCH 03/11] Add comprehensive tests for string reversal function --- tests/test_string_utils.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_string_utils.py diff --git a/tests/test_string_utils.py b/tests/test_string_utils.py new file mode 100644 index 0000000..eab8677 --- /dev/null +++ b/tests/test_string_utils.py @@ -0,0 +1,34 @@ +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_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_with_spaces(): + """Test reversal of strings with spaces.""" + assert reverse_string("hello world") == "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"]) \ No newline at end of file From 324659a7735c7cd2836c211c7f6da595dfd346fa Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:05:31 +0000 Subject: [PATCH 04/11] Add pytest to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..55b033e --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pytest \ No newline at end of file From b0d46fe63fb49e7132742a38d47c968913c04aec Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:06:13 +0000 Subject: [PATCH 05/11] Reimplement string reversal without slice or reverse methods --- src/__pycache__/string_utils.cpython-312.pyc | Bin 0 -> 625 bytes src/string_utils.py | 13 +++++++++---- ...est_string_utils.cpython-312-pytest-8.3.5.pyc | Bin 0 -> 6000 bytes 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/__pycache__/string_utils.cpython-312.pyc create mode 100644 tests/__pycache__/test_string_utils.cpython-312-pytest-8.3.5.pyc diff --git a/src/__pycache__/string_utils.cpython-312.pyc b/src/__pycache__/string_utils.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..aca1ee17c8ed3f832eea45b110741ae107eb1b98 GIT binary patch literal 625 zcmY*Xze~eF6uxVs^p_nRY6UHaAQ*)HSc?cEf?W#MPA;W3XARUO++7MS9Yl0@Yu#O> z|Af0sMW^8A`}e zT*zKRw({`{Ff>1Iam(hSVK=F-K_`A}=5Js>IX@tmmq&g!^9|R{GwM2A#d;ynSu;N! zx$X(8&2w(oPX*Hix5HvkEDiWJgiG|jhLY*q_Wk~AV(TrnGR_oUQpIt!__c_VnLB;B yG1Q+E>tlU=0&-L_urhc+O#T`y3c-)=TsWrJrn@W&N98TaFAZZni7ex+(*6Nn{-SpP literal 0 HcmV?d00001 diff --git a/src/string_utils.py b/src/string_utils.py index 567d54d..63a44a0 100644 --- a/src/string_utils.py +++ b/src/string_utils.py @@ -1,6 +1,6 @@ def reverse_string(input_string): """ - Reverse the given string. + Reverse the given string using a manual character-by-character approach. Args: input_string (str): The string to be reversed. @@ -11,9 +11,14 @@ def reverse_string(input_string): Raises: TypeError: If the input is not a string. """ - # Check if input is a string + # Type checking if not isinstance(input_string, str): raise TypeError("Input must be a string") - # Return the reversed string - return input_string[::-1] \ No newline at end of file + # 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) \ No newline at end of file diff --git a/tests/__pycache__/test_string_utils.cpython-312-pytest-8.3.5.pyc b/tests/__pycache__/test_string_utils.cpython-312-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3246c7f248e37a80161fdf49f5ffb713fc5dad90 GIT binary patch literal 6000 zcmeHL&1)M+6yKFbpKB*h(uO*5+O-uEsg7kk%|{)Q5F1+PA%;RI#Fu5QU0ds}v|?r* zTZ#?&xZq);DnP@#ty7xFhWx6+Gb`J*f?Ex4E5N?aQ7sc&X>SBkCF#I!VRGunOo zdvE5w8O`pSH}k%0ZH)_1e*gIG>{mz-)+ytafD1N00q}*O37TjMqau3-a=}bM6mn=Z zB=VZ@Xc%e&W+WFKje;zATNsUL2xwdj0hP2c&=xHMv{j1&-BT1(u_v^Xk(B7{!TMDl z6I~%THu4i0w{!N001d*uQ3eVl5$6P3^cu_xi!PoMwZL3pR-6rdniPb&;B1h5Yg0W| zCgJ~WEgG~L7d1q6#siCP3oT^R9$A@;dZ_+fbm3Kjv^UsiGg)s%k?phI7;&RUi(l=7 z?HYLz##8?nO?2urutPi18^sRo0$w{U`~a20FqcS+Xwg|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DLuOpjfq{%-XG`oYux|< literal 0 HcmV?d00001 From d7d0bde0010b1d5bcab95581ea09df442fda7fae Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 19:06:21 +0000 Subject: [PATCH 06/11] Update tests for string reversal function --- tests/test_string_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_string_utils.py b/tests/test_string_utils.py index eab8677..0a66c5b 100644 --- a/tests/test_string_utils.py +++ b/tests/test_string_utils.py @@ -10,6 +10,10 @@ 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" @@ -18,9 +22,9 @@ def test_reverse_string_unicode(): """Test reversal of unicode strings.""" 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_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.""" From 40815f3ddd18b4224e666c9355372696d4a6cf4f Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 22:29:47 +0000 Subject: [PATCH 07/11] Start draft PR From 206cfc6f15462d292e9ae44c1e0b032782224872 Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 22:29:57 +0000 Subject: [PATCH 08/11] Add string reversal function with type checking --- src/string_reversal.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/string_reversal.py diff --git a/src/string_reversal.py b/src/string_reversal.py new file mode 100644 index 0000000..1c5b4be --- /dev/null +++ b/src/string_reversal.py @@ -0,0 +1,19 @@ +def reverse_string(input_string): + """ + Reverse the given input string. + + 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") + + # Return the reversed string + return input_string[::-1] \ No newline at end of file From 7a8226548a37180858115b7ad44f33dd09f9835b Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 22:30:04 +0000 Subject: [PATCH 09/11] Add comprehensive tests for string reversal function --- tests/test_string_reversal.py | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_string_reversal.py diff --git a/tests/test_string_reversal.py b/tests/test_string_reversal.py new file mode 100644 index 0000000..5398e44 --- /dev/null +++ b/tests/test_string_reversal.py @@ -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"]) \ No newline at end of file From f38750b067afb57442b78d679cf1c38d5720b07c Mon Sep 17 00:00:00 2001 From: momstrosity Date: Fri, 9 May 2025 22:30:45 +0000 Subject: [PATCH 10/11] Implement string reversal using manual two-pointer technique --- .../string_reversal.cpython-312.pyc | Bin 0 -> 634 bytes src/string_reversal.py | 17 ++++++++++++++--- ...tring_reversal.cpython-312-pytest-8.3.5.pyc | Bin 0 -> 6199 bytes 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/__pycache__/string_reversal.cpython-312.pyc create mode 100644 tests/__pycache__/test_string_reversal.cpython-312-pytest-8.3.5.pyc diff --git a/src/__pycache__/string_reversal.cpython-312.pyc b/src/__pycache__/string_reversal.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1841456ec277daa16eb5b157938e2ee1dbb1e364 GIT binary patch literal 634 zcmY*Xy-&hG6u+a@ARvPSVj|??L}LQF8e?LNi7XDt15bKBvTh5_H9H`eS4e&eCDZdtjCw9txwcW_tX>L6 zt_3rg&7#-w)8Rnj1+fLtOAo#d=>mPPqEzO#dB69XEWD?eN7;>+^yVnOIi5$U?43SX x8|cr;+(^$&fQ}9gtPCCylm7^dL-OO>E!S!{=?+W5QF%*ntYM5Nu_c^W+&{aUrZE5j literal 0 HcmV?d00001 diff --git a/src/string_reversal.py b/src/string_reversal.py index 1c5b4be..952ccb9 100644 --- a/src/string_reversal.py +++ b/src/string_reversal.py @@ -1,6 +1,6 @@ def reverse_string(input_string): """ - Reverse the given input string. + Reverse the given input string manually, without using slice notation or reverse(). Args: input_string (str): The string to be reversed. @@ -15,5 +15,16 @@ def reverse_string(input_string): if not isinstance(input_string, str): raise TypeError("Input must be a string") - # Return the reversed string - return input_string[::-1] \ No newline at end of file + # 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) \ No newline at end of file diff --git a/tests/__pycache__/test_string_reversal.cpython-312-pytest-8.3.5.pyc b/tests/__pycache__/test_string_reversal.cpython-312-pytest-8.3.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7d4b01b696682e1cfbffc0c64701ca19a198bb72 GIT binary patch literal 6199 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y@)G|aEnVVG6QZg(NV{MHE#g4)UoD`wmP#%@ZRwiToTwu zGcI*P+9fmVu$4l)ZDuEU^9HBAxJzbE+yck7I6VGe9J6xIaSN+ZGHk6-G+=dbVYi=c zC`Nu^s&IMudb**cuMb}?OfBS%MIw9?n>Gg50-DY-zH+{7z0LU(xK5-TFloMCMKm=bw z-ma7iRnzKql_fko?5{oCfA8V`+SdNs-}cu&^>v>zX^W*iJihb%?kVS4;!Oxn9+Ob} zS$Lce0r1cbPBQ!8TI)PG%^!faaV&ilxzB@#pyf8R z40+Bkk!v{alG&r4gJB0eZygj_EH8}X-3g+OkQiL9ACZ$F0{QpImY-u)THA;?UY7iLGD%Hw_zfmexYD+FG0583TL@O^r zd~U%4Tb>RP+ZcqX3dPb)4o}MvLY6Ybi}M(n7iWb!o+4`EaW{z#2!4#_2Z&PTE}TwG zoz&|yG#Hz^ka#o}o69FM170!+|504LymLD5j4Y4YK@cxXtz}wrA^0a$Uc%SWGhjof z(C|fv7P7pXMbwSQC@``{F~-0SS!_$m7E6lW&-#r{Bf~cHPENjFu9{1>b&b9bI&=r; uGQfYLvMm2gl0J~$@BgQi{f0#3>^I4XJc=-d@EXDuggN;jsmLR&(C+|@2$QS; literal 0 HcmV?d00001 From 96a3700ab2689eef015567045849d41321847d58 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Sat, 10 May 2025 13:51:50 +0000 Subject: [PATCH 11/11] Start draft PR