[Zope-Checkins] CVS: Zope/lib/python/BTrees/tests - testSetOps.py:1.8

Tim Peters tim.one@comcast.net
Mon, 24 Jun 2002 22:00:55 -0400


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

Modified Files:
	testSetOps.py 
Log Message:
Enabled multiunion() for the IOBTree package too.  There isn't a good
reason for it not being enabled before.


=== Zope/lib/python/BTrees/tests/testSetOps.py 1.7 => 1.8 ===
 from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
 
-from BTrees.IIBTree import multiunion
-
 # XXX TODO Needs more tests.
 # This file was created when multiunion was added.  The other set operations
 # don't appear to be tested anywhere yet.
@@ -195,10 +193,14 @@
     from BTrees.OIBTree import union, intersection, difference
     builders = OISet, OITreeSet, makeBuilder(OIBTree), makeBuilder(OIBucket)
 
-class TestMultiUnion(TestCase):
+# Subclasses must set up (as class variables):
+#     multiunion, union
+#     mkset, mktreeset
+#     mkbucket, mkbtree
+class MultiUnion(TestCase):
 
     def testEmpty(self):
-        self.assertEqual(len(multiunion([])), 0)
+        self.assertEqual(len(self.multiunion([])), 0)
 
     def testOne(self):
         for sequence in [3], range(20), range(-10, 0, 2) + range(1, 10, 2):
@@ -208,22 +210,22 @@
             seqsorted = sequence[:]
             seqsorted.sort()
             for seq in seq1, seq2, seqsorted:
-                for builder in IISet, IITreeSet:
+                for builder in self.mkset, self.mktreeset:
                     input = builder(seq)
-                    output = multiunion([input])
+                    output = self.multiunion([input])
                     self.assertEqual(len(seq), len(output))
                     self.assertEqual(seqsorted, list(output))
 
     def testValuesIgnored(self):
-        for builder in IIBucket, IIBTree:
+        for builder in self.mkbucket, self.mkbtree:
             input = builder([(1, 2), (3, 4), (5, 6)])
-            output = multiunion([input])
+            output = self.multiunion([input])
             self.assertEqual([1, 3, 5], list(output))
 
     def testBigInput(self):
         N = 100000
-        input = IISet(range(N))
-        output = multiunion([input] * 10)
+        input = self.mkset(range(N))
+        output = self.multiunion([input] * 10)
         self.assertEqual(len(output), N)
         self.assertEqual(output.minKey(), 0)
         self.assertEqual(output.maxKey(), N-1)
@@ -233,32 +235,43 @@
         from random import shuffle
         N = 5000
         inputs = []
+        mkset, mktreeset = self.mkset, self.mktreeset
         for i in range(N):
             base = i * 4 - N
-            inputs.append(IISet([base, base+1]))
-            inputs.append(IITreeSet([base+2, base+3]))
+            inputs.append(mkset([base, base+1]))
+            inputs.append(mktreeset([base+2, base+3]))
         shuffle(inputs)
-        output = multiunion(inputs)
+        output = self.multiunion(inputs)
         self.assertEqual(len(output), N*4)
         self.assertEqual(list(output), range(-N, 3*N))
 
     def testFunkyKeyIteration(self):
         # The internal set iteration protocol allows "iterating over" a
         # a single key as if it were a set.
-        from BTrees.IIBTree import union
         N = 100
-        slow = IISet()
+        union, mkset = self.union, self.mkset
+        slow = mkset()
         for i in range(N):
-            slow = union(slow, IISet([i]))
-        fast = multiunion(range(N))  # acts like N distinct singleton sets
+            slow = union(slow, mkset([i]))
+        fast = self.multiunion(range(N))  # acts like N distinct singleton sets
         self.assertEqual(len(slow), N)
         self.assertEqual(len(fast), N)
         self.assertEqual(list(slow.keys()), list(fast.keys()))
         self.assertEqual(list(fast.keys()), range(N))
 
+class TestIIMultiUnion(MultiUnion):
+    from BTrees.IIBTree import multiunion, union
+    from BTrees.IIBTree import IISet as mkset, IITreeSet as mktreeset
+    from BTrees.IIBTree import IIBucket as mkbucket, IIBTree as mkbtree
+
+class TestIOMultiUnion(MultiUnion):
+    from BTrees.IOBTree import multiunion, union
+    from BTrees.IOBTree import IOSet as mkset, IOTreeSet as mktreeset
+    from BTrees.IOBTree import IOBucket as mkbucket, IOBTree as mkbtree
+
 def test_suite():
     s = TestSuite()
-    for klass in (TestMultiUnion,
+    for klass in (TestIIMultiUnion, TestIOMultiUnion,
                   PureII, PureIO, PureOI, PureOO):
         s.addTest(makeSuite(klass))
     return s