示例#1
0
    def pastify(self):
        # Translate bounded future STL to past STL
        pastifier = STLPastifier()
        self.top.accept(pastifier)
        past = pastifier.pastify(self.top)
        self.top = past

        # evaluate modular sub-specs
        for key in self.var_subspec_dict:
            node = self.var_subspec_dict[key]
            node.accept(pastifier)
            node = pastifier.pastify(node)
            self.var_subspec_dict[key] = node
示例#2
0
    def test_variable_1(self):
        old_node = Variable('req', '', 'output')
        pastifier = STLPastifier()
        old_node.accept(pastifier)
        new_node = pastifier.pastify(old_node)

        self.assertEqual('req', new_node.name,
                         'Variable pastification assertion')

        old_node = Variable('myvar.req', 'val', 'output')
        pastifier = STLPastifier()
        old_node.accept(pastifier)
        new_node = pastifier.pastify(old_node)

        self.assertEqual('myvar.req.val', new_node.name,
                         'Variable pastification assertion')
示例#3
0
    def test_constant(self):
        old_node = Constant(2)
        pastifier = STLPastifier()
        old_node.accept(pastifier)
        new_node = pastifier.pastify(old_node)

        self.assertEqual(str(2), new_node.name,
                         'Constant pastification assertion')
示例#4
0
    def test_variable_2(self):
        old_node = Variable('req', '', 'output')
        old_node.horizon = int(5)
        pastifier = STLPastifier()
        old_node.accept(pastifier)
        new_node = pastifier.pastify(old_node)

        self.assertEqual('once[5,5](req)', new_node.name,
                         'Variable pastification assertion')
示例#5
0
    def test_historically(self):
        var_node = Variable('req', '', 'output')
        node = Historically(var_node)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('historically(req)', new_node.name,
                         'Historically pastification assertion')
示例#6
0
    def test_previous_1(self):
        var_node = Variable('req', '', 'output')
        abs_node = Previous(var_node)

        pastifier = STLPastifier()
        abs_node.accept(pastifier)
        new_node = pastifier.pastify(abs_node)

        self.assertEqual('previous(req)', new_node.name,
                         'Previous pastification assertion')
示例#7
0
    def test_precedes_0_1(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        add_node = TimedPrecedes(var_node_1, var_node_2, 0, 1)

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(req)precedes[0,1](gnt)', new_node.name,
                         'Precedes pastification assertion')

        add_node.horizon = 5
        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(once[5,5](req))precedes[0,1](once[5,5](gnt))',
                         new_node.name, 'Precedes pastification assertion')
示例#8
0
    def test_eventually_0_1(self):
        var_node = Variable('req', '', 'output')
        node = TimedEventually(var_node, 0, 1)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('once[0,1](req)', new_node.name,
                         'Eventually pastification assertion')

        node.horizon = 5

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('once[0,1](once[4,4](req))', new_node.name,
                         'Eventually pastification assertion')
示例#9
0
    def test_always_0_1(self):
        var_node = Variable('req', '', 'output')
        node = TimedAlways(var_node, 0, 1)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('historically[0,1](req)', new_node.name,
                         'Always pastification assertion')

        node.horizon = 5

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('historically[0,1](once[4,4](req))', new_node.name,
                         'Always pastification assertion')
示例#10
0
    def test_since(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        add_node = Since(var_node_1, var_node_2)

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(req)since(gnt)', new_node.name,
                         'Since pastification assertion')

        add_node.horizon = 5
        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(once[5,5](req))since(once[5,5](gnt))',
                         new_node.name, 'Since pastification assertion')
示例#11
0
    def test_next_1(self):
        var_node = Variable('req', '', 'output')
        abs_node = Next(var_node)
        abs_node.horizon = 1

        pastifier = STLPastifier()
        abs_node.accept(pastifier)
        new_node = pastifier.pastify(abs_node)

        self.assertEqual('req', new_node.name, 'Next pastification assertion')
示例#12
0
    def test_fall(self):
        var_node = Variable('req', '', 'output')
        node = Fall(var_node)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('fall(req)', new_node.name,
                         'Fall pastification assertion')
示例#13
0
    def test_once(self):
        var_node = Variable('req', '', 'output')
        node = Once(var_node)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('once(req)', new_node.name,
                         'Once pastification assertion')

        node.horizon = 5

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('once(once[5,5](req))', new_node.name,
                         'Once pastification assertion')
示例#14
0
    def test_not(self):
        var_node = Variable('req', '', 'output')
        node = Neg(var_node)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('not(req)', new_node.name,
                         'Negation pastification assertion')
示例#15
0
    def test_abs_1(self):
        var_node = Variable('req', '', 'output')
        abs_node = Abs(var_node)

        pastifier = STLPastifier()
        abs_node.accept(pastifier)
        new_node = pastifier.pastify(abs_node)

        self.assertEqual('abs(req)', new_node.name,
                         'Absolute Value pastification assertion')
示例#16
0
    def test_predicate_neq(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        node = Predicate(var_node_1, var_node_2, StlComparisonOperator.NEQ)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('(req)!=(gnt)', new_node.name,
                         'Predicate NEQ pastification assertion')
示例#17
0
    def test_subtraction(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        sub_node = Subtraction(var_node_1, var_node_2)

        pastifier = STLPastifier()
        sub_node.accept(pastifier)
        new_node = pastifier.pastify(sub_node)

        self.assertEqual('(req)-(gnt)', new_node.name,
                         'Subtraction pastification assertion')
示例#18
0
    def test_xor(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        add_node = Xor(var_node_1, var_node_2)

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(req)xor(gnt)', new_node.name,
                         'Xor pastification assertion')
示例#19
0
    def test_conjunction(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        add_node = Conjunction(var_node_1, var_node_2)

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(req)and(gnt)', new_node.name,
                         'Conjunction pastification assertion')
示例#20
0
    def test_division(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        node = Division(var_node_1, var_node_2)

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('(req)/(gnt)', new_node.name,
                         'Division pastification assertion')
示例#21
0
    def test_abs_2(self):
        var_node = Variable('req', '', 'output')
        var_node.horizon = 5
        abs_node = Abs(var_node)
        abs_node.horizon = 5

        pastifier = STLPastifier()
        abs_node.accept(pastifier)
        new_node = pastifier.pastify(abs_node)

        self.assertEqual('abs(once[5,5](req))', new_node.name,
                         'Absolute Value pastification assertion')
示例#22
0
    def test_predicate_leq_2(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        node = Predicate(var_node_1, var_node_2, StlComparisonOperator.LEQ)
        node.horizon = 5

        pastifier = STLPastifier()
        node.accept(pastifier)
        new_node = pastifier.pastify(node)

        self.assertEqual('(once[5,5](req))<=(once[5,5](gnt))', new_node.name,
                         'Predicate LEQ pastification assertion')
示例#23
0
    def test_complex_past_2(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        rise_node = Rise(var_node_1)
        hist_node = Historically(var_node_2)
        once_node = TimedOnce(hist_node, 1, 2)
        add_node = TimedSince(rise_node, once_node, 2, 6)
        add_node.horizon = 0

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(rise(req))since[2,6](once[1,2](historically(gnt)))',
                         new_node.name, 'Complex pastification assertion')
示例#24
0
    def test_complex_mixed_2(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')

        ev_node = TimedEventually(var_node_1, 5, 6)
        once_node = TimedOnce(var_node_2, 1, 2)
        alw_node = TimedAlways(once_node, 3, 3)
        add_node = Implies(ev_node, alw_node)
        add_node.horizon = 6

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual('(once[0,1](req))->(once[1,2](once[3,3](gnt)))',
                         new_node.name, 'Complex pastification assertion')
示例#25
0
    def test_complex_bounded_future_2(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        var_node_3 = Variable('ack', '', 'output')

        until_node = TimedUntil(var_node_1, var_node_2, 1, 2)
        ev_node = TimedEventually(var_node_3, 0, 6)
        add_node = Implies(until_node, ev_node)
        add_node.horizon = 6

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual(
            '((once[4,4](req))precedes[1,2](once[4,4](gnt)))->(once[0,6](ack))',
            new_node.name, 'Complex pastification assertion')
示例#26
0
    def test_complex_bounded_future_1(self):
        var_node_1 = Variable('req', '', 'output')
        var_node_2 = Variable('gnt', '', 'output')
        cnt_node_1 = Constant(3)
        cnt_node_2 = Constant(3)
        pd_node_1 = Predicate(var_node_1, cnt_node_1,
                              StlComparisonOperator.GEQ)
        pd_node_2 = Predicate(var_node_2, cnt_node_2,
                              StlComparisonOperator.GEQ)
        rise_node = Rise(pd_node_1)
        hist_node = TimedAlways(pd_node_2, 3, 4)
        once_node = TimedEventually(hist_node, 1, 2)
        add_node = Implies(rise_node, once_node)
        add_node.horizon = 6

        pastifier = STLPastifier()
        add_node.accept(pastifier)
        new_node = pastifier.pastify(add_node)

        self.assertEqual(
            '(rise((once[6,6](req))>=(3)))->(once[0,1](historically[0,1]((gnt)>=(3))))',
            new_node.name, 'Complex pastification assertion')