-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_gst.py
51 lines (40 loc) · 1.53 KB
/
test_gst.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from gst import GST
import unittest
class GSTTest(unittest.TestCase):
def test_normal(self):
text = 'abcabcd'
gst_obj = GST()
gst_obj.add_text(text, 0)
gst_obj.traverse(text)
self.assertEqual(list(gst_obj.search('c')), [0])
self.assertEqual(list(gst_obj.search('abcd')), [0])
self.assertEqual(list(gst_obj.search('abcc')), [])
#@unittest.skip("")
def test_two_text(self):
text = "abc_ccc"
gst_obj = GST()
for index, t in enumerate(text.split('_')):
gst_obj.add_text(t, index)
gst_obj.traverse(text)
self.assertEqual(list(gst_obj.search('c')), [0, 1])
self.assertEqual(list(gst_obj.search('cc')), [1])
self.assertEqual(list(gst_obj.search('bc')), [0])
self.assertEqual(list(gst_obj.search('d')), [])
def test_explicit_end(self):
text = "ababa"
gst_obj = GST()
gst_obj.add_text(text, 0)
gst_obj.traverse(text)
self.assertEqual(list(gst_obj.search('c')), [])
self.assertEqual(list(gst_obj.search('aba')), [0])
def test_implicit_end(self):
text = "c_aa"
gst_obj = GST()
for index, t in enumerate(text.split('_')):
gst_obj.add_text(t, index)
gst_obj.traverse(text)
self.assertEqual(list(gst_obj.search('c')), [0])
self.assertEqual(list(gst_obj.search('ca')), [])
self.assertEqual(list(gst_obj.search('aa')), [1])
self.assertEqual(list(gst_obj.search('d')), [])