summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_set.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-08-01 21:39:29 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-08-01 21:39:29 (GMT)
commitd794666048510deca0d4987a4c74d0fca85be411 (patch)
tree0d734e3a3e02c57255d24a8458d53fc02da9d677 /Lib/test/test_set.py
parente295676c87d0a27ca4798a1d817ede88cc860586 (diff)
downloadcpython-d794666048510deca0d4987a4c74d0fca85be411.zip
cpython-d794666048510deca0d4987a4c74d0fca85be411.tar.gz
cpython-d794666048510deca0d4987a4c74d0fca85be411.tar.bz2
* Improve code for the empty frozenset singleton:
- Handle both frozenset() and frozenset([]). - Do not use singleton for frozenset subclasses. - Finalize the singleton. - Add test cases. * Factor-out set_update_internal() from set_update(). Simplifies the code for several internal callers. * Factor constant expressions out of loop in set_merge_internal(). * Minor comment touch-ups.
Diffstat (limited to 'Lib/test/test_set.py')
-rw-r--r--Lib/test/test_set.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 46e4000..cfb17b0 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -391,6 +391,15 @@ class TestFrozenSet(TestJointOps):
s.__init__(self.otherword)
self.assertEqual(s, set(self.word))
+ def test_singleton_empty_frozenset(self):
+ f = frozenset()
+ efs = [frozenset(), frozenset([]), frozenset(()), frozenset(''),
+ frozenset(), frozenset([]), frozenset(()), frozenset(''),
+ frozenset(xrange(0)), frozenset(frozenset()),
+ frozenset(f), f]
+ # All of the empty frozensets should have just one id()
+ self.assertEqual(len(set(map(id, efs))), 1)
+
def test_constructor_identity(self):
s = self.thetype(range(3))
t = self.thetype(s)
@@ -456,6 +465,17 @@ class TestFrozenSetSubclass(TestFrozenSet):
t = self.thetype(s)
self.assertEqual(s, t)
+ def test_singleton_empty_frozenset(self):
+ Frozenset = self.thetype
+ f = frozenset()
+ F = Frozenset()
+ efs = [Frozenset(), Frozenset([]), Frozenset(()), Frozenset(''),
+ Frozenset(), Frozenset([]), Frozenset(()), Frozenset(''),
+ Frozenset(xrange(0)), Frozenset(Frozenset()),
+ Frozenset(frozenset()), f, F, Frozenset(f), Frozenset(F)]
+ # All empty frozenset subclass instances should have different ids
+ self.assertEqual(len(set(map(id, efs))), len(efs))
+
# Tests taken from test_sets.py =============================================
empty_set = set()