test vars in phi

This commit is contained in:
Marcell Vazquez-Chanlatte 2017-02-25 18:48:15 -08:00
parent fa776a08f0
commit adb4cb6884
2 changed files with 8 additions and 3 deletions

View file

@ -8,7 +8,6 @@ from sympy import Symbol
ex1 = ("F[b?, 1]G[0, c?](x > a?)", {"a?", "b?", "c?"}) ex1 = ("F[b?, 1]G[0, c?](x > a?)", {"a?", "b?", "c?"})
ex2 = ("G[0, c?](x > a?)", {"a?", "c?"}) ex2 = ("G[0, c?](x > a?)", {"a?", "c?"})
ex3 = ("F[b?, 1]G[0, c?](x > a?)", {"a?", "b?", "c?"}) ex3 = ("F[b?, 1]G[0, c?](x > a?)", {"a?", "b?", "c?"})
ex4 = ("F[b?, 1]G[0, c?](x > a?)", "F[2, 1]G[0, 3](x > 1)") ex4 = ("F[b?, 1]G[0, c?](x > a?)", "F[2, 1]G[0, 3](x > 1)")
ex5 = ("G[0, c?](x > a?)", "G[0, 3](x > 1)") ex5 = ("G[0, c?](x > a?)", "G[0, 3](x > 1)")
@ -40,14 +39,17 @@ class TestSTLUtils(unittest.TestCase):
self.assertEqual(pred(1), b1) self.assertEqual(pred(1), b1)
self.assertEqual(pred(True), b2) self.assertEqual(pred(True), b2)
@params(("(F[0,1]G[0, 4]((x > 3) or (y < 4))) and (x < 3)", 2))
def test_vars_in_phi(self, phi_str, l):
phi = stl.parse(phi_str)
self.assertEqual(len(stl.utils.vars_in_phi(phi)), l)
def test_ast_lens(self): def test_ast_lens(self):
raise NotImplementedError raise NotImplementedError
def test_terms_lens(self): def test_terms_lens(self):
raise NotImplementedError raise NotImplementedError
def test_f_neg_or_canonical_form(self): def test_f_neg_or_canonical_form(self):
raise NotImplementedError raise NotImplementedError

View file

@ -21,6 +21,9 @@ def walk(phi:STL) -> STL_Generator:
yield node yield node
children.extend(node.children()) children.extend(node.children())
def vars_in_phi(phi):
focus = stl.terms_lens(phi)
return set(focus.tuple_(lens().id, lens().time).get_all())
def type_pred(*args:List[Type]) -> Mapping[Type, bool]: def type_pred(*args:List[Type]) -> Mapping[Type, bool]:
ast_types = set(args) ast_types = set(args)