From adb4cb68849cf504e189517acd8bc1de80839855 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Sat, 25 Feb 2017 18:48:15 -0800 Subject: [PATCH] test vars in phi --- stl/test_utils.py | 8 +++++--- stl/utils.py | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/stl/test_utils.py b/stl/test_utils.py index ec96ec9..37ec2af 100644 --- a/stl/test_utils.py +++ b/stl/test_utils.py @@ -8,7 +8,6 @@ from sympy import Symbol ex1 = ("F[b?, 1]G[0, c?](x > a?)", {"a?", "b?", "c?"}) ex2 = ("G[0, c?](x > a?)", {"a?", "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)") 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(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): raise NotImplementedError - def test_terms_lens(self): raise NotImplementedError - def test_f_neg_or_canonical_form(self): raise NotImplementedError diff --git a/stl/utils.py b/stl/utils.py index 6dbe234..a818bad 100644 --- a/stl/utils.py +++ b/stl/utils.py @@ -21,6 +21,9 @@ def walk(phi:STL) -> STL_Generator: yield node 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]: ast_types = set(args)