|
5 | 5 | import unittest |
6 | 6 |
|
7 | 7 | from pythainlp.braille import thai_text_braille, thai_word_braille |
| 8 | +from pythainlp.braille.core import Braille |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class TestCase(unittest.TestCase): |
@@ -40,6 +41,11 @@ def test_thai_word_braille(self) -> None: |
40 | 41 | self.assertEqual(thai_word_braille("แก้ม"), "⠣⠛⠲⠍") |
41 | 42 | self.assertEqual(thai_word_braille("เรียน"), "⠗⠷⠝") |
42 | 43 |
|
| 44 | + # Test edge case: characters not in mapping |
| 45 | + # (This should return empty string as no tokens are mappable) |
| 46 | + result = thai_word_braille("§") |
| 47 | + self.assertIsInstance(result, str) |
| 48 | + |
43 | 49 | def test_thai_text_braille(self) -> None: |
44 | 50 | """Test thai_text_braille function.""" |
45 | 51 | # Test simple text - word_tokenize splits on spaces so we get 3 tokens |
@@ -68,3 +74,43 @@ def test_thai_text_braille(self) -> None: |
68 | 74 | self.assertEqual( |
69 | 75 | thai_text_braille("แมวกิน ปลา"), ["⠣⠍⠺", "⠛⠃⠝", " ", "⠯⠇⠡"] |
70 | 76 | ) |
| 77 | + |
| 78 | + def test_braille_class(self) -> None: |
| 79 | + """Test Braille class methods.""" |
| 80 | + # Test tobraille method with string input (single character) |
| 81 | + braille_str = Braille("1245") |
| 82 | + self.assertEqual(braille_str.tobraille(), "⠛") |
| 83 | + |
| 84 | + # Test tobraille method with list of single element |
| 85 | + braille_list = Braille(["1245"]) |
| 86 | + result = braille_list.tobraille() |
| 87 | + self.assertIsInstance(result, str) |
| 88 | + # This creates ['1', '2', '4', '5'] which gives 4 separate braille chars |
| 89 | + self.assertGreater(len(result), 0) |
| 90 | + |
| 91 | + # Test tobraille method with multiple patterns (list of lists) |
| 92 | + # This is the structure used by thai_word_braille |
| 93 | + braille_multi = Braille([["1245"], ["13"]]) |
| 94 | + result = braille_multi.tobraille() |
| 95 | + self.assertIsInstance(result, str) |
| 96 | + self.assertEqual(len(result), 2) # Two braille characters |
| 97 | + |
| 98 | + # Test with empty data |
| 99 | + braille_empty = Braille([]) |
| 100 | + self.assertEqual(braille_empty.tobraille(), "") |
| 101 | + |
| 102 | + # Test with empty string |
| 103 | + braille_empty_str = Braille("") |
| 104 | + self.assertEqual(braille_empty_str.tobraille(), "") |
| 105 | + |
| 106 | + # Test printbraille method with string input (individual digits) |
| 107 | + braille_print = Braille("1245") |
| 108 | + result = braille_print.printbraille() |
| 109 | + self.assertIsInstance(result, str) |
| 110 | + self.assertGreater(len(result), 0) |
| 111 | + |
| 112 | + # Test printbraille with single-element list |
| 113 | + # When list has 1 element, it gets converted to sorted list of chars |
| 114 | + braille_print_single = Braille(["12"]) |
| 115 | + result_single = braille_print_single.printbraille() |
| 116 | + self.assertIsInstance(result_single, str) |
0 commit comments