Browse files

Prepared for release as an egg

darcs-hash:20070426142219-a5408-99ada83f5ad65554dafc7df6aa6656b976f8a30f.gz
  • Loading branch information...
1 parent 446df50 commit 36dc12f2c3276475dcdeb2fdae53b8f0bd3b66d0 @DanielStutzbach committed Apr 26, 2007
Showing with 337 additions and 95 deletions.
  1. +27 −0 LICENSE
  2. +6 −0 MANIFEST.in
  3. +3 −3 Makefile
  4. +106 −0 README.txt
  5. +48 −34 blist.c
  6. +5 −3 prototype/blist.py
  7. +73 −0 setup.py
  8. +69 −55 test_blist.py
View
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright 2007 Stutzbach Enterprises, LLC (daniel@stutzbachenterprises.com)
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
View
6 MANIFEST.in
@@ -0,0 +1,6 @@
+include blist.c
+include setup.py
+include test_blist.py
+include test/*.py
+include README.txt
+include LICENSE
View
6 Makefile
@@ -1,8 +1,8 @@
CFLAGS=-Wall -Winline -g -fno-strict-aliasing -Wstrict-prototypes $(COPT)
CC=gcc-4.1
-COPT=-O3 -DLIMIT=128 # For performance
-#COPT=-pg -O3 -DLIMIT=128 -ftest-coverage -fprofile-arcs # For profiling
+COPT=-O3 -DLIMIT=128 -DNDEBUG=1 # For performance
+#COPT=-pg -O3 -DLIMIT=128 -DNDEBUG=1 -ftest-coverage -fprofile-arcs # For profiling
#COPT=-DPy_DEBUG=1 -DLIMIT=8 # For debug mode
LDFLAGS=-g -shared $(COPT)
@@ -16,4 +16,4 @@ clean:
rm -f *.o *.so
tarball:
- cd .. ; tar -zcvf blist.tar.gz blist/blist.c blist/Makefile blist/test_blist.py blist/test/*.py prototype/blist.py
+ cd .. ; tar -zcvf blist.tar.gz blist/blist.c blist/Makefile blist/test_blist.py blist/test/*.py blist/prototype/blist.py
View
106 README.txt
@@ -0,0 +1,106 @@
+BList: a list-like type with better asymptotic performance
+==========================================================
+
+The BList is a type that looks, acts, and quacks like a Python list(),
+but has better performance for many (but not all) use cases. Below
+are some of the unique features of the BList:
+
+- just as fast as a Python list() when the list is small
+- getslice runs in O(log n) time
+- making a shallow copy runs in O(1) time
+- setslice runs in O(log n + log k) time if the inserted slice is a
+BList of length k
+- multipling a BList by k takes O(log k) time and O(log k) memory
+
+Example:
+
+>>> from blist import *
+>>> x = blist([0])
+>>> x *= 2**29
+>>> x.append(5)
+>>> y = x[4:-234234]
+>>> del x[3:1024]
+
+None of the above operations have a noticeable delay, even though the
+lists have over 500 million elements due to line 3. The BList has two
+key features that allow it to pull this off this performance:
+
+1) Internally, a B+Tree is a wide, squat tree. Each node has a
+maximum of 128 children. If the entire list contains 128 or fewer
+objects, then there is only one node, which simply contains an array
+of the objects. In other words, for short lists, a BList works just
+like Python's array-based list() type. Thus, it has the same good
+performance on small lists.
+
+2) The BList type features transparent copy-on-write. If a non-root
+node needs to be copied (as part of a getslice, copy, setslice, etc.),
+the node is shared between multiple parents instead of being copied.
+If it needs to be modified later, it will be copied at that time.
+This is completely behind-the-scenes; from the user's point of view,
+the BList works just like a regular Python list.
+
+So you can see the performance of the BList in more detail, several
+performance graphs available at the following link:
+ http://stutzbachenterprises.com/blist/
+
+BList addiction
+---------------
+
+If you fall in love with the BList, you can even do this:
+ __builtins__.list = blist
+
+Then, everywhere in your program that calls list() will create a BList
+instead. List comprehensions, [], and built-ins will still return
+ordinary list objects, however.
+
+Installation instruction
+------------------------
+
+Python 2.5 or 2.5.1 is required. If building from the source
+distribution, the Python header files are also required. In either
+case, just run:
+
+ python setup.py install
+
+The BList module will be installed in the 'site-packages' directory of
+your Python installation. (Unless directed elsewhere; see the
+"Installing Python Modules" section of the Python manuals for details
+on customizing installation locations, etc.).
+
+If you downloaded the source distribution and wish to run the
+associated test suite, you can also run:
+
+ python setup.py test
+
+which will verify the correct installation and functioning of the
+package.
+
+Platforms
+---------
+
+The BList was developed under Debian Linux. Since it has no
+dependencies other Python 2.5, we expect it will work on other 32-bit
+gcc platforms without modification. If you run into trouble building
+BList on your platform, please contact us.
+
+Known bugs and limitations
+--------------------------
+
+The .sort() method does not yet properly handle comparisons throwing
+exceptions and may crash.
+
+64-bit architectures are not yet supported.
+
+Objects with __del__ methods that modify the BList that triggered the
+__del__ may cause undefined behavior. While we plan to fix this, we
+also suggest you rethink your code.
+
+Out-of-memory errors are not always handled correctly and may cause
+undefined behavior. While we plan to fix this, we hope that it does
+not arise in practice.
+
+Feedback
+--------
+
+We're eager to hear about your experiences with the BList. Please
+send all feedback and bug reports to daniel@stutzbachenterprises.com.
View
82 blist.c
@@ -1,19 +1,31 @@
-/* Copyright (C) 2007 Stutzbach Enterprises, LLC.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
+/* Copyright 2007 Stutzbach Enterprises, LLC (daniel@stutzbachenterprises.com)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
#include <python2.5/Python.h>
@@ -27,11 +39,7 @@
*
* XXX, .reversed()
*
- * XXX, .sort()
- *
- * This goes into an infinite loop:
- * little_list = BList([0])
- * big_list = little_list * 2**30
+ * Implement TimSort for large lists
*
*/
@@ -235,7 +243,7 @@ static PyObject *blist_repeat(PyBList *self, ssize_t n);
static PyObject *_blist_get1(PyBList *self, ssize_t i);
#define blist_forget_children2(self, i, j) \
vvalidate(self, VALID_RW, _blist_forget_children2(self, i, j))
-static void inline _blist_forget_children2(PyBList *self, int i, int j);
+static void _blist_forget_children2(PyBList *self, int i, int j);
#define blist_forget_children1(self, i) \
(blist_forget_children2((self), (i), (self)->num_children))
#define blist_forget_children(self) \
@@ -483,7 +491,7 @@ static int forest_append(Forest *forest, PyBList *leaf)
parent->num_children = LIMIT;
forest->num_trees -= LIMIT;
int x = blist_underflow(parent, LIMIT - 1);
- assert(!x);
+ assert(!x); (void) x;
forest->list[forest->num_trees++] = parent;
power *= LIMIT;
@@ -505,7 +513,7 @@ static inline void forest_delete(Forest *forest)
}
/* Combine the forest into a final BList */
-static inline PyBList *forest_finish(Forest *forest)
+static PyBList *forest_finish(Forest *forest)
{
PyBList *out_tree = NULL; // The final BList we are building
int out_height = 0; // It's height
@@ -1115,7 +1123,7 @@ static PyBList *_blist_insert_here(PyBList *self, int k, PyObject *item)
self->num_children++;
self->children[k] = item;
int collapse = blist_underflow(self, k);
- assert(!collapse);
+ assert(!collapse); (void) collapse;
return NULL;
}
@@ -1126,13 +1134,13 @@ static PyBList *_blist_insert_here(PyBList *self, int k, PyObject *item)
self->num_children++;
self->children[k] = item;
int collapse = blist_underflow(self, k);
- assert(!collapse);
+ assert(!collapse); (void) collapse;
} else {
shift_right(sibling, k - HALF, 1);
sibling->num_children++;
sibling->children[k - HALF] = item;
int collapse = blist_underflow(sibling, k - HALF);
- assert(!collapse);
+ assert(!collapse); (void) collapse;
blist_adjust_n(sibling);
}
@@ -1744,7 +1752,7 @@ static PyObject *blist_debug(PyBList *self, PyObject *indent)
Py_INCREF(nl_indent);
PyString_ConcatAndDel(&nl_indent, PyString_FromString("\n"));
- result = PyString_FromFormat("BList(leaf=%d, n=%d, r=%d, ",
+ result = PyString_FromFormat("blist(leaf=%d, n=%d, r=%d, ",
self->leaf, self->n,
self->ob_refcnt);
//PyString_Concat(&result, nl_indent);
@@ -1758,7 +1766,7 @@ static PyObject *blist_debug(PyBList *self, PyObject *indent)
PyString_ConcatAndDel(&result, PyString_FromString(")"));
} else {
- result = PyString_FromFormat("BList(leaf=%d, n=%d, r=%d, ",
+ result = PyString_FromFormat("blist(leaf=%d, n=%d, r=%d, ",
self->leaf, self->n,
self->ob_refcnt);
int i;
@@ -2759,6 +2767,7 @@ static int islt(PyObject *x, PyObject *y, const compare_t *compare)
#define INSERTION_THRESH 0
#define BINARY_THRESH 10
+#if 0
/* Compare X to Y via "<". Goto "fail" if the comparison raises an
error. Else "k" is set to true iff X<Y, and an "if (k)" block is
started. It makes more sense in context <wink>. X and Y are PyObject*s.
@@ -2872,6 +2881,7 @@ static int binary_sort(PyObject **array, int n, const compare_t *compare)
return 0;
}
+#endif
static inline int
mini_merge(PyObject **array, int middle, int n, const compare_t *compare)
@@ -3014,6 +3024,7 @@ gallop_sort(PyObject **array, int n, const compare_t *compare)
}
+#if 0
static int
mini_merge_sort(PyObject **array, int n, const compare_t *compare)
{
@@ -3043,6 +3054,7 @@ mini_merge_sort(PyObject **array, int n, const compare_t *compare)
return 0;
}
+#endif
static int
is_default_cmp(PyObject *cmpfunc)
@@ -3342,8 +3354,8 @@ static PySequenceMethods blist_as_sequence = {
};
PyDoc_STRVAR(blist_doc,
-"BList() -> new list\n"
-"BLst(sequence) -> new list initialized from sequence's items");
+"blist() -> new list\n"
+"blist(sequence) -> new list initialized from sequence's items");
static PyMappingMethods blist_as_mapping = {
(lenfunc)blist_length,
@@ -3354,7 +3366,7 @@ static PyMappingMethods blist_as_mapping = {
PyTypeObject PyBList_Type = {
PyObject_HEAD_INIT(NULL)
0,
- "BList",
+ "blist",
sizeof(PyBList),
0,
(destructor)blist_dealloc, /* tp_dealloc */
@@ -3662,6 +3674,7 @@ PyMODINIT_FUNC
initblist(void)
{
PyObject *m;
+ PyObject *limit = PyInt_FromLong(LIMIT);
PyBList_Type.ob_type = &PyType_Type;
PyUserBList_Type.ob_type = &PyType_Type;
@@ -3675,8 +3688,9 @@ initblist(void)
if (PyType_Ready(&PyBList_Type) < 0) return;
if (PyType_Ready(&PyBListIter_Type) < 0) return;
- m = Py_InitModule3("blist", module_methods, "BList");
+ m = Py_InitModule3("blist", module_methods, "blist");
- PyModule_AddObject(m, "BList", (PyObject *) &PyUserBList_Type);
+ PyModule_AddObject(m, "blist", (PyObject *) &PyUserBList_Type);
+ PyModule_AddObject(m, "_limit", limit);
}
View
8 prototype/blist.py
@@ -2,7 +2,7 @@
"""
-Copyright 2006 Daniel Stutzbach (agthorr@barsoom.org)
+Copyright 2007 Stutzbach Enterprises, LLC (daniel@stutzbachenterprises.com)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@@ -1324,13 +1324,13 @@ def debug(self, indent=''):
"Return a string that shows the internal structure of the BList"
indent = indent + ' '
if not self.leaf:
- rv = 'BList(leaf=%s, n=%s, r=%s, %s)' % (
+ rv = 'blist(leaf=%s, n=%s, r=%s, %s)' % (
str(self.leaf), str(self.n), str(self.refcount),
'\n%s' % indent +
('\n%s' % indent).join([x.debug(indent+' ')
for x in self.children]))
else:
- rv = 'BList(leaf=%s, n=%s, r=%s, %s)' % (
+ rv = 'blist(leaf=%s, n=%s, r=%s, %s)' % (
str(self.leaf), str(self.n), str(self.refcount),
str(self.children))
return rv
@@ -2109,6 +2109,8 @@ def main():
little_list = BList([0])
big_list = little_list * 2**512
+
+blist = BList
if __name__ == '__main__':
main()
View
73 setup.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env
+
+from setuptools import setup, Extension
+
+setup(name='blist',
+ version='0.9.2',
+ description='a list-like type with better asymptotic performance',
+ author='Stutzbach Enterprises, LLC',
+ author_email='daniel@stutzbachenterprises.com',
+ url='http://stutzbachenterprises.com/blist/',
+ license = "BSD",
+ keywords = "blist list b+tree btree fast copy-on-write sparse",
+ ext_modules=[Extension('blist', ['blist.c'])],
+ requires = { 'python': '2.5' },
+ provides = ['blist'],
+ test_suite = "test_blist.test_suite",
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: Scientific/Engineering',
+ 'License :: OSI Approved :: BSD License',
+ 'License :: OSI Approved :: MIT License',
+ 'Programming Language :: C',
+ ],
+
+ long_description="""
+BList: a list-like type with better asymptotic performance
+=====
+
+The BList is a type that looks, acts, and quacks like a Python list(),
+but has better performance for many (but not all) use cases. Below
+are some of the unique features of the BList:
+
+- just as fast as a Python list() when the list is small
+- getslice runs in O(log n) time
+- making a shallow copy runs in O(1) time
+- setslice runs in O(log n + log k) time if the inserted slice is a
+BList of length k
+- multipling a BList by k takes O(log k) time and O(log k) memory
+
+Example:
+
+>>> from blist import *
+>>> x = blist([0])
+>>> x *= 2**29
+>>> x.append(5)
+>>> y = x[4:-234234]
+>>> del x[3:1024]
+
+None of the above operations have a noticeable delay, even though the
+lists have over 500 million elements due to line 3. The BList has two
+key features that allow it to pull this off this performance:
+
+1) Internally, a B+Tree is a wide, squat tree. Each node has a
+maximum of 128 children. If the entire list contains 128 or fewer
+objects, then there is only one node, which simply contains an array
+of the objects. In other words, for short lists, a BList works just
+like Python's array-based list() type. Thus, it has the same good
+performance on small lists.
+
+2) The BList type features transparent copy-on-write. If a non-root
+node needs to be copied (as part of a getslice, copy, setslice, etc.),
+the node is shared between multiple parents instead of being copied.
+If it needs to be modified later, it will be copied at that time.
+This is completely behind-the-scenes; from the user's point of view,
+the BList works just like a regular Python list.
+
+So you can see the performance of the BList in more detail, several
+performance graphs available at the following link:
+ http://stutzbachenterprises.com/blist/
+""",
+
+ )
View
124 test_blist.py
@@ -1,66 +1,75 @@
#!/usr/bin/python
"""
-Copyright (C) 2007 Stutzbach Enterprises, LLC.
+Copyright 2007 Stutzbach Enterprises, LLC (daniel@stutzbachenterprises.com)
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
-"""
-Current known failures:
-- .sort() is unimplemented
-"""
-
import sys
import os
import unittest
-from blist import BList
+import blist
#BList = list
from test import test_support, list_tests
-limit = 8
-n = 512
+limit = blist._limit
+n = 512/8 * limit
+blist = blist.blist
class BListTest(list_tests.CommonTest):
- type2test = BList
+ type2test = blist
def test_truth(self):
super(BListTest, self).test_truth()
- self.assert_(not BList())
- self.assert_(BList([42]))
+ self.assert_(not self.type2test())
+ self.assert_(self.type2test([42]))
def test_identity(self):
- self.assert_(BList([]) is not BList([]))
+ self.assert_(self.type2test([]) is not self.type2test([]))
def test_len(self):
super(BListTest, self).test_len()
- self.assertEqual(len(BList()), 0)
- self.assertEqual(len(BList([0])), 1)
- self.assertEqual(len(BList([0, 1, 2])), 3)
+ self.assertEqual(len(self.type2test()), 0)
+ self.assertEqual(len(self.type2test([0])), 1)
+ self.assertEqual(len(self.type2test([0, 1, 2])), 3)
def test_append(self):
- lst = BList()
+ lst = self.type2test()
t = tuple(range(n))
for i in range(n):
lst.append(i)
self.assertEqual(tuple(lst), t[:i+1])
def test_delstuff(self):
- lst = BList(range(n))
+ lst = self.type2test(range(n))
t = tuple(range(n))
x = lst[4:258]
self.assertEqual(tuple(x), tuple(t[4:258]))
@@ -74,52 +83,52 @@ def test_delstuff(self):
self.assertEqual(tuple(lst), tuple(t[0:200] + t[201:]))
def test_del1(self):
- lst2 = BList(range(limit+1))
+ lst2 = self.type2test(range(limit+1))
self.assertEqual(tuple(lst2), tuple(range(limit+1)))
del lst2[1]
del lst2[-1]
self.assertEqual(tuple(lst2), (0,) + tuple(range(2,limit)))
def test_insert_and_del(self):
- lst = BList(range(n))
+ lst = self.type2test(range(n))
t = tuple(range(n))
lst.insert(200, 0)
self.assertEqual(tuple(lst), (t[0:200] + (0,) + t[200:]))
del lst[200:]
self.assertEqual(tuple(lst), tuple(range(200)))
def test_mul3(self):
- lst = BList(range(3))
+ lst = self.type2test(range(3))
self.assertEqual(tuple(lst*3), tuple(range(3)*3))
def test_extendspam(self):
- a = BList('spam')
+ a = self.type2test('spam')
a.extend('eggs')
self.assertEqual(list(a), list('spameggs'))
def test_bigmul1(self):
- x = BList([0])
+ x = self.type2test([0])
for i in range(290) + [1000, 10000, 100000, 1000000, 10000000, 2**29]:
self.assertEqual(len(x*i), i)
def test_badinit(self):
- self.assertRaises(TypeError, BList, 0, 0, 0)
+ self.assertRaises(TypeError, self.type2test, 0, 0, 0)
def test_copyself(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
x[:] = x
def test_nohash(self):
- x = BList()
+ x = self.type2test()
d = {}
self.assertRaises(TypeError, d.__setitem__, x, 5)
def test_collapseboth(self):
- x = BList(range(512))
+ x = self.type2test(range(512))
del x[193:318]
def test_collapseright(self):
- x = BList(range(512))
+ x = self.type2test(range(512))
del x[248:318]
def test_badrepr(self):
@@ -130,27 +139,27 @@ class BadRepr:
def __repr__(self):
raise BadExc
- x = BList([BadRepr()])
+ x = self.type2test([BadRepr()])
self.assertRaises(BadExc, repr, x)
- x = BList(range(n))
+ x = self.type2test(range(n))
x.append(BadRepr())
self.assertRaises(BadExc, repr, x)
def test_slice0(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
x[slice(5,3,1)] = []
self.assertEqual(x, list(range(n)))
- x = BList(range(n))
+ x = self.type2test(range(n))
self.assertRaises(ValueError, x.__setitem__, slice(5,3,1), [5,3,2])
del x[slice(5,3,1)]
self.assertEqual(x, list(range(n)))
def test_badindex(self):
- x = BList()
+ x = self.type2test()
self.assertRaises(TypeError, x.__setitem__, 's', 5)
def test_comparelist(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
y = list(range(n-1))
self.assert_(not (x == y))
self.assert_(x != y)
@@ -168,8 +177,8 @@ def test_comparelist(self):
self.assert_(x != y)
def test_compareblist(self):
- x = BList(range(n))
- y = BList(range(n-1))
+ x = self.type2test(range(n))
+ y = self.type2test(range(n-1))
self.assert_(not (x == y))
self.assert_(x != y)
self.assert_(not (x < y))
@@ -182,35 +191,40 @@ def test_compareblist(self):
self.assert_(x != y)
def test_comparetuple(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
y = tuple(range(n))
self.assert_(x != y)
def test_indexempty(self):
- x = BList(range(10))
+ x = self.type2test(range(10))
self.assertRaises(ValueError, x.index, 'spam')
def test_indexargs(self):
- x = BList(range(10))
+ x = self.type2test(range(10))
self.assertEqual(x.index(5,1,-1), 5)
self.assertRaises(ValueError, x.index, 5, -1, -9)
self.assertRaises(ValueError, x.index, 8, 1, 4)
self.assertRaises(ValueError, x.index, 0, 1, 4)
def test_reversebig(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
x.reverse()
self.assertEqual(x, range(n-1,-1,-1))
def test_badconcat(self):
- x = BList()
+ x = self.type2test()
y = 'foo'
self.assertRaises(TypeError, x.__add__, y)
def test_bad_assign(self):
- x = BList(range(n))
+ x = self.type2test(range(n))
self.assertRaises(TypeError, x.__setitem__, slice(1,10,2), 5)
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(BListTest))
+ return suite
+
def test_main(verbose=None):
test_support.run_unittest(BListTest)

0 comments on commit 36dc12f

Please sign in to comment.