///|
test "adding zero is an identity" {
@quickcheck.check((x : Int32) => x + 0 == x)
}///|
test "division identity" {
@quickcheck.check((x : Int32) => x / x == 1, filter=x => x != 0)
}///|
test "configured property run" {
@quickcheck.check(
(xs : Array[Int32]) => xs.length() >= 0,
count=200,
max_size=50,
max_shrinks=100,
discard_ratio=10,
seed=2026,
)
}///|
test "inspect a counterexample" {
let report = @quickcheck.report(
(_ : Int32) => false,
count=1,
max_size=0,
max_shrinks=0,
seed=7,
)
debug_inspect(
report,
content=(
#|Falsified(
#| counterexample=1164562236,
#| tests=1,
#| size=0,
#| shrinks=0,
#| shrink_attempts=0,
#|)
),
)
}///|
test "context describes the shrunk counterexample" {
let report = @quickcheck.report(
(x : Int32) => x < 3,
counterexample_context=x => "rendered input <\{x}>",
seed=7,
)
debug_inspect(
report,
content=(
#|Falsified(
#| counterexample=3,
#| context="rendered input <3>",
#| tests=1,
#| size=0,
#| shrinks=29,
#| shrink_attempts=31,
#|)
),
)
}///|
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 : Int32 = @quickcheck.gen()
inspect(
x,
content=(
#|-1757125880
),
)
// Generate with size parameter
let sized : Array[Int32] = @quickcheck.gen(size=5)
inspect(sized.length() <= 5, content="true")
}///|
test "multiple samples" {
let ints : Array[Int32] = @quickcheck.samples(5)
debug_inspect(
ints,
content=(
#|[-1757125880, -2, -1, 534197635, -1073741824]
),
)
let strings : Array[String] = @quickcheck.samples(12)
debug_inspect(
strings[5:10],
content=(
#|<ArrayView:
#| ["\u{03}>", "2", "Z^", "96f\u{1c}\u{06}", ".\u{1c}"]>
),
)
}///|
test "builtin types" {
// Basic types
let v : (Bool, Char, Byte) = @quickcheck.gen()
debug_inspect(
v,
content=(
#|(false, 'O', 0xd9)
),
)
// Numeric types
let v : (Int32, Int64, UInt32, UInt64, Float, Double, BigInt) = @quickcheck.gen()
debug_inspect(
v,
content=(
#|(
#| -2,
#| -6688783864181708209,
#| 512,
#| 12085892970581224893,
#| 0.29428136,
#| 0.6038538294571573,
#| -18446744073709551617,
#|)
),
)
// Collections
let v : (String, Bytes, Iter[Int32]) = @quickcheck.gen()
let (s, b, iter) = v
debug_inspect(
(s, b, iter.to_array()),
content=(
#|("", <Bytes: []>, [])
),
)
}///|
priv struct Point {
x : Int32
y : Int32
} derive(Debug)
///|
impl @quickcheck.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, }
}
///|
impl @quickcheck.Shrink for Point with fn shrink(self) {
@quickcheck.Shrink::shrink((self.x, self.y)).map(pair => {
x: pair.0,
y: pair.1,
})
}
///|
test "custom type generation" {
let point : Point = @quickcheck.gen()
debug_inspect(
point,
content=(
#|{ x: -2, y: -841733569 }
),
)
let points : Array[Point] = @quickcheck.samples(10)
debug_inspect(
points[6:],
content=(
#|<ArrayView:
#| [
#| { x: 1153847821, y: -99999999 },
#| { x: 2, y: 1983292812 },
#| { x: 4194303, y: 999999 },
#| { x: 917696847, y: -372937489 },
#| ]>
),
)
}
///|
test "custom type shrinking" {
let point : Point = { x: 2, y: 1, }
debug_inspect(
@quickcheck.Shrink::shrink(point).collect(),
content=(
#|[{ x: 1, y: 1 }, { x: 0, y: 1 }, { x: 2, y: 0 }]
),
)
}impl Arbitrary for FixedArray[X]impl Arbitrary for ReadOnlyArray[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]#callsite(autofill(loc))
fn[A : Arbitrary + Shrink + Debug] check(property : (A) -> Bool raise?, filter? : (A) -> Bool, observe? : (A) -> Array[Observation], counterexample_context? : (A) -> String, count? : UInt, max_size? : UInt, max_shrinks? : UInt, discard_ratio? : UInt, seed? : UInt64, loc~ : SourceLoc) -> Unit raisetest "adding zero is an identity" {
@quickcheck.check((x : Int32) => x + 0 == x)
}fn[A : Arbitrary + Shrink] report(property : (A) -> Bool raise?, filter? : (A) -> Bool, observe? : (A) -> Array[Observation], counterexample_context? : (A) -> String, 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=(
#|[4, 2, 2]
),
)
}Install
Installed by default