Пример #1
0
def test_bounds_propagate_through_intersections():
    x = rd.star(rd.char(b'\0\1'))
    y = rd.star(rd.char(b'\1\2'))
    assert isinstance(
        rd.bounded(rd.intersection(x, y), 3),
        rd.Intersection
    )
Пример #2
0
def test_derivatives_of_intersection():
    x = rd.star(rd.char(b'\0\1'))
    y = rd.star(rd.literal(b'\0\1'))
    z = rd.intersection(x, y)
    d1 = rd.derivative(z, 0)
    d2 = rd.derivative(d1, 1)
    assert d2 is z
Пример #3
0
def test_trival_dfa_from_intersection():
    assert rd.build_dfa(
        rd.intersection(rd.char(b'\x00'), rd.char(b'\x00\x01'))) == (
        [False, True], [{0: 1}, {}]
    )
Пример #4
0
def test_can_walk_graph_for_infintiy():
    assert rd.is_infinite(rd.intersection(
        rd.star(rd.char(b'01')), rd.star(rd.char(b'12'))
    ))
Пример #5
0
def test_self_intersection_is_identity():
    x = rd.char(0)
    assert rd.intersection(x, x, x) is x
Пример #6
0
def test_empty_kills_intersections():
    assert rd.intersection(rd.Empty, rd.Epsilon) is rd.Empty
Пример #7
0
def test_epsilon_prunes_down_intersections():
    assert rd.intersection(rd.Epsilon, rd.star(rd.char(0))) is rd.Epsilon
    assert rd.intersection(rd.Epsilon, rd.char(0)) is rd.Empty
Пример #8
0
def test_flattens_intersections():
    x = rd.star(rd.char(b'01'))
    y = rd.star(rd.char(b'02'))
    z = rd.star(rd.char(b'03'))
    assert rd.intersection(x, rd.intersection(y, z)) is \
        rd.intersection(rd.intersection(x, z), y)
Пример #9
0
@given(regex())
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 symdiff(x, y):
    return rd.union(rd.subtract(x, y), rd.subtract(y, x))


@example(
    rd.union(
        rd.char(b'\x00'), rd.subtract(rd.star(rd.char(b'\x01')), rd.Epsilon)),
    rd.intersection(rd.char(b'\x00'), rd.star(rd.char(b'\x00')))
)
@example(x=rd.literal(b'01'), y=rd.literal(b'11'))
@given(regex(), regex())
def test_lexmin_of_symmetric_difference_is_refutation(x, 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)


@example(rd.union(rd.char(b'\0'), rd.star(rd.char(b'\x00'))))
@given(regex())
def test_no_refutation_for_decompilation(re):
    dec = rd.decompile_dfa(*rd.build_dfa(re))
    assert rd.witness_difference(dec, re) is None