summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-12-16 09:54:14 (GMT)
committerGitHub <noreply@github.com>2019-12-16 09:54:14 (GMT)
commit1ca8fb187eb320f87a74b82c2a20acb89f429841 (patch)
tree480d482f6ca769dc8908fb04622c1cb6553808f9 /Lib/test
parent79f02fee1a542c440fd906fd54154c73fc0f8235 (diff)
downloadcpython-1ca8fb187eb320f87a74b82c2a20acb89f429841.zip
cpython-1ca8fb187eb320f87a74b82c2a20acb89f429841.tar.gz
cpython-1ca8fb187eb320f87a74b82c2a20acb89f429841.tar.bz2
Add tests and design notes for Counter subset/superset operations. (GH-17625)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index a2a66a7..92520b0 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -2064,6 +2064,29 @@ class TestCounter(unittest.TestCase):
set_result = setop(set(p.elements()), set(q.elements()))
self.assertEqual(counter_result, dict.fromkeys(set_result, 1))
+ def test_subset_superset_not_implemented(self):
+ # Verify that multiset comparison operations are not implemented.
+
+ # These operations were intentionally omitted because multiset
+ # comparison semantics conflict with existing dict equality semantics.
+
+ # For multisets, we would expect that if p<=q and p>=q are both true,
+ # then p==q. However, dict equality semantics require that p!=q when
+ # one of sets contains an element with a zero count and the other
+ # doesn't.
+
+ p = Counter(a=1, b=0)
+ q = Counter(a=1, c=0)
+ self.assertNotEqual(p, q)
+ with self.assertRaises(TypeError):
+ p < q
+ with self.assertRaises(TypeError):
+ p <= q
+ with self.assertRaises(TypeError):
+ p > q
+ with self.assertRaises(TypeError):
+ p >= q
+
def test_inplace_operations(self):
elements = 'abcd'
for i in range(1000):