Collection Strategy¶
Controls the size range of generated collections during fixture generation.
Configuration¶
The CollectionStrategy takes a single sizeRange parameter — an IntRange specifying the minimum and maximum number of elements in generated collections.
// Default: 1 to 5 elements
some { collectionStrategy = CollectionStrategy() }
// Small collections: 0 to 2 elements
some { collectionStrategy = CollectionStrategy(0..2) }
// Medium collections: 10 to 20 elements
some { collectionStrategy = CollectionStrategy(10..20) }
// Large collections: 50 to 100 elements
some { collectionStrategy = CollectionStrategy(50..100) }
// Fixed size: always exactly 3 elements
some { collectionStrategy = CollectionStrategy(3..3) }
Default¶
| Property | Default value |
|---|---|
sizeRange |
1..5 |
Affected types¶
The collection strategy applies to all collection and array types generated by Some:
List<T>MutableList<T>Set<T>MutableSet<T>Map<K, V>MutableMap<K, V>Array<T>
Validation¶
The CollectionStrategy constructor enforces two constraints on the sizeRange parameter via require() checks. Both throw IllegalArgumentException on failure.
Start must be non-negative¶
sizeRange.first (the start of the range) must be > -1, meaning it must be 0 or greater.
CollectionStrategy(-1..5) // IllegalArgumentException: sizeRange.start must be positive
CollectionStrategy(0..5) // OK — empty collections are allowed
CollectionStrategy(1..5) // OK
End must be strictly greater than start¶
sizeRange.last (the end of the range) must be strictly greater than sizeRange.first. This means a range with equal bounds (e.g. 3..3) is not valid — there must be at least one possible size.
CollectionStrategy(5..3) // IllegalArgumentException: sizeRange.end must be greater than or equal to sizeRange.start
CollectionStrategy(3..3) // IllegalArgumentException: end is not greater than start
CollectionStrategy(3..4) // OK — produces collections of size 3 or 4
Note that the error message says "greater than or equal to" but the actual check is strict (last > first). Equal bounds are rejected.