Terry J. Reedy <[email protected]> added the comment:
I like using 'multiset', but I think 'assertMultisetEqual', proposed by Martin
Panter in msg266207, is better than assertMultiSetEqual, as it does not imply
the existence of a class 'MultiSet'.
Raymond's comment "distinct but equal values may appear on both sides, so it
isn't really a permutation" turns on the ambiguity of 'same element' in the
assertCoultEqual definition. The doc never says explicitly that it means same
by equality ('==') regardless of class, rather than same by equality within a
class, which one might assume for 'permutation of values', or same by identity
('is'), which would be needed for 'permutation of objects'. I think it should
what same means here.
Gregory Smith msg266208 objects to a name containing 'set' because "this is
most notably an api having nothing to do with sets". However, the short
definition of the assertion, "a and b have the same elements in the same
number, regardless of their order" *is* a definition of multiset equality. The
assertion looks at both collections as multisets.
Unlike R. David Murray msg266153, I see a difference between 'count' and
'counts'. The former can only mean comparing one count for each collection,
the number of items. The latter could mean the same, but could also mean
comparing multiple counts for each collection, as is the case.
RDM goes on to claim that 'count' is correct because the function's doc defines
it in terms of itertools.count. It actually defines it in terms of
collections.Counter, which would suggest, using the same logic,
'assertCounterEqual' or assertCountersEqual. Since Counter implements the
mathematical idea of 'multiset' and "is similar to bags or multisets in other
languages", we get to 'assertMultisetEqual' as the less Python-specific name.
[I am puzzled about a couple of things. The doc says "Equivalent to:
assertEqual(Counter(list(first)), Counter(list(second)))
but works with sequences of unhashable objects as well." That expression *is*
the current implementation.
1. It seems that the 'list' call should be irrelevant.
2. Counter calls fail with iterables of unhashable objects. Why not the
overall expression?]
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue27071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com