summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sets.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-09-21 08:14:11 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-09-21 08:14:11 (GMT)
commit175a6ac114ffc8d5c74769b50897faf3fb99f63a (patch)
tree93baf4c7710e9f99fd25e36fda9bb3505223ef91 /Lib/test/test_sets.py
parent41631e8f668c9c2c724731d207edcc39c6fcf38c (diff)
downloadcpython-175a6ac114ffc8d5c74769b50897faf3fb99f63a.zip
cpython-175a6ac114ffc8d5c74769b50897faf3fb99f63a.tar.gz
cpython-175a6ac114ffc8d5c74769b50897faf3fb99f63a.tar.bz2
Improve and expand identity tests.
Diffstat (limited to 'Lib/test/test_sets.py')
-rw-r--r--Lib/test/test_sets.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/Lib/test/test_sets.py b/Lib/test/test_sets.py
index 416b7ca..1b26d4c 100644
--- a/Lib/test/test_sets.py
+++ b/Lib/test/test_sets.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import unittest, operator, copy, pickle
+import unittest, operator, copy, pickle, random
from sets import Set, ImmutableSet
from test import test_support
@@ -711,18 +711,18 @@ class TestCopyingNested(TestCopying):
class TestIdentities(unittest.TestCase):
def setUp(self):
- self.a = Set('abracadabra')
- self.b = Set('alacazam')
+ self.a = Set([random.randrange(100) for i in xrange(50)])
+ self.b = Set([random.randrange(100) for i in xrange(50)])
def test_binopsVsSubsets(self):
a, b = self.a, self.b
- self.assert_(a - b < a)
- self.assert_(b - a < b)
- self.assert_(a & b < a)
- self.assert_(a & b < b)
- self.assert_(a | b > a)
- self.assert_(a | b > b)
- self.assert_(a ^ b < a | b)
+ self.assert_(a - b <= a)
+ self.assert_(b - a <= b)
+ self.assert_(a & b <= a)
+ self.assert_(a & b <= b)
+ self.assert_(a | b >= a)
+ self.assert_(a | b >= b)
+ self.assert_(a ^ b <= a | b)
def test_commutativity(self):
a, b = self.a, self.b
@@ -744,12 +744,19 @@ class TestIdentities(unittest.TestCase):
self.assertEqual((a-b)|(b-a), a^b)
def test_exclusion(self):
- # check that inverse operations show non-overlap
+ # check that inverse operations do not overlap
a, b, zero = self.a, self.b, Set()
self.assertEqual((a-b)&b, zero)
self.assertEqual((b-a)&a, zero)
self.assertEqual((a&b)&(a^b), zero)
+ def test_cardinality_relations(self):
+ a, b = self.a, self.b
+ self.assertEqual(len(a), len(a-b) + len(a&b))
+ self.assertEqual(len(b), len(b-a) + len(a&b))
+ self.assertEqual(len(a^b), len(a-b) + len(b-a))
+ self.assertEqual(len(a|b), len(a-b) + len(a&b) + len(b-a))
+
#==============================================================================
libreftest = """