-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Damerau-Levenshtein distance algorithm
- Loading branch information
1 parent
2ca529d
commit 6cdb034
Showing
3 changed files
with
175 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
from __future__ import annotations | ||
import unittest | ||
from limestone.editdistance import lowrance_wagner | ||
|
||
class TestLevenshtein(unittest.TestCase): | ||
def test_distance_diff(self): | ||
dist = lowrance_wagner.distance("ACTG", "FHYU") | ||
self.assertEqual(dist, 4.0) | ||
|
||
def test_similarity_diff(self): | ||
sim = lowrance_wagner.similarity("ACTG", "FHYU") | ||
self.assertEqual(sim, 0.0) | ||
|
||
def test_norm_distance_diff(self): | ||
dist = lowrance_wagner.normalized_distance("ACTG", "FHYU") | ||
self.assertEqual(dist, 1.0) | ||
|
||
def test_norm_similarity_diff(self): | ||
sim = lowrance_wagner.normalized_similarity("ACTG", "FHYU") | ||
self.assertEqual(sim, 0.0) | ||
|
||
def test_distance_sim(self): | ||
dist = lowrance_wagner.distance("ACTG", "ACTG") | ||
self.assertEqual(dist, 0.0) | ||
|
||
def test_similarity_sim(self): | ||
sim = lowrance_wagner.similarity("ACTG", "ACTG") | ||
self.assertEqual(sim, 4.0) | ||
|
||
def test_norm_distance_sim(self): | ||
dist = lowrance_wagner.normalized_distance("ACTG", "ACTG") | ||
self.assertEqual(dist, 0.0) | ||
|
||
def test_norm_similarity_sim(self): | ||
sim = lowrance_wagner.normalized_similarity("ACTG", "ACTG") | ||
self.assertEqual(sim, 1.0) | ||
|
||
def test_norm_distance1(self): | ||
dist = lowrance_wagner.normalized_distance("ACTG", "AATG") | ||
self.assertEqual(dist, 0.25) | ||
|
||
def test_norm_distance2(self): | ||
dist = lowrance_wagner.normalized_distance("ACTG", "AAAG") | ||
self.assertEqual(dist, 0.5) | ||
|
||
def test_norm_distance3(self): | ||
dist = lowrance_wagner.normalized_distance("ACTG", "AAAA") | ||
self.assertEqual(dist, 0.75) | ||
|
||
def test_norm_similarity1(self): | ||
dist = lowrance_wagner.normalized_similarity("ACTG", "AATG") | ||
self.assertEqual(dist, 0.75) | ||
|
||
def test_norm_similarity2(self): | ||
dist = lowrance_wagner.normalized_similarity("ACTG", "AAAG") | ||
self.assertEqual(dist, 0.5) | ||
|
||
def test_norm_similarity3(self): | ||
dist = lowrance_wagner.normalized_similarity("ACTG", "AAAA") | ||
self.assertEqual(dist, 0.25) | ||
|
||
def test_align1(self): | ||
alignment = lowrance_wagner.align("BA", "ABA") | ||
self.assertEqual(alignment, "-BA\nABA") | ||
|
||
def test_align2(self): | ||
alignment = lowrance_wagner.align("ACTG", "ATCG") | ||
self.assertEqual(alignment, "ACTG\nACTG") | ||
|
||
def test_align3(self): | ||
alignment = lowrance_wagner.align("ACTGGTAC", "ATCGGATC") | ||
self.assertEqual(alignment, "ACTGGTAC\nACTGGTAC") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |