added tests for walk and type pred
This commit is contained in:
parent
ed7b084bd1
commit
fa776a08f0
2 changed files with 13 additions and 10 deletions
|
|
@ -29,13 +29,16 @@ class TestSTLUtils(unittest.TestCase):
|
||||||
self.assertEqual(set(map(str, stl.utils.param_lens(phi).get_all())), set())
|
self.assertEqual(set(map(str, stl.utils.param_lens(phi).get_all())), set())
|
||||||
self.assertEqual(phi, phi2)
|
self.assertEqual(phi, phi2)
|
||||||
|
|
||||||
def test_walk(self):
|
@params(("x > 5", 1), ("~(x)", 2), ("(F[0,1](x)) & (~(G[0, 2](y)))", 6))
|
||||||
raise NotImplementedError
|
def test_walk(self, phi_str, l):
|
||||||
|
self.assertEqual(l, len(list(stl.walk(stl.parse(phi_str)))))
|
||||||
|
|
||||||
def test_type_pred(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
@params(([], False, False),([int], True, False), ([int, bool], True, True))
|
||||||
|
def test_type_pred(self, types, b1, b2):
|
||||||
|
pred = stl.utils.type_pred(*types)
|
||||||
|
self.assertFalse(pred(None))
|
||||||
|
self.assertEqual(pred(1), b1)
|
||||||
|
self.assertEqual(pred(True), b2)
|
||||||
|
|
||||||
def test_ast_lens(self):
|
def test_ast_lens(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ from stl.ast import (LinEq, And, Or, NaryOpSTL, F, G, Interval, Neg,
|
||||||
AtomicPred)
|
AtomicPred)
|
||||||
from stl.types import STL, STL_Generator, MTL
|
from stl.types import STL, STL_Generator, MTL
|
||||||
|
|
||||||
def walk(phi:STL, bfs:bool=False) -> STL_Generator:
|
def walk(phi:STL) -> STL_Generator:
|
||||||
"""Walks Ast. Defaults to DFS unless BFS flag is set."""
|
"""DSF walk of the AST."""
|
||||||
pop = deque.popleft if bfs else deque.pop
|
pop = deque.pop
|
||||||
children = deque([phi])
|
children = deque([phi])
|
||||||
while len(children) != 0:
|
while len(children) > 0:
|
||||||
node = pop(children)
|
node = pop(children)
|
||||||
yield node
|
yield node
|
||||||
children.extend(node.children())
|
children.extend(node.children())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue