File: test_matching_blocks.py

package info (click to toggle)
python-levenshtein 0.27.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 304 kB
  • sloc: cpp: 724; python: 291; makefile: 20; sh: 13
file content (24 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import annotations

from rapidfuzz.distance import MatchingBlock

from Levenshtein import editops, matching_blocks


def test_simple():
    a, b = "spam", "park"
    assert matching_blocks(editops(a, b), a, b) == [
        MatchingBlock(1, 0, 2),
        MatchingBlock(4, 4, 0),
    ]
    assert matching_blocks(editops(a, b), len(a), len(b)) == [
        MatchingBlock(1, 0, 2),
        MatchingBlock(4, 4, 0),
    ]
    assert matching_blocks(editops("", ""), 0, 0) == [MatchingBlock(0, 0, 0)]
    assert matching_blocks(editops("", "a"), 0, 1) == [MatchingBlock(0, 1, 0)]
    assert matching_blocks(editops("a", ""), 1, 0) == [MatchingBlock(1, 0, 0)]
    assert matching_blocks(editops("a", "a"), 1, 1) == [
        MatchingBlock(0, 0, 1),
        MatchingBlock(1, 1, 0),
    ]