-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·58 lines (44 loc) · 1.75 KB
/
tests.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
52
53
54
55
56
57
58
from src.sequences import Sequences
from src.frames import mass_frame, single_frames
import unittest
def hash_val(text:str):
res = 0
for ch in text:
res = ( res*281 ^ ord(ch)*997) & 0xFFFFFFFF
return res
def run_test(words):
test_hit_all(words)
test_window(words)
test_clone(words)
def test_clone(words):
s = Sequences(words, id_func=hash_val)
c = s.clone()
assert s.id_func == c.id_func
def test_hit_all(words):
v = 'apextrackstackcapechoappleswwindowwindyyescakedddddf'
s = Sequences(words)#, id_func=hash_val)
r = mass_frame(s, v)
e = (('ddddd', 'ww', 'yes', 'stack', 'cake', 'wind', 'w', 'windy', 'win',
'window', 'ape', 'apex', 'extra', 'tracks', 'apples', 'cape', 'echo'),
('cake', 'wind', 'ddddd', 'yes', 'w', 'windy', 'win', 'window',
'ape', 'apex', 'extra', 'tracks', 'apples', 'ww', 'stack',
'cape', 'echo'),
('tracks', 'yes', 'ww', 'stack', 'cake', 'wind', 'w', 'windy',
'win', 'window', 'ape', 'apex', 'extra', 'ddddd', 'apples',
'cape', 'echo'))
assertTupleTupleEqual(r, e)
def test_window(words):
v = 'window'
e = (('ww', 'ddddd', 'w', 'win', 'wind', 'windy', 'window'),
('w', 'window', 'win', 'wind'),
('ww', 'ddddd', 'w', 'windy', 'win', 'wind'))
se = (('ww', 'w', 'wind', 'windy', 'win'), ('w', 'window'), ())
s = Sequences(words)#, id_func=hash_val)
r = mass_frame(s, v)
sr = single_frames(s, v)
assertTupleTupleEqual(r, e)
assertTupleTupleEqual(sr, se)
return r
def assertTupleTupleEqual(tta, ttb):
for x,y in zip(tta,ttb):
unittest.TestCase().assertTupleEqual(tuple(sorted(x)),tuple(sorted(y)))