Skip to content

Commit

Permalink
Implement show_maximum_overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Dec 24, 2024
1 parent 2b77b1a commit a063ac6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
56 changes: 55 additions & 1 deletion micall/tests/test_find_maximum_overlap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from micall.utils.find_maximum_overlap import find_maximum_overlap
from micall.utils.find_maximum_overlap import find_maximum_overlap, show_maximum_overlap


@pytest.mark.parametrize(
Expand All @@ -25,3 +25,57 @@ def test_maximum_overlap_cases(left, right, expected):
else:
with pytest.raises(expected):
find_maximum_overlap(left, right)


@pytest.mark.parametrize(
"left, right, expected",
[
('tttttxxxxx', 'uuuuuxxx', '''\
tttttxxxxx
uuuuuxxx--
'''),
('tttttxxx', 'uuuuuxxxxx', '''\
--tttttxxx
uuuuuxxxxx
'''),
('xxxttttt', 'xxxxxuuuuu', '''\
--xxxttttt
xxxxxuuuuu
'''),
('xxxxxttttt', 'xxxuuuuu', '''\
xxxxxttttt
xxxuuuuu--
'''),
('xxxxttttt', 'uuuuuxxx', '''\
-----xxxxttttt
uuuuuxxx------
'''),
('aaaaxxxxttttt', 'uxxxk', '''\
aaaaxxxxttttt
---uxxxk-----
'''
),
('tttttxxxx', 'xxxuuuuu', '''\
tttttxxxx-----
------xxxuuuuu
'''),
('tttttxxxx', 'xxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu', '''\
tttttxxxx-------------------------------
------xxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
'''),
('tttttxxxxpppppppppppppppppppp', 'xxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu', '''\
tttttxxxxpppppppppppppppppppp-----------
------xxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
'''),
],
)
def test_print(left, right, expected):
shift = find_maximum_overlap(left, right)
ret = show_maximum_overlap(left, right, shift)
if ret != expected:
print()
print()
print(ret)
print()
print()
assert ret == expected
14 changes: 14 additions & 0 deletions micall/utils/find_maximum_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ def find_maximum_overlap(arr1: Sequence[object],

shift_value = max_offset - len(total)
return int(shift_value)


def show_maximum_overlap(arr1: Sequence[object],
arr2: Sequence[object],
shift: int,
) -> str:

arr1_line = '-' * (abs(shift) - len(arr1)) + ''.join(map(str, arr1))
arr2_line = '-' * (len(arr1) - abs(shift)) + ''.join(map(str, arr2))
max_len = max(len(arr1_line), len(arr2_line))
lines = (x.ljust(max_len, '-')
for x in [arr1_line, arr2_line])

return '\n'.join(chain(lines, ['']))

0 comments on commit a063ac6

Please sign in to comment.