Skip to content

Commit bc19e68

Browse files
committed
feat: Add test_string.py
1 parent 0ef4b0f commit bc19e68

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/basic/test_string.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Test module for string operations.
3+
"""
4+
5+
import unittest
6+
7+
from src.basic.string import extract_alphanumeric, reverse_string
8+
9+
10+
class TestString(unittest.TestCase):
11+
"""Test class for string operations"""
12+
13+
def test_reverse_string_basic(self):
14+
"""Test for basic string reversal"""
15+
self.assertEqual(reverse_string("hello"), "olleh")
16+
self.assertEqual(reverse_string("python"), "nohtyp")
17+
18+
def test_reverse_string_empty(self):
19+
"""Test for empty string"""
20+
self.assertEqual(reverse_string(""), "")
21+
22+
def test_reverse_string_single_char(self):
23+
"""Test for single character string"""
24+
self.assertEqual(reverse_string("a"), "a")
25+
26+
def test_reverse_string_japanese(self):
27+
"""Test for Japanese string"""
28+
self.assertEqual(reverse_string("こんにちは"), "はちにんこ")
29+
30+
def test_reverse_string_with_spaces(self):
31+
"""Test for string with spaces"""
32+
self.assertEqual(reverse_string("hello world"), "dlrow olleh")
33+
34+
def test_extract_alphanumeric_basic(self):
35+
"""Test for basic alphanumeric extraction"""
36+
self.assertEqual(extract_alphanumeric("Hello123"), "Hello123")
37+
self.assertEqual(extract_alphanumeric("Python3.9"), "Python39")
38+
39+
def test_extract_alphanumeric_with_spaces(self):
40+
"""Test for strings with spaces"""
41+
self.assertEqual(extract_alphanumeric("Hello World 123"), "HelloWorld123")
42+
self.assertEqual(extract_alphanumeric(" abc 123 "), "abc123")
43+
44+
def test_extract_alphanumeric_with_special_chars(self):
45+
"""Test for strings with special characters"""
46+
self.assertEqual(extract_alphanumeric("Hello@World!123"), "HelloWorld123")
47+
self.assertEqual(extract_alphanumeric("$#@123abc!?"), "123abc")
48+
49+
def test_extract_alphanumeric_empty(self):
50+
"""Test for empty string"""
51+
self.assertEqual(extract_alphanumeric(""), "")
52+
53+
def test_extract_alphanumeric_no_alphanumeric(self):
54+
"""Test for string with no alphanumeric characters"""
55+
self.assertEqual(extract_alphanumeric("@#$%^&*()"), "")
56+
57+
def test_extract_alphanumeric_japanese_and_alphanumeric(self):
58+
"""Test for string with Japanese and alphanumeric characters"""
59+
self.assertEqual(extract_alphanumeric("こんにちは123ABC"), "123ABC")

0 commit comments

Comments
 (0)