Skip to content

Commit

Permalink
feat: Add test_string.py
Browse files Browse the repository at this point in the history
  • Loading branch information
teihenn committed Jan 13, 2025
1 parent 0ef4b0f commit bc19e68
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/basic/test_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Test module for string operations.
"""

import unittest

from src.basic.string import extract_alphanumeric, reverse_string


class TestString(unittest.TestCase):
"""Test class for string operations"""

def test_reverse_string_basic(self):
"""Test for basic string reversal"""
self.assertEqual(reverse_string("hello"), "olleh")
self.assertEqual(reverse_string("python"), "nohtyp")

def test_reverse_string_empty(self):
"""Test for empty string"""
self.assertEqual(reverse_string(""), "")

def test_reverse_string_single_char(self):
"""Test for single character string"""
self.assertEqual(reverse_string("a"), "a")

def test_reverse_string_japanese(self):
"""Test for Japanese string"""
self.assertEqual(reverse_string("こんにちは"), "はちにんこ")

def test_reverse_string_with_spaces(self):
"""Test for string with spaces"""
self.assertEqual(reverse_string("hello world"), "dlrow olleh")

def test_extract_alphanumeric_basic(self):
"""Test for basic alphanumeric extraction"""
self.assertEqual(extract_alphanumeric("Hello123"), "Hello123")
self.assertEqual(extract_alphanumeric("Python3.9"), "Python39")

def test_extract_alphanumeric_with_spaces(self):
"""Test for strings with spaces"""
self.assertEqual(extract_alphanumeric("Hello World 123"), "HelloWorld123")
self.assertEqual(extract_alphanumeric(" abc 123 "), "abc123")

def test_extract_alphanumeric_with_special_chars(self):
"""Test for strings with special characters"""
self.assertEqual(extract_alphanumeric("Hello@World!123"), "HelloWorld123")
self.assertEqual(extract_alphanumeric("$#@123abc!?"), "123abc")

def test_extract_alphanumeric_empty(self):
"""Test for empty string"""
self.assertEqual(extract_alphanumeric(""), "")

def test_extract_alphanumeric_no_alphanumeric(self):
"""Test for string with no alphanumeric characters"""
self.assertEqual(extract_alphanumeric("@#$%^&*()"), "")

def test_extract_alphanumeric_japanese_and_alphanumeric(self):
"""Test for string with Japanese and alphanumeric characters"""
self.assertEqual(extract_alphanumeric("こんにちは123ABC"), "123ABC")

0 comments on commit bc19e68

Please sign in to comment.