Commit 6d37f216 authored by Tim Peters's avatar Tim Peters

Added an exhaustive test of deletions in the degenerate BTree. This is

disabled for now, because it dies in lots of ways.  I hope, but don't know,
that they're all related to "Guido's bug".

Also backported the "Guido's bug" test case from the Zope3 project.  This
is also disabled for now.
parent a2dc6f0b
...@@ -953,12 +953,12 @@ class TestIITreeSets(NormalSetTests, TestCase): ...@@ -953,12 +953,12 @@ class TestIITreeSets(NormalSetTests, TestCase):
# One more. # One more.
t = ts() t = ts()
t.__setstate__(((tree13, 4, tree5711), bucket1)) t.__setstate__(((tree13, 4, tree5711), bucket1))
return t return t, [1, 3, 5, 7, 11]
def testDegenerateBasicOps(self): def testDegenerateBasicOps(self):
t = self._build_degenerate_tree() t, keys = self._build_degenerate_tree()
self.assertEqual(len(t), 5) self.assertEqual(len(t), len(keys))
self.assertEqual(list(t.keys()), [1, 3, 5, 7, 11]) self.assertEqual(list(t.keys()), keys)
# has_key actually returns the depth of a bucket. # has_key actually returns the depth of a bucket.
self.assertEqual(t.has_key(1), 4) self.assertEqual(t.has_key(1), 4)
self.assertEqual(t.has_key(3), 4) self.assertEqual(t.has_key(3), 4)
...@@ -970,12 +970,14 @@ class TestIITreeSets(NormalSetTests, TestCase): ...@@ -970,12 +970,14 @@ class TestIITreeSets(NormalSetTests, TestCase):
def _checkRanges(self, tree, keys): def _checkRanges(self, tree, keys):
self.assertEqual(len(tree), len(keys)) self.assertEqual(len(tree), len(keys))
self.assertEqual(list(tree.keys()), keys) sorted_keys = keys[:]
sorted_keys.sort()
self.assertEqual(list(tree.keys()), sorted_keys)
for k in keys: for k in keys:
self.assert_(tree.has_key(k)) self.assert_(tree.has_key(k))
if keys: if keys:
lokey = min(keys) lokey = sorted_keys[0]
hikey = max(keys) hikey = sorted_keys[-1]
self.assertEqual(lokey, tree.minKey()) self.assertEqual(lokey, tree.minKey())
self.assertEqual(hikey, tree.maxKey()) self.assertEqual(hikey, tree.maxKey())
else: else:
...@@ -989,8 +991,36 @@ class TestIITreeSets(NormalSetTests, TestCase): ...@@ -989,8 +991,36 @@ class TestIITreeSets(NormalSetTests, TestCase):
self.assertEqual(want, got) self.assertEqual(want, got)
def testRanges(self): def testRanges(self):
t = self._build_degenerate_tree() t, keys = self._build_degenerate_tree()
self._checkRanges(t, [1, 3, 5, 7, 11]) self._checkRanges(t, keys)
def XXXtestDeletes(self):
# Delete keys in all possible orders, checking each tree along
# the way.
# XXX This is hopeless for now: it dies with:
# XXX 1. A variety of assertion failures in _checkRanges.
# XXX 2. Assorted "Invalid firstbucket pointer" failures at
# XXX seemingly random times, coming out of the BTree destructor.
# XXX 3. Under Python 2.3 CVS, some baffling
# XXX RuntimeWarning: tp_compare didn't return -1 or -2 for exception
# XXX warnings, possibly due to memory corruption after a BTree
# XXX goes insane.
# XXX These are probably related to "Guido's bug" (which test case
# SXX is also disabled for now).
t, keys = self._build_degenerate_tree()
for oneperm in permutations(keys):
t, keys = self._build_degenerate_tree()
for key in oneperm:
t.remove(key)
keys.remove(key)
self._checkRanges(t, keys)
# A damaged tree may trigger an "invalid firstbucket pointer"
# failure at the time its destructor is invoked. Try to force
# that to happen now, so it doesn't look like a baffling failure
# at some unrelated line.
del t # trigger destructor
class TestOITreeSets(NormalSetTests, TestCase): class TestOITreeSets(NormalSetTests, TestCase):
def setUp(self): def setUp(self):
...@@ -1075,10 +1105,23 @@ def lsubtract(l1, l2): ...@@ -1075,10 +1105,23 @@ def lsubtract(l1, l2):
def realseq(itemsob): def realseq(itemsob):
return map(lambda x: x, itemsob) return map(lambda x: x, itemsob)
def permutations(x):
# Return a list of all permutations of list x.
n = len(x)
if n <= 1:
return [x]
result = []
x0 = x[0]
for i in range(n):
# Build the (n-1)! permutations with x[i] in the first position.
xcopy = x[:]
first, xcopy[i] = xcopy[i], x0
result.extend([[first] + p for p in permutations(xcopy[1:])])
return result
def main(): def main():
TextTestRunner().run(test_suite()) TextTestRunner().run(test_suite())
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment