stl generator
This commit is contained in:
parent
7e3d43bbea
commit
212a8c195a
3 changed files with 38 additions and 14 deletions
30
stl/hypothesis.py
Normal file
30
stl/hypothesis.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from hypothesis_cfg import ContextFreeGrammarStrategy
|
||||
|
||||
from hypothesis.searchstrategy.strategies import SearchStrategy
|
||||
from hypothesis.strategies import integers
|
||||
|
||||
import stl
|
||||
|
||||
|
||||
GRAMMAR = {
|
||||
'phi': (('Unary', '(', 'phi', ')'),
|
||||
('(', 'phi', ')', 'Binary', '(', 'phi', ')'),
|
||||
('AP',)),
|
||||
'Unary': (('~',), ('G',), ('F',), ('X',)),
|
||||
'Binary': ((' | ',), (' & ',), (' U ',)),
|
||||
}
|
||||
|
||||
|
||||
class SignalTemporalLogicStategy(SearchStrategy):
|
||||
def __init__(self, max_length: int):
|
||||
super(SearchStrategy, self).__init__()
|
||||
self.cfg_gen = ContextFreeGrammarStrategy(
|
||||
GRAMMAR, max_length=max_length, start='phi')
|
||||
|
||||
def do_draw(self, data):
|
||||
# TODO: randomly assign all intervals
|
||||
# TODO: randomly decide between linear predicate or boolean predicates
|
||||
# TODO: randomly generate boolean predicate
|
||||
# TODO: randomly generate linear predicate
|
||||
phi = stl.parse("".join(self.cfg_gen.do_draw(data)))
|
||||
return phi
|
||||
|
|
@ -1,21 +1,13 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import stl
|
||||
from hypothesis import given, note
|
||||
from hypothesis_cfg import ContextFreeGrammarStrategy
|
||||
from hypothesis import given, event
|
||||
|
||||
GRAMMAR = {
|
||||
'phi': (('Unary', '(', 'phi', ')'),
|
||||
('(', 'phi', ')', 'Binary', '(', 'phi', ')'),
|
||||
('AP',)),
|
||||
'Unary': (('~',), ('G',), ('F',), ('X',)),
|
||||
'Binary': ((' | ',), (' & ',), (' U ',)),
|
||||
}
|
||||
from stl.hypothesis import SignalTemporalLogicStategy
|
||||
|
||||
|
||||
@given(ContextFreeGrammarStrategy(GRAMMAR, length=15, start='phi'))
|
||||
def test_invertable_repr(foo):
|
||||
note(''.join(foo))
|
||||
phi = stl.parse(''.join(foo))
|
||||
@given(SignalTemporalLogicStategy(max_length=25))
|
||||
def test_invertable_repr(phi):
|
||||
event(str(phi))
|
||||
assert str(phi) == str(stl.parse(str(phi)))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue