Example #1
0
def test_enumeration_when_sizes_do_not_agree():
    dfa = ConcreteDFA([{
        0: 1,
        1: 2
    }, {}, {
        1: 3
    }, {}], {1, 3})  # 0  # 1  # 2  # 3

    assert list(dfa.all_matching_strings()) == [b"\0", b"\1\1"]
Example #2
0
def test_enumeration_of_very_long_strings():
    """This test is mainly testing that it terminates. If we were
    to use a naive breadth first search for this it would take
    forever to run because it would run in time roughly 256 ** 50.
    """
    size = 50
    dfa = ConcreteDFA([{c: n + 1
                        for c in range(256)}
                       for n in range(100)] + [{}], {size})

    for i, s in enumerate(dfa.all_matching_strings()):
        assert len(s) == size
        assert int.from_bytes(s, "big") == i
        if i >= 1000:
            break