Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

dfa - Use hypothesis to distinguish between automata and python function

I have a python function which describes Language L which gets a word and returns True in case that the word is in the language and return False otherwise. In addition, I have a detemenistic finite automata which desribes another language L2 and I want to check if L2=L. I thought maybe I can use hypothesis libray to get counterexample and distingish between the function and the dfa but I don't know how to combine hypothesis in my code programaticly and not as a test. Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It looks like you asked this question as two parts on the Hypothesis issue tracker - thanks for moving it over here as suggested :-) Porting my answer over too for posterity:

The key insight here is that you can call a Hypothesis-wrapped function like any other, and have the inner function save its inputs. For example:

counterexample = None

@given(x=st.integers())
def check(f, g, x):
    if f(x) != g(x):
        global counterexample
        counterexample = x
        raise AssertionError

with contextlib.suppress(AssertionError):
    check(f=math.sin, g=math.cos)

assert counterexample is not None

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...