python: implement the map and transform functions for formulas

* wrap/python/spot.py: Implement them.
* wrap/python/tests/ltlsimple.py: New tests.
This commit is contained in:
Alexandre Duret-Lutz 2015-09-27 22:02:49 +02:00
parent 2369389850
commit fad05632a2
2 changed files with 42 additions and 0 deletions

View file

@ -74,3 +74,22 @@ assert spot.fnode_instances_check()
#----------------------------------------------------------------------
assert str([x for x in spot.formula('a &b & c')]) == '[a, b, c]'
def switch_g_f(x):
if x._is(spot.G):
return spot.formula.F(switch_g_f(x[0]))
if x._is(spot.F):
return spot.formula.G(switch_g_f(x[0]))
return x.map(switch_g_f)
f = spot.formula('GFa & XFGb & Fc & G(a | b | Fd)')
assert str(switch_g_f(f)) == 'FGa & XGFb & Gc & F(a | b | Gd)'
x = 0
def count_g(f):
global x
if f._is(spot.G):
x += 1
f.traverse(count_g)
assert x == 3