2018-02-23 13:35:38 +00:00
|
|
|
from __future__ import unicode_literals
|
2018-02-20 16:32:25 +00:00
|
|
|
import pytest
|
|
|
|
from .._align import align
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('string1,string2,cost', [
|
2018-02-20 16:51:49 +00:00
|
|
|
('hello', 'hell', 1),
|
|
|
|
('rat', 'cat', 1),
|
|
|
|
('rat', 'rat', 0),
|
|
|
|
('rat', 'catsie', 4),
|
|
|
|
('t', 'catsie', 5),
|
2018-02-20 16:32:25 +00:00
|
|
|
])
|
|
|
|
def test_align_costs(string1, string2, cost):
|
|
|
|
output_cost, i2j, j2i, matrix = align(string1, string2)
|
|
|
|
assert output_cost == cost
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('string1,string2,i2j', [
|
2018-02-20 16:51:49 +00:00
|
|
|
('hello', 'hell', [0,1,2,3,-1]),
|
|
|
|
('rat', 'cat', [0,1,2]),
|
|
|
|
('rat', 'rat', [0,1,2]),
|
|
|
|
('rat', 'catsie', [0,1,2]),
|
|
|
|
('t', 'catsie', [2]),
|
2018-02-20 16:32:25 +00:00
|
|
|
])
|
|
|
|
def test_align_i2j(string1, string2, i2j):
|
|
|
|
output_cost, output_i2j, j2i, matrix = align(string1, string2)
|
|
|
|
assert list(output_i2j) == i2j
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('string1,string2,j2i', [
|
2018-02-20 16:51:49 +00:00
|
|
|
('hello', 'hell', [0,1,2,3]),
|
|
|
|
('rat', 'cat', [0,1,2]),
|
|
|
|
('rat', 'rat', [0,1,2]),
|
|
|
|
('rat', 'catsie', [0,1,2, -1, -1, -1]),
|
|
|
|
('t', 'catsie', [-1, -1, 0, -1, -1, -1]),
|
2018-02-20 16:32:25 +00:00
|
|
|
])
|
|
|
|
def test_align_i2j(string1, string2, j2i):
|
|
|
|
output_cost, output_i2j, output_j2i, matrix = align(string1, string2)
|
|
|
|
assert list(output_j2i) == j2i
|
2018-02-20 16:51:49 +00:00
|
|
|
|
|
|
|
def test_align_strings():
|
|
|
|
words1 = ['hello', 'this', 'is', 'test!']
|
|
|
|
words2 = ['hellothis', 'is', 'test', '!']
|
|
|
|
cost, i2j, j2i, matrix = align(words1, words2)
|
|
|
|
assert cost == 4
|
|
|
|
assert list(i2j) == [0, -1, 1, 2]
|
|
|
|
assert list(j2i) == [0, 2, 3, -1]
|