Skip to content

Commit 3f88fbe

Browse files
Copilotwannaphong
andcommitted
Add comprehensive Braille class tests for 100% coverage
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
1 parent 499e0bf commit 3f88fbe

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/core/test_braille.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66

77
from pythainlp.braille import thai_text_braille, thai_word_braille
8+
from pythainlp.braille.core import Braille
89

910

1011
class TestCase(unittest.TestCase):
@@ -40,6 +41,11 @@ def test_thai_word_braille(self) -> None:
4041
self.assertEqual(thai_word_braille("แก้ม"), "⠣⠛⠲⠍")
4142
self.assertEqual(thai_word_braille("เรียน"), "⠗⠷⠝")
4243

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+
4349
def test_thai_text_braille(self) -> None:
4450
"""Test thai_text_braille function."""
4551
# Test simple text - word_tokenize splits on spaces so we get 3 tokens
@@ -68,3 +74,43 @@ def test_thai_text_braille(self) -> None:
6874
self.assertEqual(
6975
thai_text_braille("แมวกิน ปลา"), ["⠣⠍⠺", "⠛⠃⠝", " ", "⠯⠇⠡"]
7076
)
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

Comments
 (0)