///|
test "adding zero is an identity" {
@quickcheck.check((x : Int) => x + 0 == x)
}///|
test "division identity" {
@quickcheck.check((x : Int) => x / x == 1, filter=x => x != 0)
}///|
test "configured property run" {
@quickcheck.check(
(xs : Array[Int]) => xs.length() >= 0,
count=200,
max_size=50,
max_shrinks=100,
discard_ratio=10,
seed=2026,
)
}///|
test "inspect a counterexample" {
let report = @quickcheck.report(
(_ : Int) => false,
count=1,
max_size=0,
max_shrinks=0,
seed=7,
)
debug_inspect(
report,
content=(
#|Falsified(
#| counterexample=0,
#| tests=1,
#| size=0,
#| shrinks=0,
#| shrink_attempts=0,
#|)
),
)
}///|
test "observe generated cases" {
let report = @quickcheck.report(
(_ : Unit) => true,
observe=_ => {
[@quickcheck.label("unit"), @quickcheck.classify(true, "generated")]
},
count=2,
)
debug_inspect(
report,
content=(
#|Passed(
#| tests=2,
#| observations={ labels: { <List: ["unit"]>: 2 }, classes: { "generated": 2 } },
#|)
),
)
}///|
test "basic generation" {
let b : Bool = @quickcheck.gen()
inspect(b, content="true")
let x : Int = @quickcheck.gen()
inspect(x, content="0")
// Generate with size parameter
let sized : Array[Int] = @quickcheck.gen(size=5)
inspect(sized.length() <= 5, content="true")
}///|
test "multiple samples" {
let ints : Array[Int] = @quickcheck.samples(5)
debug_inspect(ints, content="[0, 0, 0, -1, -1]")
let strings : Array[String] = @quickcheck.samples(12)
debug_inspect(
strings[5:10],
content=(
#|<ArrayView: ["(K!", "", "vx2\b", "", "Hp9\u{18}Rx"]>
),
)
}///|
test "builtin types" {
// Basic types
let v : (Bool, Char, Byte) = @quickcheck.gen()
debug_inspect(
v,
content=(
#|(false, '~', 0x4d)
),
)
// Numeric types
let v : (Int, Int64, UInt, UInt64, Float, Double, BigInt) = @quickcheck.gen()
debug_inspect(
v,
content="(0, 0, 0, 0, 0.23986786603927612, 0.7917029935679342, 0)",
)
// Collections
let v : (String, Bytes, Iter[Int]) = @quickcheck.gen()
let (s, b, iter) = v
debug_inspect(
(s, b, iter.to_array()),
content=(
#|("", <Bytes: []>, [])
),
)
}///|
priv struct Point {
x : Int
y : Int
} derive(Debug)
///|
impl Arbitrary for Point with fn arbitrary(size, r0) {
let r1 = r0.split()
let y = @quickcheck.Arbitrary::arbitrary(size, r1)
{ x: @quickcheck.Arbitrary::arbitrary(size, r0), y }
}
///|
test "custom type generation" {
let point : Point = @quickcheck.gen()
debug_inspect(
point,
content=(
#|{ x: 0, y: 0 }
),
)
let points : Array[Point] = @quickcheck.samples(10)
debug_inspect(
points[6:],
content=(
#|<ArrayView:
#| [{ x: 0, y: 1 }, { x: -1, y: -5 }, { x: -6, y: -6 }, { x: -1, y: 7 }]>
),
)
}impl Arbitrary for FixedArray[X]impl Arbitrary for PriorityQueue[X]impl Arbitrary for PriorityQueue[X]fn[A : Arbitrary, B : Arbitrary, C : Arbitrary] arbitrary(size : Int, r0 : RandomState) -> (A, B, C)type Generator[T]impl Show for Observationtype QuickCheckReport[A]impl Debug for QuickCheckReport[A]test "adding zero is an identity" {
@quickcheck.check((x : Int) => x + 0 == x)
}fn[A : Arbitrary + Shrink] report(property : (A) -> Bool raise?, filter? : (A) -> Bool, observe? : (A) -> Array[Observation], count? : UInt, max_size? : UInt, max_shrinks? : UInt, discard_ratio? : UInt, seed? : UInt64) -> QuickCheckReport[A]test "spawn draws from Arbitrary" {
let strings : @quickcheck.Generator[String] = @quickcheck.spawn()
let lengths = strings.samples(count=3, size=4, seed=37).map(s => s.length())
debug_inspect(
lengths,
content=(
#|[3, 2, 1]
),
)
}Install
Installed by default