[Zodb-checkins] CVS: Zope/lib/python/BTrees/tests - testBTrees.py:1.41

Tim Peters tim.one@comcast.net
Thu, 13 Jun 2002 18:33:52 -0400


Update of /cvs-repository/Zope/lib/python/BTrees/tests
In directory cvs.zope.org:/tmp/cvs-serv838/tests

Modified Files:
	testBTrees.py 
Log Message:
BTree_rangeSearch():  Repaired more cases where a should-be empty range
search returned a seemingly random slice of the tree.  A new test on the
painfully constructed highly-degenerate BTree turned up lots of these.
It turns out that BTree_rangeSearch had a much harder job than it
thought it had <0.7 wink>.


=== Zope/lib/python/BTrees/tests/testBTrees.py 1.40 => 1.41 ===
             self.assertEqual(t.has_key(i), 0)
 
+    def _checkRanges(self, tree, keys):
+        self.assertEqual(len(tree), len(keys))
+        self.assertEqual(list(tree.keys()), keys)
+        for k in keys:
+            self.assert_(tree.has_key(k))
+        if keys:
+            lokey = min(keys)
+            hikey = max(keys)
+            self.assertEqual(lokey, tree.minKey())
+            self.assertEqual(hikey, tree.maxKey())
+        else:
+            lokey = hikey = 42
+
+        # 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)
+
+    def testRanges(self):
+        t = self._build_degenerate_tree()
+        self._checkRanges(t, [1, 3, 5, 7, 11])
+
 class TestOITreeSets(NormalSetTests, TestCase):
     def setUp(self):
         self.t = OITreeSet()