From 8f407776306195e26972801183c14f3c06b79046 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Fri, 9 May 2025 11:06:59 +0000 Subject: [PATCH 1/6] Start draft PR From 43ebd80161120a9a2b887e63f431fceaa18cfb22 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Fri, 9 May 2025 11:07:11 +0000 Subject: [PATCH 2/6] 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..ca3c8c0 --- /dev/null +++ b/src/string_utils.py @@ -0,0 +1,19 @@ +def reverse_string(input_string): + """ + Reverse a 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 a1cff9319377dbc6d4466c56d10e04fd60e11edf Mon Sep 17 00:00:00 2001 From: laura-abro Date: Fri, 9 May 2025 11:07:20 +0000 Subject: [PATCH 3/6] Add comprehensive tests for string reversal function --- tests/test_string_utils.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 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..52c4538 --- /dev/null +++ b/tests/test_string_utils.py @@ -0,0 +1,32 @@ +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 with special characters and spaces.""" + assert reverse_string("Hello, World!") == "!dlroW ,olleH" + assert reverse_string(" trim ") == " mirt " + +def test_reverse_string_unicode(): + """Test reversal with Unicode characters.""" + assert reverse_string("こんにちは") == "はちにんこ" + assert reverse_string("🌈🦄") == "🦄🌈" + +def test_reverse_string_invalid_input(): + """Test error handling 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(["list"]) \ No newline at end of file From cab130aed5e22980495435ea07f42735a4e67ba2 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Fri, 9 May 2025 11:07:25 +0000 Subject: [PATCH 4/6] 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 cde0d57bb9afa0dad2bbb04d262353d4e3514cc6 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Fri, 9 May 2025 11:08:08 +0000 Subject: [PATCH 5/6] Implement string reversal without using slice or reverse() --- src/__pycache__/string_utils.cpython-312.pyc | Bin 0 -> 623 bytes src/string_utils.py | 15 +++++++++++---- ...est_string_utils.cpython-312-pytest-8.3.5.pyc | Bin 0 -> 6420 bytes 3 files changed, 11 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..df8cf617e8bef38d75abeb6d17b6de134929f5a7 GIT binary patch literal 623 zcmY*Xze@u#6i#}l^!MOUD_9AF&_l4g77;`QyL70XTuSZ5dQk6u#Ejk^7h?ARePA>YA-bsB&-X;0I_q{J6kC{voLA<^dP9HEr?{X0ZtW^Y(GC(G} zLPw~FjaVx}B&@^GU<3z{21xv2eI#PArD7D$cuLGgdnO)*+)La?W(+>SGloS;;dDg zc5QgV>hKM>=V!yygtx;IP%H)bI;0EqwT#lao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