Commit 0ddef194 authored by Chris McDonough's avatar Chris McDonough

Added tests for TreeSets.

parent 43a7b3cf
...@@ -91,10 +91,10 @@ except: ...@@ -91,10 +91,10 @@ except:
sys.path.insert(0, '../..') sys.path.insert(0, '../..')
import ZODB import ZODB
from BTrees.OOBTree import OOBTree, OOBucket, OOSet from BTrees.OOBTree import OOBTree, OOBucket, OOSet, OOTreeSet
from BTrees.IOBTree import IOBTree, IOBucket, IOSet from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
class Base: class Base:
...@@ -263,7 +263,7 @@ class MappingBase(Base): ...@@ -263,7 +263,7 @@ class MappingBase(Base):
diff = lsubtract(list(self.t.keys()), []) diff = lsubtract(list(self.t.keys()), [])
assert diff == [], diff assert diff == [], diff
class SetTests(Base): class NormalSetTests(Base):
""" Test common to all set types """ """ Test common to all set types """
def testInsertReturnsValue(self): def testInsertReturnsValue(self):
t = self.t t = self.t
...@@ -342,13 +342,20 @@ class SetTests(Base): ...@@ -342,13 +342,20 @@ class SetTests(Base):
assert t.minKey(3) == 3 assert t.minKey(3) == 3
assert t.minKey(9) == 10 assert t.minKey(9) == 10
class ExtendedSetTests(NormalSetTests):
def testLen(self): def testLen(self):
# should sets know their length?
t = self.t t = self.t
r = xrange(10000) r = xrange(10000)
for x in r: t.insert(x) for x in r: t.insert(x)
assert len(t) == 10000, len(t) assert len(t) == 10000, len(t)
def testGetItem(self):
t = self.t
r = xrange(10000)
for x in r: t.insert(x)
for x in r:
assert t[x] == x
class BucketTests(MappingBase): class BucketTests(MappingBase):
""" Tests common to all buckets """ """ Tests common to all buckets """
pass pass
...@@ -609,22 +616,38 @@ class TestIIBTrees(BTreeTests, TestCase): ...@@ -609,22 +616,38 @@ class TestIIBTrees(BTreeTests, TestCase):
## Set tests ## Set tests
class TestIOSets(SetTests, TestCase): class TestIOSets(ExtendedSetTests, TestCase):
def setUp(self): def setUp(self):
self.t = IOSet() self.t = IOSet()
class TestOOSets(SetTests, TestCase): class TestOOSets(ExtendedSetTests, TestCase):
def setUp(self): def setUp(self):
self.t = OOSet() self.t = OOSet()
class TestIISets(SetTests, TestCase): class TestIISets(ExtendedSetTests, TestCase):
def setUp(self): def setUp(self):
self.t = IISet() self.t = IISet()
class TestOISets(SetTests, TestCase): class TestOISets(ExtendedSetTests, TestCase):
def setUp(self): def setUp(self):
self.t = OISet() self.t = OISet()
class TestIOTreeSets(NormalSetTests, TestCase):
def setUp(self):
self.t = IOTreeSet()
class TestOOTreeSets(NormalSetTests, TestCase):
def setUp(self):
self.t = OOTreeSet()
class TestIITreeSets(NormalSetTests, TestCase):
def setUp(self):
self.t = IITreeSet()
class TestOITreeSets(NormalSetTests, TestCase):
def setUp(self):
self.t = OITreeSet()
## Bucket tests ## Bucket tests
class TestIOBuckets(BucketTests, TestCase): class TestIOBuckets(BucketTests, TestCase):
...@@ -654,12 +677,18 @@ def main(): ...@@ -654,12 +677,18 @@ def main():
TOISet = makeSuite(TestIOSets, 'test') TOISet = makeSuite(TestIOSets, 'test')
TIISet = makeSuite(TestOOSets, 'test') TIISet = makeSuite(TestOOSets, 'test')
TIOTreeSet = makeSuite(TestIOTreeSets, 'test')
TOOTreeSet = makeSuite(TestOOTreeSets, 'test')
TOITreeSet = makeSuite(TestIOTreeSets, 'test')
TIITreeSet = makeSuite(TestOOTreeSets, 'test')
TIOBucket = makeSuite(TestIOBuckets, 'test') TIOBucket = makeSuite(TestIOBuckets, 'test')
TOOBucket = makeSuite(TestOOBuckets, 'test') TOOBucket = makeSuite(TestOOBuckets, 'test')
TOIBucket = makeSuite(TestOIBuckets, 'test') TOIBucket = makeSuite(TestOIBuckets, 'test')
TIIBucket = makeSuite(TestIIBuckets, 'test') TIIBucket = makeSuite(TestIIBuckets, 'test')
alltests = TestSuite((TIOSet, TOOSet, TOISet, TIISet, alltests = TestSuite((TIOSet, TOOSet, TOISet, TIISet,
TIOTreeSet, TOOTreeSet, TOITreeSet, TIITreeSet,
TIOBucket, TOOBucket, TOIBucket, TIIBucket, TIOBucket, TOOBucket, TOIBucket, TIIBucket,
TOOBTree, TIOBTree, TOIBTree, TIIBTree)) TOOBTree, TIOBTree, TOIBTree, TIIBTree))
runner = TextTestRunner() runner = TextTestRunner()
......
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