def test_a_verifier_retrieves_previous_failing_examples_from_the_database(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database)) verifier.falsify(lambda x: x < 11, int) called = [] def save_calls(t): called.append(t) return False verifier2 = Verifier(settings=hs.Settings(database=database)) verifier2.falsify(save_calls, int) assert called[0] == 11 assert all(0 <= x <= 11 for x in called)
def test_does_not_falsify_if_all_args_given(): verifier = Verifier() verifier.falsify = None @given(int, int, verifier=verifier) def foo(x, y): pass foo(1, 2)
def test_can_falsify_in_derandomize_mode(): settings = Settings(derandomize=True) v = Verifier(settings=settings) v.falsify(lambda x: x > 0, int)
def smallest_tree(predicate): d = NAryTree(int, int, int) strat = strategy(d) v = Verifier() return strat.reify(v.falsify(lambda t: not predicate(t), d)[0])
def test_a_verifier_can_still_do_its_thing_if_a_saved_example_fails(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database)) verifier.falsify(lambda x: x < 11, int) verifier2 = Verifier(settings=hs.Settings(database=database)) verifier2.falsify(lambda x: x < 100, int)
def test_a_verifier_saves_any_failing_examples_in_its_database(): database = ExampleDatabase() verifier = Verifier(settings=hs.Settings(database=database)) counterexample = verifier.falsify(lambda x: x > 0, int) saved = list(database.storage_for((int, )).fetch()) assert saved == [counterexample]