README

moonbitlang/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 Bytes
impl Shrink for Array[X]
impl Shrink for Iter[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]

#
shrink_distinct_array

fn[X : Shrink + Eq] shrink_distinct_array(xs : Array[X]) -> Iter[Array[X]]

Shrink distinct array, requires all elements of the Array[X] to be distinct.

#
shrink_non_empty_array

fn[X : Shrink] shrink_non_empty_array(xs : Array[X]) -> Iter[Array[X]]

Shrink non-empty array without producing the empty array.

test {
assert_true(shrink_non_empty_array([1, 2, 3]).all(ys => ys.length() > 0))
}

#
shrink_non_empty_list

fn[T : Shrink] shrink_non_empty_list(xs :
List
[T]) -> Iter[
List
[T]]

Shrink non-empty list without producing the empty list.

test {
let xs : @list.List[Int] = @list.from_array([5])
// Default list shrink would produce [], which is filtered out here.
assert_true(shrink_non_empty_list(xs).all(ys => !ys.is_empty()))
}

#
shrink_sorted_array

fn[T : Shrink + Compare + Eq] shrink_sorted_array(xs : Array[T], lo~ : T, hi~ : T) -> Iter[Array[T]]

Shrink sorted array, requires the Array[T] to be sorted.

#
shrink_sorted_distinct_array

fn[T : Shrink + Compare + Eq] shrink_sorted_distinct_array(xs : Array[T], lo~ : T, hi~ : T) -> Iter[Array[T]]

Shrink sorted distinct array, requires the Array[T] to be sorted and distinct.

#
shrink_sorted_list

fn[T : Shrink + Compare + Eq] shrink_sorted_list(xs :
List
[T], lo~ : T, hi~ : T) -> Iter[
List
[T]]

Shrink sorted list, requires the List[T] to be sorted.

Source Files