File: test_arith_ncd.py

package info (click to toggle)
textdistance 4.6.3-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: python: 2,728; sh: 4; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (3)
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
35
# built-in
from fractions import Fraction
from math import isclose

# external
import pytest

# project
import textdistance


ALG = textdistance.arith_ncd


@pytest.mark.parametrize('left, right, expected', [
    ('test', 'test', 1),
    ('test', 'nani', 2.1666666666666665),
])
def test_similarity(left, right, expected):
    actual = ALG(left, right)
    assert isclose(actual, expected)


def test_make_probs():
    alg = textdistance.ArithNCD(terminator='\x00')
    probs = alg._make_probs('lol', 'lal')
    assert probs['l'] == (Fraction(0, 1), Fraction(4, 7))
    assert probs['o'][1] == Fraction(1, 7)
    assert probs['a'][1] == Fraction(1, 7)


def test_arith_output():
    alg = textdistance.ArithNCD(terminator='\x00')
    fraction = alg._compress('BANANA')
    assert fraction.numerator == 1525