[Zope-CVS] CVS: Products/ZCTextIndex/tests - test_index.py:1.1.2.3

Fred L. Drake, Jr. fdrake@acm.org
Tue, 30 Apr 2002 16:47:45 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	test_index.py 
Log Message:
Add tests that involve multiple documents.
Add a test that makes sure documents with repeated words properly.


=== Products/ZCTextIndex/tests/test_index.py 1.1.2.2 => 1.1.2.3 ===
 # 
 ##############################################################################
-"""
-
-Revision information:
-$Id$
-"""
 
 from unittest import TestCase, TestSuite, main, makeSuite
 
@@ -74,6 +69,57 @@
         self.assertEqual(len(self.index._docweight), 0)
         self.assertEqual(len(self.index._wordinfo), 0)
         self.assertEqual(len(self.index._docwords), 0)
+
+    def test_index_two_documents(self):
+        self.test_index_document()
+        doc = MethodIndexable('not the same document')
+        DOCID = 2
+        self.index.index_object(DOCID, doc)
+        self.assert_(self.index._docweight[DOCID])
+        self.assertEqual(len(self.index._wordinfo), 8)
+        self.assertEqual(len(self.index._docwords), 2)
+        self.assertEqual(len(self.index._docwords[DOCID]), 4)
+        document_wid = self.lexicon._words["document"]
+        for wid, (docfreq, map) in self.index._wordinfo.items():
+            if wid == document_wid:
+                self.assertEqual(docfreq, 2)
+                self.assertEqual(len(map), 2)
+                self.assert_(map.has_key(1))
+                self.assert_(map.has_key(DOCID))
+            else:
+                self.assertEqual(docfreq, 1)
+                self.assertEqual(len(map), 1)
+
+    def test_index_two_unindex_one(self):
+        # index two documents, unindex one, and test the results
+        self.test_index_two_documents()
+        self.index.unindex_object(1)
+        DOCID = 2
+        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._docwords[DOCID]), 4)
+        for docfreq, map in self.index._wordinfo.values():
+            self.assertEqual(docfreq, 1)
+            self.assertEqual(len(map), 1)
+            self.assert_(map.has_key(DOCID))
+
+    def test_index_duplicated_words(self, DOCID=1):
+        doc = Indexable("this is a repititive repititive repititive document")
+        self.index.index_object(DOCID, doc)
+        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._docwords[DOCID]), 5)
+        repititive_wid = self.lexicon._words["repititive"]
+        for wid, (docfreq, map) in self.index._wordinfo.items():
+            if wid == repititive_wid:
+                self.assertEqual(docfreq, 1)
+            else:
+                self.assertEqual(docfreq, 1)
+            self.assertEqual(len(map), 1)
+            self.assert_(map.has_key(DOCID))
 
 
 def test_suite():