def test_document_len(self): bag1 = BagOfWords("cat dog cow fish cat cat fish") bag2 = BagOfWords("dog grape banana peach") self.assertEqual(bag1.document_len(), 7) self.assertEqual(bag2.document_len(), 4) self.assertEqual(bag1.intersection(bag2).document_len(), 1) self.assertEqual(bag1.union(bag2).document_len(), 11)
def test_union(self): bag1 = BagOfWords("cat dog cow fish cat cat fish") bag2 = BagOfWords("dog grape banana peach") self.assertDictEqual( bag1.union(bag2).values, { "banana": 1, "cat": 3, "cow": 1, "dog": 2, "fish": 2, "grape": 1, "peach": 1 })