From fd91016c2a57940e5c1b5ce1e9a96a662875f607 Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 19 May 2025 12:51:55 -0300 Subject: [PATCH 1/3] Start draft PR From d815d68bccd3a2693208edfff9cb310b6d555549 Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 19 May 2025 12:52:43 -0300 Subject: [PATCH 2/3] Resolve merge conflicts in test_string_reversal.py --- src/__pycache__/string_utils.cpython-312.pyc | Bin 625 -> 959 bytes src/string_reversal.py | 24 ++++++++++++++++++ src/string_utils.py | 8 +++--- ..._string_utils.cpython-312-pytest-8.3.5.pyc | Bin 6000 -> 6919 bytes tests/test_string_reversal.py | 17 ++++++++----- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/__pycache__/string_utils.cpython-312.pyc b/src/__pycache__/string_utils.cpython-312.pyc index aca1ee17c8ed3f832eea45b110741ae107eb1b98..ec32751225509bb82a053729c99bf186b2660e7a 100644 GIT binary patch delta 580 zcmY*X&1(}u6rb7MByE$fUnD9-SSu8RglWLggHrGV4}wM9dXzBP9e20g?1tG{i;|FD z1tD2-^&sLwDR>e;PF@RwY}uX`|AF4B=|wO4wn4!M@4flGncw@pVdlH?xuAZTpPxfu zZ}m&|ODR&Db2&gV_~d@*|PL)&<|Hl-)PHf2-Z&M06v(GVMwg$(Hd zF#EWNdiX5VBk9?!g8EV)o636e=;(i;C;jcI0~dq$@g}O}a})rIo}VLH7&xA#QLRJ0 zkh+>-Q%()Rc)k6&{tsxh+vPqr?C8^1bw3+(|2J3)t;R!K9i%xGKUpJ~wEcS{3FAB3K{-!dcg!##UpT;Kjjl5XlA(D154IFZkkiv`GI2I9{i6Md~kY8X%;L str: + """ + Reverse a given string without using built-in reversal methods. +>>>>>>> pr-23-labrocadabro-task-tester Args: input_string (str): The string to be reversed. @@ -15,6 +21,7 @@ def reverse_string(input_string): if not isinstance(input_string, str): raise TypeError("Input must be a string") +<<<<<<< HEAD # Convert string to list of characters chars = list(input_string) @@ -22,9 +29,26 @@ def reverse_string(input_string): left, right = 0, len(chars) - 1 while left < right: # Swap characters from both ends +======= + # Handle empty string case + if not input_string: + return "" + + # Convert string to list of characters for manipulation + chars = list(input_string) + + # Reverse the list using two-pointer technique + left, right = 0, len(chars) - 1 + while left < right: + # Swap characters +>>>>>>> pr-23-labrocadabro-task-tester chars[left], chars[right] = chars[right], chars[left] left += 1 right -= 1 +<<<<<<< HEAD # Convert list back to string and return +======= + # Convert back to string +>>>>>>> pr-23-labrocadabro-task-tester return ''.join(chars) \ No newline at end of file diff --git a/src/string_utils.py b/src/string_utils.py index 63a44a0..24e5584 100644 --- a/src/string_utils.py +++ b/src/string_utils.py @@ -11,14 +11,12 @@ def reverse_string(input_string): Raises: TypeError: If the input is not a string. """ - # Type checking + # Enhanced type checking with more explicit validation 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]) + # Efficient string reversal using list comprehension + reversed_chars = [input_string[i] for i in range(len(input_string) - 1, -1, -1)] # 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 index 3246c7f248e37a80161fdf49f5ffb713fc5dad90..ca220a938f0a1ad6b0ae4129c19c194594042421 100644 GIT binary patch delta 525 zcmeyM*KWplnwOW00SLARYi9(qPUMqdjG3q&&XvO1!Vtw@$*9S-u_=}{yhuMIKQ~oB zC$Y3BQ9nJi1cWn6lk^LUfWjpisinpGX{m`NrA4W_Nu`-NDXB&J<@rU~Kq|i|IZ-z; zJvFaHza+J|q*%WwwIClt#v5+_z-q-dxk6|*s}|4+yptt_=WfpCeZ)9fi)TKo4p2yN z^En;`W>!5QQ*`rZ{#GVNlgZjVayGe{6{#r-$r*`7iOD6YMG7UA1*ye)Re~O=IXU?{ z3gP)hIVp+?hDOF!g2qOM3W_N?Mfu?hI{7&{sUDL9Ijtst5)!Qk8xjvPq`1fcXoDmW z7k2`Q28IVxx))end+aVq>0aj612Qidxq?U_+sO4Ix9fEl5V{HzfpFpEMUYkq?=pgU z1*lp|7b1KK$X4doLvW0sM#9YiGOn?>ZeA>G&%|m0bd&7l=b{@K1t!lFa{-3IJuwqq zkduo*Qbpz delta 194 zcmZoS`=G~nnwOW00SLYY%4IBJnaC%>7&cKooTZXclXGK7EUTc7equp^eo<;celeJg z-)zHX#Wr~=|9n<0pf=vkmI4aQtU5rZ;O02tR;I~iJhNH#fLzhZV!U%VJBsTvv6=z7 zl9P)iH!|{1R+VyLG@6_xWugHREiwfWsvtrcNZjJE$<0qG%}KQ@vH@}#fw)+2@@Xjr WF@sMWOpH#9AkykH2PdNvSQ7wy&Mg%H diff --git a/tests/test_string_reversal.py b/tests/test_string_reversal.py index 5398e44..9db46af 100644 --- a/tests/test_string_reversal.py +++ b/tests/test_string_reversal.py @@ -9,29 +9,32 @@ 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.""" + """Test reversing a palindrome.""" 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(): +def test_reverse_with_special_chars(): """Test reversing a string with special characters.""" + assert reverse_string("hello!@#") == "#@!olleh" assert reverse_string("a1b2c3!@#") == "#@!3c2b1a" def test_reverse_unicode_string(): - """Test reversing a string with Unicode characters.""" + """Test reversing a Unicode string.""" assert reverse_string("こんにちは") == "はちにんこ" def test_invalid_input_type(): - """Test that a TypeError is raised for non-string inputs.""" + """Test raising TypeError for non-string input.""" with pytest.raises(TypeError, match="Input must be a string"): - reverse_string(12345) - + 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 1d03a1eff393f39f1e6de0014511ef071a430eeb Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 19 May 2025 12:52:53 -0300 Subject: [PATCH 3/3] Resolve merge conflicts in string_reversal.py and consolidate changes --- src/string_reversal.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/string_reversal.py b/src/string_reversal.py index fb7d70a..a16ab6e 100644 --- a/src/string_reversal.py +++ b/src/string_reversal.py @@ -1,12 +1,6 @@ -<<<<<<< HEAD -def reverse_string(input_string): - """ - Reverse the given input string manually, without using slice notation or reverse(). -======= def reverse_string(input_string: str) -> str: """ - Reverse a given string without using built-in reversal methods. ->>>>>>> pr-23-labrocadabro-task-tester + Reverse the given input string manually, without using slice notation or reverse(). Args: input_string (str): The string to be reversed. @@ -21,15 +15,6 @@ def reverse_string(input_string: str) -> str: if not isinstance(input_string, str): raise TypeError("Input must be a string") -<<<<<<< HEAD - # 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 -======= # Handle empty string case if not input_string: return "" @@ -40,15 +25,10 @@ def reverse_string(input_string: str) -> str: # Reverse the list using two-pointer technique left, right = 0, len(chars) - 1 while left < right: - # Swap characters ->>>>>>> pr-23-labrocadabro-task-tester + # Swap characters from both ends chars[left], chars[right] = chars[right], chars[left] left += 1 right -= 1 -<<<<<<< HEAD # Convert list back to string and return -======= - # Convert back to string ->>>>>>> pr-23-labrocadabro-task-tester return ''.join(chars) \ No newline at end of file