def test_add_new_doc_one_word(): doc_id = 1 content = 'foo' foo_index = InvertedIndex() foo_index.add_new_document(doc_id, content) assert doc_id in foo_index.inverted_index[content], ( "add a new document with 1 word but couldn't find in built index")
def test_add_new_doc_multi_word(): doc_id = 23 word_1 = ' foo ' word_2 = ' \t bar\t' foo_index = InvertedIndex() foo_index.add_new_document(doc_id, word_1 + word_2) assert_mes = "add a new document with 2 words and different separators but couldn't find a word in built index" assert doc_id in foo_index.inverted_index[word_1.strip()], assert_mes assert doc_id in foo_index.inverted_index[word_2.strip()], assert_mes