Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 551 Bytes

README.md

File metadata and controls

24 lines (19 loc) · 551 Bytes

Early version of implementation of Hypothesis strategy for Context Free Grammars.

from hypothesis import given
from hypothesis_cfg import ContextFreeGrammarStrategy

# Production rules
GRAMMAR = {
    'P': (('P', 'P'), ('A', 'R')),
    'A': (('L', 'P'), ('(',)),
    'L': (('(',),),
    'R': ((')',),),
}

@given(ContextFreeGrammarStrategy(GRAMMAR, max_length=20, start='P'))
def test_foo(foo):
    assert len(foo) <= 20

Currently no guarantees on the distribution. TODO: cite relevant works.