[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_identity.py:1.8

Casey Duncan casey at zope.com
Wed Feb 18 00:08:12 EST 2004


Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv30834/tests

Modified Files:
	test_identity.py 
Log Message:
Implement multiUnion and multiIntersection functions for identity sets


=== Packages/pypes/pypes/tests/test_identity.py 1.7 => 1.8 ===
--- Packages/pypes/pypes/tests/test_identity.py:1.7	Tue Feb 10 22:57:45 2004
+++ Packages/pypes/pypes/tests/test_identity.py	Wed Feb 18 00:08:10 2004
@@ -23,6 +23,7 @@
 from persistent import Persistent
 from BTrees.OOBTree import OOTreeSet, difference
 from types import TypeType
+from sets import Set
 from common \
     import PypesTestCase, TestClass, PersistenceTest, PypesPersistentTest
 
@@ -469,7 +470,7 @@
         union = set1.union(set2)
         self.failIf(union is set1)
         self.failIf(union is set2)
-        self.failUnless(len(union), 20)
+        self.assertEqual(len(union), 20)
         for o in all:
             self.failUnless(o in union)
 
@@ -485,7 +486,7 @@
         union = set1 | set2
         self.failIf(union is set1)
         self.failIf(union is set2)
-        self.failUnless(len(union), len(expected))
+        self.assertEqual(len(union), len(expected))
         for o in expected:
             self.failUnless(o in union)   
             
@@ -500,7 +501,7 @@
         diff = set1.difference(set2)
         self.failIf(diff is set1)
         self.failIf(diff is set2)
-        self.failUnless(len(diff), len(expected))
+        self.assertEqual(len(diff), len(expected))
         for o in expected:
             self.failUnless(o in diff)
     
@@ -515,7 +516,7 @@
         diff = set1 - set2
         self.failIf(diff is set1)
         self.failIf(diff is set2)
-        self.failUnless(len(diff), len(expected))
+        self.assertEqual(len(diff), len(expected))
         for o in expected:
             self.failUnless(o in diff)
             
@@ -594,6 +595,80 @@
         self.failUnless(set1.issuperset(set2))
         self.failUnless(set2.issuperset(set1))
         self.assertEqual(set1, set2)
+
+
+class TestMultiSetOps(PypesTestCase):
+    
+    def testMultiUnionDisjoint(self):
+        from pypes.identity import IdentitySet, multiUnion
+        sets = [IdentitySet([self._newObj() for i in range(10)])
+                for i in range(10)]
+        union = multiUnion(sets)
+        self.assertEqual(len(union), 100)
+        union2 = IdentitySet()
+        for set in sets:
+            union2 = union2.union(set)
+        self.assertEqual(union, union2)
+    
+    def testMultiUnionOverlapping(self):
+        from pypes.identity import IdentitySet, multiUnion
+        objs = [self._newObj() for i in range(100)]
+        sets = []
+        expected = Set()
+        for i in range(5):
+            members = objs[0:-1:i+1]
+            sets.append(IdentitySet(members))
+            expected.update(members)
+        union = multiUnion(sets)
+        self.assertEqual(len(union), len(expected))
+        self.assertEqual(union, IdentitySet(expected))
+    
+    def testMultiUnionEmpty(self):
+        from pypes.identity import IdentitySet, multiUnion
+        self.assertEqual(multiUnion(()), IdentitySet())
+        
+    def testMultiUnionSingle(self):
+        from pypes.identity import IdentitySet, multiUnion
+        set = IdentitySet([self._newObj() for i in range(10)])
+        union = multiUnion([set])
+        self.failIf(union is set)
+        self.assertEqual(union, set)
+    
+    def testMultiIntersectionOverlapping(self):
+        from pypes.identity import IdentitySet, multiIntersection
+        sets = [IdentitySet([self._newObj() for i in range(10)])
+                for i in range(10)]
+        overlap = [list(set)[5] for set in sets]
+        for set in sets:
+            set.update(overlap)
+        sect = multiIntersection(sets)
+        self.assertEqual(sect, IdentitySet(overlap))
+    
+    def testMultiIntersectionDisjoint(self):
+        from pypes.identity import IdentitySet, multiIntersection
+        sets = [IdentitySet([self._newObj() for i in range(10)])
+                for i in range(10)]
+        self.assertEqual(multiIntersection(sets), IdentitySet())
+    
+    def testMultiIntersectionOneSetEmpty(self):
+        # Exercise empty input set optimization
+        from pypes.identity import IdentitySet, multiIntersection
+        sets = [IdentitySet([self._newObj() for i in range(10)])
+                for i in range(10)]
+        sets.insert(5, IdentitySet())
+        self.assertEqual(multiIntersection(sets), IdentitySet())
+    
+    def testMultiIntersectionEmpty(self):
+        from pypes.identity import IdentitySet, multiIntersection
+        self.assertEqual(multiIntersection(()), IdentitySet())
+        
+    def testMultiIntersectionSingle(self):
+        from pypes.identity import IdentitySet, multiIntersection
+        set = IdentitySet([self._newObj() for i in range(10)])
+        sect = multiIntersection([set])
+        self.failIf(sect is set)
+        self.assertEqual(sect, set)    
+        
 
 class TestIdentitySetPersistence(PypesPersistentTest):
     




More information about the Zope-CVS mailing list