[Checkins] SVN: zc.blist/trunk/src/zc/blist/ - improved test coverage of the BList API
Thomas Lotze
tl at gocept.com
Wed Mar 11 03:52:40 EDT 2009
Log message for revision 97821:
- improved test coverage of the BList API
- fixed BList.__getitem__
- fixed BList.__delitem__ so del b[-1] works
Changed:
U zc.blist/trunk/src/zc/blist/__init__.py
U zc.blist/trunk/src/zc/blist/regression.txt
-=-
Modified: zc.blist/trunk/src/zc/blist/__init__.py
===================================================================
--- zc.blist/trunk/src/zc/blist/__init__.py 2009-03-11 02:16:33 UTC (rev 97820)
+++ zc.blist/trunk/src/zc/blist/__init__.py 2009-03-11 07:52:40 UTC (rev 97821)
@@ -479,7 +479,7 @@
if isinstance(index, slice):
return self.iterSlice(index) # XXX return view?
if index < 0:
- index += length
+ index += len(self)
if index < 0:
raise IndexError('list index out of range')
elif index > len(self):
@@ -499,9 +499,13 @@
def __delitem__(self, index):
if not isinstance(index, slice):
- if index > len(self):
+ length = len(self)
+ if index >= length or index < -length:
raise IndexError('list assignment index out of range')
- index = slice(index, index+1)
+ if index == -1:
+ index = slice(-1, None)
+ else:
+ index = slice(index, index+1)
elif index.step == 1:
index = slice(index.start, index.stop)
elif index.step is not None:
Modified: zc.blist/trunk/src/zc/blist/regression.txt
===================================================================
--- zc.blist/trunk/src/zc/blist/regression.txt 2009-03-11 02:16:33 UTC (rev 97820)
+++ zc.blist/trunk/src/zc/blist/regression.txt 2009-03-11 07:52:40 UTC (rev 97821)
@@ -94,7 +94,51 @@
>>> comparison.insert(995, 5)
>>> matches(b, comparison)
True
+ >>> 999 in b
+ True
+ >>> 1000 in b
+ False
+ >>> b == zc.blist.BList(range(1000))
+ False
+ >>> b.sort()
+ >>> comparison.sort()
+ >>> matches(b, comparison)
+ True
+ >>> b == range(1000)
+ False
+ >>> b == zc.blist.BList(range(1000))
+ True
+ >>> b != range(1000)
+ True
+ >>> b != zc.blist.BList(range(1000))
+ False
+ >>> b.remove(999)
+ >>> comparison.remove(999)
+ >>> matches(b, comparison)
+ True
+ >>> b.count(999)
+ 0
+ >>> b.append(999)
+ >>> b.count(999)
+ 1
+ >>> b.append(999)
+ >>> b.count(999)
+ 2
+Regression tests for accessing the last list item, which would fail in 1.0b1:
+
+ >>> len(b)
+ 1001
+
+ >>> b[-1] = 1000
+ >>> b[-1]
+ 1000
+ >>> del b[-1]
+ >>> b[-1]
+ 999
+ >>> len(b)
+ 1000
+
These are some more stress and regression tests.
>>> del b[900:]
More information about the Checkins
mailing list