File: test_levenshtein_distance.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 (34 lines) | stat: -rw-r--r-- 891 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
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations

import Levenshtein


def test_empty_string():
    """
    when both strings are empty this is a perfect match
    """
    assert Levenshtein.distance(b"", b"") == 0
    assert Levenshtein.distance("", "") == 0


def test_simple():
    """
    some very simple tests using supported string types
    bytes/unicode
    to catch relatively obvious implementation errors
    """
    assert Levenshtein.distance(b"ABCD", b"AF") == 3
    assert Levenshtein.distance("ABCD", "AF") == 3
    assert Levenshtein.distance(b"ABCD", b"ABCD") == 0
    assert Levenshtein.distance("ABCD", "ABCD") == 0


def test_simple_unicode_tests():
    """
    some very simple tests using unicode
    to catch relatively obvious implementation errors
    """
    s1 = "ÁÄ"
    s2 = "ABCD"
    assert Levenshtein.distance(s1, s2) == 4
    assert Levenshtein.distance(s1, s1) == 0