README

moonbitlang/core/quickcheck/shrink does not have a README file

#
Shrink

pub(open) trait Shrink {
fn shrink(Self) -> Iter[Self] = _
}

Types that can enumerate "smaller" variants of a given value for the classical QuickCheck shrinker. Each call to shrink(x) returns an Iter[Self] of candidates strictly simpler than x; the driver walks these candidates after a failure, keeping the first one that still falsifies the property.

The return type is Iter[Self] rather than Array[Self] so large or recursive shrink spaces stay lazy. The default body (= _) means "no shrinks" — a conservative starting point for types where shrinking isn't meaningful.

test {
// `Int` has a built-in Shrink instance that walks toward 0.
let candidates : Array[Int] = Shrink::shrink(100).collect()
assert_true(candidates.contains(0))
assert_true(candidates.length() > 0)
// `Bool` shrinks `true` to `false`, and `false` has no shrinks.
@debug.assert_eq(Shrink::shrink(true).collect(), [false])
@debug.assert_eq(Shrink::shrink(false).collect(), [])
}
impl Shrink for Unit
impl Shrink for Bool
impl Shrink for Byte
impl Shrink for Char
impl Shrink for Int
impl Shrink for Int64
impl Shrink for UInt
impl Shrink for UInt64
impl Shrink for Float
impl Shrink for Double
impl Shrink for String
impl Shrink for Option[T]
impl Shrink for Result[T, E]
impl Shrink for FixedArray[X]
impl Shrink for Bytes
impl Shrink for Array[X]
impl Shrink for ArrayView[X]
impl Shrink for Tuple2[A, B]
impl Shrink for Tuple3[A, B, C]
impl Shrink for Tuple4[A, B, C, D]
impl Shrink for Tuple5[A, B, C, D, E]
impl Shrink for Tuple6[A, B, C, D, E, F]
impl Shrink for Tuple7[A, B, C, D, E, F, G]
impl Shrink for Tuple8[A, B, C, D, E, F, G, H]
impl Shrink for Tuple9[A, B, C, D, E, F, G, H, I]