forked from FER-NASP/AdvancedAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_SDS.py
More file actions
76 lines (69 loc) · 2.25 KB
/
Copy pathTest_SDS.py
File metadata and controls
76 lines (69 loc) · 2.25 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import unittest
from Trie import Trie
from PatriciaTree import PatriciaTree
from SuffixArray import SuffixArray,StringArray
from General import StringPL
from SuffixTree import SuffixTree
class SimpleStringCases(unittest.TestCase):
def test_Trie(self):
t=Trie()
t.insert("dado")
t.insert("da")
t.insert("dalibor")
t.insert("ana")
t.remove("dado")
self.assertTrue(t.search('dado'))
def test_PatriciaTree1(self):
pt=PatriciaTree()
pt.insert("analisys")
pt.insert("acronym")
b1=pt.search('ana')
pt.insert("analogy")
pt.insert("acrobat")
pt.insert("ana")
self.assertTrue(not b1 and pt.search('ana'))
def test_PatriciaTree2(self):
pt=PatriciaTree()
pt.insert("analisys")
pt.insert("acronym")
pt.insert("analogy")
pt.insert("acrobat")
pt.insert("ana")
pt.remove('analisys')
pt.remove('analogy')
pt.remove('ana')
pt.remove('acronym')
pt.remove('acrobat')
self.assertTrue(not pt.search('analisys'))
def test_SuffixArray1(self):
sa=SuffixArray('banana$')
res = sa.search('nana$')
self.assertTrue(res)
def test_SuffixArray2(self):
arr = []
arr.append(StringPL('prognosis$'))
arr.append(StringPL('programmability$'))
arr.append(StringPL('programmable$'))
arr.append(StringPL('programmatic$'))
arr.append(StringPL('programmatically$'))
arr.append(StringPL('programmed$'))
arr.append(StringPL('programmer$'))
arr.append(StringPL('programmers$'))
arr.append(StringPL('progress$'))
arr.append(StringPL('protected$'))
arr.append(StringPL('protectionism$'))
arr.append(StringPL('protege$'))
arr.append(StringPL('protoplasm$'))
sa=StringArray(arr)
res = sa.search('protection$')
self.assertTrue(res)
def test_SuffixTree1(self):
st = SuffixTree()
st.insert('ABABABCDCDE')
s1 = st.search('BCD')
s2 = st.search('BCE')
s3 = st.search('ACD')
s4 = st.search('DCD')
self.assertTrue(s1 and not s2 and not s3 and s4)
if __name__ == '__main__':
unittest.main()