diff options
Diffstat (limited to 'Lib/test/test_sets.py')
-rw-r--r-- | Lib/test/test_sets.py | 29 |
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 = """ |