]> granicus.if.org Git - python/commitdiff
Issue 15246: Improve test coverage for collections.abc.Set. (Contributed by James...
authorRaymond Hettinger <python@rcn.com>
Mon, 26 May 2014 01:28:39 +0000 (18:28 -0700)
committerRaymond Hettinger <python@rcn.com>
Mon, 26 May 2014 01:28:39 +0000 (18:28 -0700)
Lib/test/test_collections.py
Misc/ACKS

index 7e149808d44b8a5006471b04cee5d8b5102eb23c..a53862a5dc4ab134332f614f5bbf9a0aabc9122c 100644 (file)
@@ -640,6 +640,59 @@ class TestCollectionABCs(ABCTestCase):
         a, b = OneTwoThreeSet(), OneTwoThreeSet()
         self.assertTrue(hash(a) == hash(b))
 
+    def test_isdisjoint_Set(self):
+        class MySet(Set):
+            def __init__(self, itr):
+                self.contents = itr
+            def __contains__(self, x):
+                return x in self.contents
+            def __iter__(self):
+                return iter(self.contents)
+            def __len__(self):
+                return len([x for x in self.contents])
+        s1 = MySet((1, 2, 3))
+        s2 = MySet((4, 5, 6))
+        s3 = MySet((1, 5, 6))
+        self.assertTrue(s1.isdisjoint(s2))
+        self.assertFalse(s1.isdisjoint(s3))
+
+    def test_equality_Set(self):
+        class MySet(Set):
+            def __init__(self, itr):
+                self.contents = itr
+            def __contains__(self, x):
+                return x in self.contents
+            def __iter__(self):
+                return iter(self.contents)
+            def __len__(self):
+                return len([x for x in self.contents])
+        s1 = MySet((1,))
+        s2 = MySet((1, 2))
+        s3 = MySet((3, 4))
+        s4 = MySet((3, 4))
+        self.assertTrue(s2 > s1)
+        self.assertTrue(s1 < s2)
+        self.assertFalse(s2 <= s1)
+        self.assertFalse(s2 <= s3)
+        self.assertFalse(s1 >= s2)
+        self.assertEqual(s3, s4)
+        self.assertNotEqual(s2, s3)
+
+    def test_arithmetic_Set(self):
+        class MySet(Set):
+            def __init__(self, itr):
+                self.contents = itr
+            def __contains__(self, x):
+                return x in self.contents
+            def __iter__(self):
+                return iter(self.contents)
+            def __len__(self):
+                return len([x for x in self.contents])
+        s1 = MySet((1, 2, 3))
+        s2 = MySet((3, 4, 5))
+        s3 = s1 & s2
+        self.assertEqual(s3, MySet((3,)))
+
     def test_MutableSet(self):
         self.assertIsInstance(set(), MutableSet)
         self.assertTrue(issubclass(set, MutableSet))
index 68701c486e076f36e1583a53ce4d522bbc363719..f25da5efe6e18c149465cec961df177227f11e37 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -679,6 +679,7 @@ Jason Killen
 Jan Kim
 Taek Joo Kim
 Sam Kimbrel
+James King
 W. Trevor King
 Paul Kippes
 Steve Kirsch