stl generator
This commit is contained in:
parent
7e3d43bbea
commit
212a8c195a
3 changed files with 38 additions and 14 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
||||||
dist/*
|
dist/*
|
||||||
|
.cache/*
|
||||||
|
.hypothesis/*
|
||||||
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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import stl
|
import stl
|
||||||
from hypothesis import given, note
|
from hypothesis import given, event
|
||||||
from hypothesis_cfg import ContextFreeGrammarStrategy
|
|
||||||
|
|
||||||
GRAMMAR = {
|
from stl.hypothesis import SignalTemporalLogicStategy
|
||||||
'phi': (('Unary', '(', 'phi', ')'),
|
|
||||||
('(', 'phi', ')', 'Binary', '(', 'phi', ')'),
|
|
||||||
('AP',)),
|
|
||||||
'Unary': (('~',), ('G',), ('F',), ('X',)),
|
|
||||||
'Binary': ((' | ',), (' & ',), (' U ',)),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@given(ContextFreeGrammarStrategy(GRAMMAR, length=15, start='phi'))
|
@given(SignalTemporalLogicStategy(max_length=25))
|
||||||
def test_invertable_repr(foo):
|
def test_invertable_repr(phi):
|
||||||
note(''.join(foo))
|
event(str(phi))
|
||||||
phi = stl.parse(''.join(foo))
|
|
||||||
assert str(phi) == str(stl.parse(str(phi)))
|
assert str(phi) == str(stl.parse(str(phi)))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue