From 673ede60e33b2ae7e96f26cec51c990c091645d9 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Sun, 9 Oct 2016 21:22:15 -0700 Subject: [PATCH] test pstl parsing and param setting --- test_parser.py | 9 +++++++++ test_utils.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test_utils.py diff --git a/test_parser.py b/test_parser.py index b21b258..fbb5349 100644 --- a/test_parser.py +++ b/test_parser.py @@ -9,12 +9,21 @@ ex1 = ('x1 > 2', stl.LinEq( ">", 2.0 )) +ex1_ = ('x1 > a?', stl.LinEq( + (stl.Var(1, Symbol("x1"), stl.ast.t_sym),), + ">", + Symbol("a?") +)) + i1 = stl.Interval(0., 1.) +i1_ = stl.Interval(0., Symbol("b?")) i2 = stl.Interval(2., 3.) ex2 = ('◇[0,1](x1 > 2)', stl.F(i1, ex1[1])) ex3 = ('□[2,3]◇[0,1](x1 > 2)', stl.G(i2, ex2[1])) ex4 = ('(x1 > 2) or ((x1 > 2) or (x1 > 2))', stl.Or((ex1[1], ex1[1], ex1[1]))) +ex5 = ('G[0, b?](x1 > a?)', + stl.G(i1_, ex1_)) class TestSTLParser(unittest.TestCase): @params(ex1, ex2, ex3, ex4) diff --git a/test_utils.py b/test_utils.py new file mode 100644 index 0000000..f417d4c --- /dev/null +++ b/test_utils.py @@ -0,0 +1,30 @@ +import stl +import stl.utils +import pandas as pd +from nose2.tools import params +import unittest +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)") + +val = {"a?": 1.0, "b?": 2.0, "c?": 3.0} + +class TestSTLUtils(unittest.TestCase): + @params(ex1, ex2, ex3) + def test_param_lens(self, phi_str, params): + phi = stl.parse(phi_str) + self.assertEqual(set(map(str, stl.utils.param_lens(phi).get_all())), params) + + @params(ex4, ex5) + def test_set_params(self, phi_str, phi2_str): + phi = stl.parse(phi_str) + phi2 = stl.parse(phi2_str) + phi = stl.utils.set_params(phi, val) + + self.assertEqual(set(map(str, stl.utils.param_lens(phi).get_all())), set()) + self.assertEqual(phi, phi2)