[Zope3-checkins] CVS: Zope3/src/zodb/btrees/tests - test_btrees.py:1.6

Tim Peters tim.one@comcast.net
Sat, 22 Feb 2003 01:00:19 -0500


Update of /cvs-repository/Zope3/src/zodb/btrees/tests
In directory cvs.zope.org:/tmp/cvs-serv13181/src/zodb/btrees/tests

Modified Files:
	test_btrees.py 
Log Message:
Exclusive range searches work now.

Dilemma:  the DegenerateBTree test class runs expensive tests, and the
very expensive testDeletes() method in particular takes 4x longer now
(because there are 4x as many ways a range search can be specified now).
However, this test class has provoked every non-conflict-resolution BTree
bug I've seen, and also found nasty errors in the new implementation of
exclusive range searches (which turned out to be messy in some end cases
involving trees with multiple buckets having a single item per bucket --
which happens in real life after an unfortunate sequence of deletes).

So I'm loathe to weaken this test, but also loathe to spend so much time
in it too.  Oh, well -- a bug in BTrees is deadly, so better safe than
sorry.


=== Zope3/src/zodb/btrees/tests/test_btrees.py 1.5 => 1.6 ===
--- Zope3/src/zodb/btrees/tests/test_btrees.py:1.5	Fri Feb 21 12:33:02 2003
+++ Zope3/src/zodb/btrees/tests/test_btrees.py	Sat Feb 22 01:00:18 2003
@@ -103,6 +103,42 @@
                 self._closeDB(root)
                 self._delDB()
 
+    def testSimpleExclusiveKeyRange(self):
+        t = self.t.__class__()
+        self.assertEqual(list(t.keys()), [])
+        self.assertEqual(list(t.keys(excludemin=True)), [])
+        self.assertEqual(list(t.keys(excludemax=True)), [])
+        self.assertEqual(list(t.keys(excludemin=True, excludemax=True)), [])
+
+        self._populate(t, 1)
+        self.assertEqual(list(t.keys()), [0])
+        self.assertEqual(list(t.keys(excludemin=True)), [])
+        self.assertEqual(list(t.keys(excludemax=True)), [])
+        self.assertEqual(list(t.keys(excludemin=True, excludemax=True)), [])
+
+        t.clear()
+        self._populate(t, 2)
+        self.assertEqual(list(t.keys()), [0, 1])
+        self.assertEqual(list(t.keys(excludemin=True)), [1])
+        self.assertEqual(list(t.keys(excludemax=True)), [0])
+        self.assertEqual(list(t.keys(excludemin=True, excludemax=True)), [])
+
+        t.clear()
+        self._populate(t, 3)
+        self.assertEqual(list(t.keys()), [0, 1, 2])
+        self.assertEqual(list(t.keys(excludemin=True)), [1, 2])
+        self.assertEqual(list(t.keys(excludemax=True)), [0, 1])
+        self.assertEqual(list(t.keys(excludemin=True, excludemax=True)), [1])
+
+        self.assertEqual(list(t.keys(-1, 3, excludemin=True, excludemax=True)),
+                         [0, 1, 2])
+        self.assertEqual(list(t.keys(0, 3, excludemin=True, excludemax=True)),
+                         [1, 2])
+        self.assertEqual(list(t.keys(-1, 2, excludemin=True, excludemax=True)),
+                         [0, 1])
+        self.assertEqual(list(t.keys(0, 2, excludemin=True, excludemax=True)),
+                         [1])
+
 class MappingBase(Base):
     """ Tests common to mappings (buckets, btrees) """
 
@@ -1158,9 +1194,16 @@
         # Try all range searches.
         for lo in range(lokey - 1, hikey + 2):
             for hi in range(lo - 1, hikey + 2):
-                want = [k for k in keys if lo <= k <= hi]
-                got = list(tree.keys(lo, hi))
-                self.assertEqual(want, got)
+                for skipmin in False, True:
+                    for skipmax in False, True:
+                        wantlo, wanthi = lo, hi
+                        if skipmin:
+                            wantlo += 1
+                        if skipmax:
+                            wanthi -= 1
+                        want = [k for k in keys if wantlo <= k <= wanthi]
+                        got = list(tree.keys(lo, hi, skipmin, skipmax))
+                        self.assertEqual(want, got)
 
     def testRanges(self):
         t, keys = self._build_degenerate_tree()