def test_count_below_bound_is_the_same(re, m, n): assume(rd.has_matches(re)) m, n = sorted((m, n)) count1 = rd.LanguageCounter(*rd.build_dfa(re)).count(m) count2 = rd.LanguageCounter(*rd.build_dfa(rd.bounded(re, n))).count(m) assert count1 == count2
def test_can_simulate_accurately(regex, seed, max_size, param): assume(param > 0) assume(rd.has_matches(regex)) if max_size is not None: assume(rd.has_matches(rd.bounded(regex, max_size))) sim = Simulator(regex, seed) d = sim.draw(param, max_size=max_size) try: next(d) except ParamTooLarge: assert param > 0 reject() for _ in range(10): x = next(d) assert rd.matches(regex, x) if max_size is not None: assert len(x) <= max_size
def test_lexmin_of_mutated_regex_is_refutation(x, data): assume(rd.has_matches(x)) accepting, transitions = rd.build_dfa(x) j = data.draw(st.integers(0, len(accepting) - 1)) assume(transitions[j]) c = data.draw(st.sampled_from(sorted(transitions[j]))) transitions[j][c] = data.draw(st.integers(0, len(accepting) - 1)) y = rd.decompile_dfa(accepting, transitions) assume(rd.has_matches(y)) assume(not rd.equivalent(x, y)) w = rd.lexmin(symdiff(x, y)) assert w is not None assert w == rd.witness_difference(x, y)
def test_characters_in_same_class_produce_equivalent_expressions(re): assume(rd.has_matches(re)) classes = rd.character_classes(re) assume(any(len(cs) > 1 for cs in classes)) for cs in classes: if len(cs) > 1: derivs = [rd.derivative(re, c) for c in cs] for a in derivs: for b in derivs: assert rd.equivalent(a, b)
def test_can_build_a_dfa(re): assume(rd.has_matches(re)) rd.build_dfa(re)
def test_decompilation(re): assume(rd.has_matches(re)) dfa = rd.build_dfa(re) rewritten = rd.decompile_dfa(*dfa) assert rd.equivalent(re, rewritten)
def test_infinite_regex_have_more_than_one_solution(reg): assume(rd.is_infinite(reg)) x = rd.subtract(reg, rd.literal(rd.lexmin(reg))) assert rd.has_matches(x)
def test_non_empty_is_identity_on_non_nullable(re): assume(not re.nullable) assume(rd.has_matches(re)) assert rd.nonempty(re) is re
def test_bounded_min_matches_bounds(re, n): bd = rd.bounded(re, n) assume(rd.has_matches(bd)) assert len(rd.lexmin(bd)) <= n