File: test_matrix.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 (38 lines) | stat: -rw-r--r-- 746 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
36
37
38
# external
import pytest

# project
import textdistance


ALG = textdistance.Matrix
# https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
NW_MATRIX = {
    ('A', 'A'): 10,
    ('G', 'G'): 7,
    ('C', 'C'): 9,
    ('T', 'T'): 8,
    ('A', 'G'): -1,
    ('A', 'C'): -3,
    ('A', 'T'): -4,
    ('G', 'C'): -5,
    ('G', 'T'): -3,
    ('C', 'T'): 0,
}


@pytest.mark.parametrize('left, right, expected', [
    ('', '', 1),
    ('', 'a', 0),
    ('abcd', 'abcd', 1),
    ('A', 'C', -3),
    ('G', 'G', 7),
    ('A', 'A', 10),
    ('T', 'A', -4),
    ('T', 'C', 0),
    ('A', 'G', -1),
    ('C', 'T', 0),
])
def test_distance(left, right, expected):
    actual = ALG(NW_MATRIX, symmetric=True)(left, right)
    assert actual == expected