-
Notifications
You must be signed in to change notification settings - Fork 110
/
test.py
31 lines (21 loc) · 1.08 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import unittest
import wordninja
class TestWordNinja(unittest.TestCase):
def test_simple(self):
self.assertEqual(list(wordninja.split('derekanderson')), ['derek','anderson'])
def test_with_underscores_etc(self):
self.assertEqual(list(wordninja.split('derek anderson')), ['derek','anderson'])
self.assertEqual(list(wordninja.split('derek-anderson')), ['derek','anderson'])
self.assertEqual(list(wordninja.split('derek_anderson')), ['derek','anderson'])
self.assertEqual(list(wordninja.split('derek/anderson')), ['derek','anderson'])
def test_caps(self):
self.assertEqual(list(wordninja.split('DEREKANDERSON')), ['DEREK','ANDERSON'])
def test_digits(self):
self.assertEqual(list(wordninja.split('win32intel')), ['win','32','intel'])
def test_apostrophes(self):
self.assertEqual(list(wordninja.split("that'sthesheriff'sbadge")), ["that's","the","sheriff's","badge"])
def test_custom_model(self):
lm = wordninja.LanguageModel('test_lang.txt.gz')
self.assertEqual(list(lm.split('derek')), ['der','ek'])
if __name__ == '__main__':
unittest.main()