-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_test.py
41 lines (31 loc) · 1.12 KB
/
simple_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
31
32
33
34
35
36
37
38
39
40
41
from refalpy import refal
imports = {
'add': lambda arg: (arg[0] + arg[1],)
}
@refal(imports)
def rules():
pal = True
pal[s.x] = True
pal[s.a, e.b, s.a] = pal[e.b]
pal[e.x] = False
reverse = _
reverse[s.a, e.b] = reverse[e.b], s.a
rle[s.x, e.tail] = rle[{s.x, 1}, e.tail]
rle[{s.x, s.c}, s.x, e.tail] = rle[{s.x, add[s.c, 1]}, e.tail]
rle[{s.x, s.c}, s.y, e.tail] = {s.x, s.c}, rle[{s.y, 1}, e.tail]
rle[e.x] = e.x
uniq[e.p1, s.x, e.p2, s.x, e.p3] = uniq[e.p1, s.x, e.p2, e.p3]
uniq[e.x] = e.x
zip[{s.x, e.a}, {t.x, e.b}] = {s.x, t.x}, zip[{e.a}, {e.b}]
zip[{}, {}] = _
def test():
assert rules('pal', tuple('abba')) == (True,)
assert rules('pal', tuple('a')) == (True,)
assert rules('pal', tuple('abcd')) == (False,)
assert rules('reverse', tuple('abc')) == ('c', 'b', 'a')
assert rules('rle', tuple('aaaabbbcca')) == (
('a', 4), ('b', 3), ('c', 2), ('a', 1))
assert rules('uniq', tuple('aaaabbbcca')) == ('a', 'b', 'c')
assert rules('zip', ((1, 2, 3, 4), ('a', 'b', 'c', 'd'))) == (
(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'))
test()