Ejemplo n.º 1
0
def assert_banded(s, t, maxdiff):
    banded_dist = ed(s, t, maxdiff=maxdiff)
    true_dist = ed(s, t)
    if true_dist > maxdiff:
        assert banded_dist > maxdiff
    else:
        assert banded_dist == true_dist
Ejemplo n.º 2
0
def test_edit_distance():
    assert ed("", "") == 0
    assert ed("", "A") == 1
    assert ed("A", "B") == 1
    assert ed("A", "A") == 0
    assert ed("A", "AB") == 1
    assert ed("BA", "AB") == 2
    for s, t in STRING_PAIRS:
        assert ed(s, "") == len(s)
        assert ed("", s) == len(s)
        assert ed(s, t) == ed(t, s)
Ejemplo n.º 3
0
def test_edit_distance():
    assert ed('', '') == 0
    assert ed('', 'A') == 1
    assert ed('A', 'B') == 1
    assert ed('A', 'A') == 0
    assert ed('A', 'AB') == 1
    assert ed('BA', 'AB') == 2
    for s, t in STRING_PAIRS:
        assert ed(s, '') == len(s)
        assert ed('', s) == len(s)
        assert ed(s, t) == ed(t, s)
Ejemplo n.º 4
0
def test_edit_distance_bytes():
    assert ed(b"", b"") == 0
    assert ed(b"", b"A") == 1
    assert ed(b"A", b"B") == 1
    assert ed(b"A", b"A") == 0
    assert ed(b"A", b"AB") == 1
    assert ed(b"BA", b"AB") == 2
    for s, t in STRING_PAIRS:
        s = s.encode("ascii")
        t = t.encode("ascii")
        assert ed(s, b"") == len(s)
        assert ed(b"", s) == len(s)
        assert ed(s, t) == ed(t, s)
Ejemplo n.º 5
0
def test_edit_distance_bytes():
    assert ed(b'', b'') == 0
    assert ed(b'', b'A') == 1
    assert ed(b'A', b'B') == 1
    assert ed(b'A', b'A') == 0
    assert ed(b'A', b'AB') == 1
    assert ed(b'BA', b'AB') == 2
    for s, t in STRING_PAIRS:
        s = s.encode('ascii')
        t = t.encode('ascii')
        assert ed(s, b'') == len(s)
        assert ed(b'', s) == len(s)
        assert ed(s, t) == ed(t, s)
Ejemplo n.º 6
0
def test_compare_to_edit_dist():
    for s, t in STRING_PAIRS:
        assert ed(s, t) == ed_aff(s, t, [1] * len(s), 1, 1)