def setUp(self): super(TestIIIndex, self).setUp() self._idx = IIIndex()
def setUp(self): self._idx = IIIndex()
class TestIIIndex(IndicoTestCase): def setUp(self): super(TestIIIndex, self).setUp() self._idx = IIIndex() def testIndexOperation(self): """ Check that index_doc works """ self._idx.index_doc(1, 2000) self._idx.index_doc(2, 3000) self._idx.index_doc(3, 1500) self.assertEqual(self._idx.wordCount(), 3) self.assertEqual(self._idx.documentCount(), 3) def testUnindexOperation(self): """ Check that unindex_doc works """ self.testIndexOperation() self._idx.unindex_doc(3) self.assertEqual(self._idx.wordCount(), 2) self.assertEqual(self._idx.documentCount(), 2) self._idx.unindex_doc(2) self._idx.unindex_doc(1) self.assertEqual(self._idx.wordCount(), 0) self.assertEqual(self._idx.documentCount(), 0) def testIndexCollisionOperation(self): """ Check that index_doc works when there are key collisions """ self.testIndexOperation() self._idx.index_doc(4, 1500) self._idx.index_doc(5, 1500) self.assertEqual(self._idx.wordCount(), 3) self.assertEqual(self._idx.documentCount(), 5) def testQueryOperation(self): """ Check that queries over the index work """ self.testIndexCollisionOperation() self.assertEqual(list(self._idx.apply((1500, 3000))), [1, 2, 3, 4, 5]) self.assertEqual(list(self._idx.apply((1500, 1500))), [3, 4, 5]) self.assertEqual(list(self._idx.apply((4000, 5000))), []) def testFaultyUnindex(self): """ Unindex of non-existing value """ # the operation won't fail (silently ignored), but # the document count won't change either self._idx.unindex_doc(1) self.assertEqual(self._idx.documentCount(), 0) self._idx.index_doc(1, 4000) self._idx.unindex_doc(3) self.assertEqual(self._idx.documentCount(), 1)