From 76ec673f693eb9e904a8da86a6cbbda4440778bc Mon Sep 17 00:00:00 2001 From: liuchunlin Date: Mon, 8 Sep 2025 17:06:11 +0800 Subject: [PATCH 1/4] add test file --- src/com/hankcs/algorithm/simple_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/com/hankcs/algorithm/simple_utils.py diff --git a/src/com/hankcs/algorithm/simple_utils.py b/src/com/hankcs/algorithm/simple_utils.py new file mode 100644 index 0000000..8e301db --- /dev/null +++ b/src/com/hankcs/algorithm/simple_utils.py @@ -0,0 +1,9 @@ +def reverse_string(text): + """Reverses the characters in a string.""" + return text[::-1] + +def count_words(sentence): + return len(sentence.split()) + +def celsius_to_fahrenheit(celsius): + return (celsius * 9/5) + 32 From ee7ca795c12d10d6c5e44f5e7a83e6ca31237ef0 Mon Sep 17 00:00:00 2001 From: liuchunlin Date: Mon, 8 Sep 2025 17:34:41 +0800 Subject: [PATCH 2/4] add test file --- src/com/hankcs/algorithm/simple_utils.py | 7 +++++++ src/com/hankcs/algorithm/test.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/com/hankcs/algorithm/test.py diff --git a/src/com/hankcs/algorithm/simple_utils.py b/src/com/hankcs/algorithm/simple_utils.py index 8e301db..432c06c 100644 --- a/src/com/hankcs/algorithm/simple_utils.py +++ b/src/com/hankcs/algorithm/simple_utils.py @@ -7,3 +7,10 @@ def count_words(sentence): def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 + +def fibonacci(n): + """Returns the nth Fibonacci number.""" + a, b = 0, 1 + for _ in range(n): + a, b = b, a + b + return a diff --git a/src/com/hankcs/algorithm/test.py b/src/com/hankcs/algorithm/test.py new file mode 100644 index 0000000..f96a1bc --- /dev/null +++ b/src/com/hankcs/algorithm/test.py @@ -0,0 +1,24 @@ +# ...existing code... +def reverse_string(text: str) -> str: + """ + Reverse the characters in a string. + + Args: + text (str): The string to reverse. + + Returns: + str: The reversed string. + """ + return text[::-1] +# ...existing# ...existing code... +def reverse_string(text: str) -> str: + """ + Reverse the characters in a string. + + Args: + text (str): The string to reverse. + + Returns: + str: The reversed string. + """ + return text[::-1] From dceeade793b262e58da211bd7db07c68b689ad16 Mon Sep 17 00:00:00 2001 From: liuchunlin Date: Tue, 9 Sep 2025 15:51:19 +0800 Subject: [PATCH 3/4] adjust test script --- src/com/hankcs/algorithm/simple_utils.py | 5 ++++- src/com/hankcs/algorithm/test.py | 23 +---------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/com/hankcs/algorithm/simple_utils.py b/src/com/hankcs/algorithm/simple_utils.py index 432c06c..f7b95d6 100644 --- a/src/com/hankcs/algorithm/simple_utils.py +++ b/src/com/hankcs/algorithm/simple_utils.py @@ -9,7 +9,10 @@ def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 def fibonacci(n): - """Returns the nth Fibonacci number.""" + if not isinstance(n, int): + raise TypeError("n must be a non-negative integer") + if n < 0: + raise ValueError("n must be non-negative") a, b = 0, 1 for _ in range(n): a, b = b, a + b diff --git a/src/com/hankcs/algorithm/test.py b/src/com/hankcs/algorithm/test.py index f96a1bc..607909b 100644 --- a/src/com/hankcs/algorithm/test.py +++ b/src/com/hankcs/algorithm/test.py @@ -1,24 +1,3 @@ -# ...existing code... -def reverse_string(text: str) -> str: - """ - Reverse the characters in a string. - Args: - text (str): The string to reverse. - - Returns: - str: The reversed string. - """ - return text[::-1] -# ...existing# ...existing code... -def reverse_string(text: str) -> str: - """ - Reverse the characters in a string. - - Args: - text (str): The string to reverse. - - Returns: - str: The reversed string. - """ +def reverse_string(text): return text[::-1] From 9356185d07df7d91d86046d690e50c6a0bce48c7 Mon Sep 17 00:00:00 2001 From: liuchunlin Date: Tue, 9 Sep 2025 16:41:10 +0800 Subject: [PATCH 4/4] fix test file problem --- src/com/hankcs/algorithm/test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/hankcs/algorithm/test.py b/src/com/hankcs/algorithm/test.py index 607909b..6b835ef 100644 --- a/src/com/hankcs/algorithm/test.py +++ b/src/com/hankcs/algorithm/test.py @@ -1,3 +1,7 @@ def reverse_string(text): return text[::-1] + + +if __name__ == "__main__": + print(reverse_string("hello")) \ No newline at end of file