Doubling the other model's elements only exposes an implementation that
counts occurrences instead of distinct members when the two sets share
at least half of the receiver's elements, which depended on the models
a test happened to pick. A BitSet.isStrictSubset that counted
duplicates passed every model pair. Repeat the other model
`xm.count + 2` times instead, so a shared element always appears more
often than the receiver has members.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every sequence the checker passed reported its exact count, so an
implementation that trusts underestimatedCount went unnoticed: an empty
TreeSet whose isEqualSet returned `other.underestimatedCount == 0`
passed every test. Also check the predicates and isEqualSet against a
single-pass MinimalSequence, whose underestimatedCount is 0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No checker exercised isEqualSet(to:), and no test passed it a sequence
with duplicates, so #749's bug, where BitSet.Counted rejected such
sequences, went unnoticed until it was reported. Add a checkSetAlgebra
overload for SetAPIExtras types that also checks isEqualSet against the
models: given another Self, an Array, an Array with duplicates, and a
Set, which takes the _UniqueCollection path in the types that have one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five predicates were only ever given another Self, so a type whose
Sequence-taking overloads first check for Self never ran their
general path under the checker. Check them against an Array of the
other model, with and without duplicates, as the set operations
already are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
formUnion against union, formIntersection against intersection,
subtract against subtracting, and formSymmetricDifference against
symmetricDifference, in both the Self-taking and Sequence-taking
overloads.
Each runs under withHiddenCopies at both sharing states, because a
mutating operation on a shared value is where copy-on-write bugs
live, and the original is checked afterwards to confirm it was not
mutated through the copy.
This is the highest-value law in the checker. The two implementations
should agree by construction, so a divergence is a real bug rather
than a debatable one — and nothing else here would catch a form*
method that is simply wrong: a formUnion that intersects passes every
law in the preceding commit.
Verified by injecting three defects into a stand-in conformance: a
formUnion that intersects, an isStrictSubset that drops strictness,
and a subtracting that returns a stale count. All three are caught,
and an unmodified control passes. The stale-count case is caught only
because contents and count are asserted separately.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
SetAPIChecker verifies that a set-like type has the right shape: it is
a protocol with no assertions, so conforming makes the compiler check
that the API surface exists. This adds the other half — that the
operations behave as documented.
Constrained on SetAPIChecker rather than SetAlgebra, because
OrderedSet deliberately does not conform to SetAlgebra (only its
UnorderedView does, for documented reasons about order-sensitive
equality). Constraining on the stdlib protocol would exclude the type
that needs this most.
Follows the house pattern of validating the specification before the
implementation. A Set<Element> model is only as sound as Element's
Hashable conformance, so _checkSetAlgebraModels runs _checkHashable
over the model elements and verifies each model survives a round trip
through Array before any instance is judged; it returns false and the
caller stops rather than reporting defects in the wrong artefact. A
broken model and a broken implementation can agree with each other,
which fails quietly in a way a wrong implementation does not.
Per-instance: contents and count against the model, isEmpty against
count independently of it, the empty set's identity and absorption
cases, the reflexive containment predicates, and filter at both
extremes and in between.
Per-pair: the four operations against the model and again through the
Sequence-taking overloads, which are separate entry points and can
diverge from the Self-taking ones; commutativity, both absorption
laws, and symmetricDifference against its definition in terms of the
other three; and the containment predicates against the model and
against each other. A type can implement each predicate plausibly and
still have them disagree.
Contents and count are asserted separately throughout: a type that
maintains a stored count can return the right elements alongside a
stale one.
Call sites for BitSet, OrderedSet and TreeSet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>