Problem
CollectionState<T>.Validate compares the requested distinct collection size with the cardinality advertised by the main item generator. The requested size includes values added through Containing(...) and ContainingAny(...), even when those values extend the effective domain beyond what the main generator can produce.
A valid collection is therefore rejected eagerly:
var values = Any.SetOf(Any.Int32().OneOf(1, 2))
.Containing(3)
.WithCount(3);
The set { 1, 2, 3 } is satisfiable, but validation treats the request as three distinct values required from a generator whose cardinality is two.
The same underestimation affects the cardinality cap used when resolving an unconstrained or ranged collection count.
Impact
Valid distinct lists, sets and dictionaries can fail with ConflictingAnyConstraintException. The result also depends unexpectedly on whether required values happen to belong to the main generator's domain.
Direction
Model the effective distinct domain more carefully:
- fixed contained values known to be outside the main generator's domain may increase the available cardinality;
- fixed contained values already inside that domain must not increase it;
- generated contained values or opaque generators whose overlap cannot be proven should make the eager cardinality calculation conservative rather than cause a false conflict;
- when satisfiability cannot be established statically, defer to the existing bounded generation-time exhaustion check.
The correction must apply consistently to ListOf(...).Distinct(), SetOf(...) and dictionary keys.
Acceptance criteria
- The example above generates a three-element set containing
1, 2 and 3.
- A contained value already present in the item domain does not incorrectly increase cardinality.
- Genuinely impossible requests still fail eagerly when they can be proven impossible.
- Unknown overlap never causes an eager false positive; bounded generation remains the fallback.
- Tests cover fixed contained values,
ContainingAny(...), custom comparers and order-independent constraint declaration.
Context
Surfaced during a focused review of the standalone Dummies library.
Problem
CollectionState<T>.Validatecompares the requested distinct collection size with the cardinality advertised by the main item generator. The requested size includes values added throughContaining(...)andContainingAny(...), even when those values extend the effective domain beyond what the main generator can produce.A valid collection is therefore rejected eagerly:
The set
{ 1, 2, 3 }is satisfiable, but validation treats the request as three distinct values required from a generator whose cardinality is two.The same underestimation affects the cardinality cap used when resolving an unconstrained or ranged collection count.
Impact
Valid distinct lists, sets and dictionaries can fail with
ConflictingAnyConstraintException. The result also depends unexpectedly on whether required values happen to belong to the main generator's domain.Direction
Model the effective distinct domain more carefully:
The correction must apply consistently to
ListOf(...).Distinct(),SetOf(...)and dictionary keys.Acceptance criteria
1,2and3.ContainingAny(...), custom comparers and order-independent constraint declaration.Context
Surfaced during a focused review of the standalone
Dummieslibrary.