Это моя функция, которую я сделал ниже.
def cosine_similarity(a,b):
"""
Determins the similarity between two vectors, by computing the cosine of the angle between them
:param Union[ndarray, Iterable, int, float] a: a non zero numeric vector
:param Union[ndarray, Iterable, int, float] b: a non zero numeric vector
:return: ndarray
"""
norm_a = numpy.linalg.norm(a)
norm_b = numpy.linalg.norm(b)
if norm_a ==0 or norm_b ==0:
raise ZeroDivisionError("Can not find the cosine between two vectors with following norms:{} {}".format(norm_a,norm_b))
return numpy.dot(a,b)/(norm_a * norm_b)
Мне нужна помощь в написании тестовых случаев. Я запустил его, но теряюсь, поскольку никогда не писал тестовый пример
class TestCosineSimilarity(TestCase):
def test_cosine_similarity_with_zero(self):