mtl-aas/stl/test_ast.py
2017-11-11 17:35:48 -08:00

47 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import stl
from stl.hypothesis import SignalTemporalLogicStrategy
from hypothesis import given
@given(SignalTemporalLogicStrategy)
def test_identities(phi):
assert stl.TOP == stl.TOP | phi
assert stl.BOT == stl.BOT & phi
assert stl.TOP == phi | stl.TOP
assert stl.BOT == phi & stl.BOT
assert phi == phi & stl.TOP
assert phi == phi | stl.BOT
assert stl.TOP == stl.TOP & stl.TOP
assert stl.BOT == stl.BOT | stl.BOT
assert stl.TOP == stl.TOP | stl.BOT
assert stl.BOT == stl.TOP & stl.BOT
assert ~stl.BOT == stl.TOP
assert ~stl.TOP == stl.BOT
assert ~~stl.BOT == stl.BOT
assert ~~stl.TOP == stl.TOP
assert (phi & phi) & phi == phi & (phi & phi)
assert (phi | phi) | phi == phi | (phi | phi)
assert ~~phi == phi
def test_lineqs_unittest():
phi = stl.parse('(G[0, 1](x + y > a?)) & (F[1,2](z - x > 0))')
assert len(phi.lineqs) == 2
assert phi.lineqs == {stl.parse('x + y > a?'), stl.parse('z - x > 0')}
phi = stl.parse('(G[0, 1](x + y > a?)) U (F[1,2](z - x > 0))')
assert len(phi.lineqs) == 2
assert phi.lineqs == {stl.parse('x + y > a?'), stl.parse('z - x > 0')}
phi = stl.parse('G(⊥)')
assert phi.lineqs == set()
phi = stl.parse('F()')
assert phi.lineqs == set()
def test_walk():
phi = stl.parse(
'((G[0, 1](x + y > a?)) & (F[1,2](z - x > 0))) | ((X(AP1)) U (AP2))')
assert len(list((~phi).walk())) == 11