def test_cosine_similarity_subset(self): value = rating_utils._cosine_similarity({1, 2}, {1}) self.assertAlmostEqual(1 / math.sqrt(2), value)
def test_cosine_similarity_intersection(self): value = rating_utils._cosine_similarity({1, 2}, {2, 3}) self.assertAlmostEqual(0.5, value)
def test_cosine_similarity_disjoint_sets(self): value = rating_utils._cosine_similarity({1}, {2, 3}) self.assertAlmostEqual(0, value)
def test_cosine_similarity_equal_sets(self): value = rating_utils._cosine_similarity({2, 3}, {2, 3}) self.assertAlmostEqual(1, value)
def test_cosine_similarity_one_empty(self): value = rating_utils._cosine_similarity({1}, set()) self.assertAlmostEqual(0, value)