[Zope-CVS] CVS: Products/ZCTextIndex/tests - testIndex.py:1.8

Tim Peters tim.one@comcast.net
Fri, 17 May 2002 01:36:09 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv686/tests

Modified Files:
	testIndex.py 
Log Message:
Refactor/combine _docweight/_doclen.


=== Products/ZCTextIndex/tests/testIndex.py 1.7 => 1.8 ===
 from Products.ZCTextIndex.OkapiIndex import OkapiIndex
 
-# The cosine and Okapi indices have the same public interfaces, but these
-# tests access internal attributes, and those aren't identical.
-# The IndexTest class is abstract, and subclasses must implement the
-# check_docid_known and num_docs_known methods.  CosineIndexTest (later in
-# this file) does those in terms of ._docweight, while OkapiIndexTest
-# (later in this file) does them in terms of ._doclen.
+# Subclasses must set a class variable IndexFactory to the appropriate
+# index object constructor.
 
 class IndexTest(TestCase):
 
-    # Subclasses must implement these methods, and set a class variable
-    # IndexFactory to the appropriate index object constructor.
-
-    def check_docid_known(self, DOCID):
-        raise NotImplementedError
-
-    def num_docs_known(self):
-        raise NotImplementedError
-
-
     def setUp(self):
         self.lexicon = Lexicon(Splitter())
         self.index = self.IndexFactory(self.lexicon)
@@ -44,8 +30,8 @@
     def test_index_document(self, DOCID=1):
         doc = "simple document contains five words"
         self.index.index_doc(DOCID, doc)
-        self.check_docid_known(DOCID)
-        self.assertEqual(self.num_docs_known(), 1)
+        self.assert_(self.index._docweight[DOCID])
+        self.assertEqual(len(self.index._docweight), 1)
         self.assertEqual(len(self.index._wordinfo), 5)
         self.assertEqual(len(self.index._docwords), 1)
         self.assertEqual(len(self.index.get_words(DOCID)), 5)
@@ -57,7 +43,7 @@
         DOCID = 1
         self.test_index_document(DOCID)
         self.index.unindex_doc(DOCID)
-        self.assertEqual(self.num_docs_known(), 0)
+        self.assertEqual(len(self.index._docweight), 0)
         self.assertEqual(len(self.index._wordinfo), 0)
         self.assertEqual(len(self.index._docwords), 0)
 
@@ -66,8 +52,8 @@
         doc = "another document just four"
         DOCID = 2
         self.index.index_doc(DOCID, doc)
-        self.check_docid_known(DOCID)
-        self.assertEqual(self.num_docs_known(), 2)
+        self.assert_(self.index._docweight[DOCID])
+        self.assertEqual(len(self.index._docweight), 2)
         self.assertEqual(len(self.index._wordinfo), 8)
         self.assertEqual(len(self.index._docwords), 2)
         self.assertEqual(len(self.index.get_words(DOCID)), 4)
@@ -87,8 +73,8 @@
         self.test_index_two_documents()
         self.index.unindex_doc(1)
         DOCID = 2
-        self.assertEqual(self.num_docs_known(), 1)
-        self.check_docid_known(DOCID)
+        self.assertEqual(len(self.index._docweight), 1)
+        self.assert_(self.index._docweight[DOCID])
         self.assertEqual(len(self.index._wordinfo), 4)
         self.assertEqual(len(self.index._docwords), 1)
         self.assertEqual(len(self.index.get_words(DOCID)), 4)
@@ -99,7 +85,7 @@
     def test_index_duplicated_words(self, DOCID=1):
         doc = "very simple repeat repeat repeat document test"
         self.index.index_doc(DOCID, doc)
-        self.check_docid_known(DOCID)
+        self.assert_(self.index._docweight[DOCID])
         self.assertEqual(len(self.index._wordinfo), 5)
         self.assertEqual(len(self.index._docwords), 1)
         self.assertEqual(len(self.index.get_words(DOCID)), 7)
@@ -144,22 +130,8 @@
 class CosineIndexTest(IndexTest):
     IndexFactory = CosineIndex
 
-    def check_docid_known(self, docid):
-        self.assert_(self.index._docweight.has_key(docid))
-        self.assert_(self.index._docweight[docid] > 0)
-
-    def num_docs_known(self):
-        return len(self.index._docweight)
-
 class OkapiIndexTest(IndexTest):
     IndexFactory = OkapiIndex
-
-    def check_docid_known(self, docid):
-        self.assert_(self.index._doclen.has_key(docid))
-        self.assert_(self.index._doclen[docid] > 0)
-
-    def num_docs_known(self):
-        return len(self.index._doclen)
 
 def test_suite():
     return TestSuite((makeSuite(CosineIndexTest),