[Zope3-checkins] CVS: Zope3/lib/python/Zope/TextIndex/tests - testNBest.py:1.2

Guido van Rossum guido@python.org
Tue, 3 Dec 2002 15:40:30 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/TextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv18951/tests

Modified Files:
	testNBest.py 
Log Message:
During testing of TextIndexWrapper, Christian Zagrodnick noticed a bug
in NBest, which makes repeating a query with a larger N return
inconsistent results when the scores are the same.  I've added a test
for this (testAllSameScore()) and a fix, which is using bisect_left()
instead of bisect_right().


=== Zope3/lib/python/Zope/TextIndex/tests/testNBest.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/TextIndex/tests/testNBest.py:1.1	Tue Dec  3 09:28:16 2002
+++ Zope3/lib/python/Zope/TextIndex/tests/testNBest.py	Tue Dec  3 15:40:29 2002
@@ -82,6 +82,14 @@
                     self.assertEqual(nb.pop_smallest(), expected[-i])
                 self.assertRaises(IndexError, nb.pop_smallest)
 
+    def testAllSameScore(self):
+        inputs = [(i, 0) for i in range(10)]
+        for n in range(1, 12):
+            nb = NBest(n)
+            nb.addmany(inputs)
+            outputs = nb.getbest()
+            self.assertEqual(outputs, inputs[:len(outputs)])
+
 def test_suite():
     return makeSuite(NBestTest)