def test_input_two_same_words(self): testfile = open("text.txt", 'w') testfile.write("sun sun") testfile.close() expectedresult = dict({ "sun": { "text.txt": [indexer.Position(0, 3), indexer.Position(4, 7)] } }) self.testindexer.index("text.txt") resulteddictionary = dict(shelve.open('database')) self.assertEqual(resulteddictionary, expectedresult)
def test_input_sentence(self): testfile = open("text.txt", 'w') testfile.write("This is a sentence sentence.") testfile.close() expectedresult = dict({ "This": { "text.txt": [indexer.Position(0, 4)] }, "is": { "text.txt": [indexer.Position(5, 7)] }, "a": { "text.txt": [indexer.Position(8, 9)] }, "sentence": { "text.txt": [indexer.Position(10, 18), indexer.Position(19, 27)] } }) self.testindexer.index("text.txt") resulteddictionary = dict(shelve.open('database')) self.assertEqual(resulteddictionary, expectedresult)
def test_equal(self): a = indexer.Position(1, 6) b = indexer.Position(1, 6) self.assertEqual(a, b)
def test_not_equal(self): a = indexer.Position(2, 5) b = indexer.Position(4, 6) self.assertNotEqual(a, b)