Skip to content

Commit

Permalink
Fix: Testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
RakshitKhajuria committed Oct 16, 2023
1 parent 4380bea commit 10b4760
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
19 changes: 8 additions & 11 deletions tests/test_embedding_distance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
import numpy as np
from langtest.metrics import EmbeddingDistance
from langtest.metrics import (
EmbeddingDistance,
) # Replace 'your_module' with the actual module where EmbeddingDistance is defined


class TestEmbeddingDistance(unittest.TestCase):
Expand All @@ -22,8 +24,7 @@ def test_cosine_similarity(self):
This test checks the correctness of the cosine similarity distance metric.
It ensures that the result is a float, within the range [-1, 1], and not None.
"""
ed = EmbeddingDistance()
result = ed["cosine"](self.vector1, self.vector2)
result = EmbeddingDistance._cosine_distance(self.vector1, self.vector2)
self.assertIsInstance(result, float)
self.assertGreaterEqual(result, -1)
self.assertLessEqual(result, 1)
Expand All @@ -36,8 +37,7 @@ def test_euclidean_distance(self):
This test checks the correctness of the Euclidean distance metric.
It ensures that the result is a float, greater than or equal to 0, and not None.
"""
ed = EmbeddingDistance()
result = ed["euclidean"](self.vector1, self.vector2)
result = EmbeddingDistance._euclidean_distance(self.vector1, self.vector2)
self.assertIsInstance(result, float)
self.assertGreaterEqual(result, 0)
self.assertIsNotNone(result)
Expand All @@ -49,8 +49,7 @@ def test_manhattan_distance(self):
This test checks the correctness of the Manhattan distance metric.
It ensures that the result is a float, greater than or equal to 0, and not None.
"""
ed = EmbeddingDistance()
result = ed["manhattan"](self.vector1, self.vector2)
result = EmbeddingDistance._manhattan_distance(self.vector1, self.vector2)
self.assertIsInstance(result, float)
self.assertGreaterEqual(result, 0)
self.assertIsNotNone(result)
Expand All @@ -62,8 +61,7 @@ def test_chebyshev_distance(self):
This test checks the correctness of the Chebyshev distance metric.
It ensures that the result is a float, greater than or equal to 0, and not None.
"""
ed = EmbeddingDistance()
result = ed["chebyshev"](self.vector1, self.vector2)
result = EmbeddingDistance._chebyshev_distance(self.vector1, self.vector2)
self.assertIsInstance(result, float)
self.assertGreaterEqual(result, 0)
self.assertIsNotNone(result)
Expand All @@ -75,8 +73,7 @@ def test_hamming_distance(self):
This test checks the correctness of the Hamming distance metric.
It ensures that the result is a float, greater than or equal to 0, and less than or equal to 1, and not None.
"""
ed = EmbeddingDistance()
result = ed["hamming"](self.vector1, self.vector2)
result = EmbeddingDistance._hamming_distance(self.vector1, self.vector2)
self.assertIsInstance(result, float)
self.assertGreaterEqual(result, 0)
self.assertLessEqual(result, 1)
Expand Down
27 changes: 12 additions & 15 deletions tests/test_string_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@


class TestStringDistance(unittest.TestCase):
def setUp(self):
self.text1 = "hello"
self.text2 = "hola"
@classmethod
def setUpClass(cls):
cls.text1 = "hello"
cls.text2 = "hola"

def assert_normalized_distance(self, distance_name, result):
"""
Expand All @@ -25,8 +26,7 @@ def test_normalized_jaro_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["jaro"](self.text1, self.text2)
result = StringDistance._normalized_jaro_distance(self.text1, self.text2)
self.assert_normalized_distance("jaro", result)

def test_normalized_jaro_winkler_distance(self):
Expand All @@ -35,8 +35,7 @@ def test_normalized_jaro_winkler_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["jaro_winkler"](self.text1, self.text2)
result = StringDistance._normalized_jaro_winkler_distance(self.text1, self.text2)
self.assert_normalized_distance("jaro_winkler", result)

def test_normalized_hamming_distance(self):
Expand All @@ -45,8 +44,7 @@ def test_normalized_hamming_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["hamming"](self.text1, self.text2)
result = StringDistance._normalized_hamming_distance(self.text1, self.text2)
self.assert_normalized_distance("hamming", result)

def test_normalized_levenshtein_distance(self):
Expand All @@ -55,8 +53,7 @@ def test_normalized_levenshtein_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["levenshtein"](self.text1, self.text2)
result = StringDistance._normalized_levenshtein_distance(self.text1, self.text2)
self.assert_normalized_distance("levenshtein", result)

def test_normalized_damerau_levenshtein_distance(self):
Expand All @@ -65,8 +62,9 @@ def test_normalized_damerau_levenshtein_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["damerau_levenshtein"](self.text1, self.text2)
result = StringDistance._normalized_damerau_levenshtein_distance(
self.text1, self.text2
)
self.assert_normalized_distance("damerau_levenshtein", result)

def test_normalized_indel_distance(self):
Expand All @@ -75,6 +73,5 @@ def test_normalized_indel_distance(self):
Ensure that the result is a float, not None, and falls within the range [0, 1].
"""
sd = StringDistance()
result = sd["indel"](self.text1, self.text2)
result = StringDistance._normalized_indel_distance(self.text1, self.text2)
self.assert_normalized_distance("indel", result)

0 comments on commit 10b4760

Please sign in to comment.