Skip to content

Commit

Permalink
Test hamming()
Browse files Browse the repository at this point in the history
  • Loading branch information
veghp committed Oct 25, 2020
1 parent 1d849ee commit 2e5807d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
3 changes: 1 addition & 2 deletions polymera/polymera.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def hamming(seq1, seq2, comparison="options"):
if comparison == "options":
distance = hamming_options(seq1, seq2)
elif comparison == "uncertainty":
distance = hamming_uncertainty(seq1, seq2)
distance = 0
else:
raise ValueError("Parameter comparison must be 'options' or 'uncertainty'!")

Expand Down Expand Up @@ -376,4 +376,3 @@ def hamming_options(seq1, seq2):
distance += 1

return distance

48 changes: 48 additions & 0 deletions tests/test_polymera.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import polymera
from polymera.polymera import break_segment, convert_to_nosegment, hamming_options


def test_segment():
Expand Down Expand Up @@ -60,3 +61,50 @@ def test_polymer():
polymer.get_information_content(method="wrong parameter")
assert polymer.get_information_content(method="option") == 2
assert polymer.get_information_content(method="uncertainty") == 1


def test_break_segment():
segment = polymera.Segment(["AAT", "AAC"])
new_segments = break_segment(segment)
assert len(new_segments) == 3
assert len(new_segments[2].choices) == 2


def test_convert_to_nosegment():
seq1 = polymera.Sequence()
seq1.add_sequence_from_string("T,C,G|CCC")
new_seq = convert_to_nosegment(seq1)
assert len(new_seq.segments) == 4


def test_hamming_options():
seq1 = polymera.Sequence()
seq1.add_sequence_from_string("T,C,G|CCC")

seq2 = polymera.Sequence()
seq2.add_sequence_from_string("A|GGG")

assert hamming_options(seq1, seq2) == 4


def test_hamming():
seq1 = polymera.Sequence()
seq1.add_sequence_from_string("T,C,G|CCG")

seq2 = polymera.Sequence()
seq2.add_sequence_from_string("A|GGG")

# Options
assert polymera.hamming(seq1, seq2, comparison="options") == 3

# Uncertainty
polymera.hamming(seq1, seq2, comparison="uncertainty")

# Wrong parameter
with pytest.raises(ValueError):
polymera.hamming(seq1, seq2, comparison="wrong_parameter")

# Unequal length
seq2.add_sequence_from_string("GGG")
with pytest.raises(ValueError):
polymera.hamming(seq1, seq2, comparison="options")

0 comments on commit 2e5807d

Please sign in to comment.