Std.Test
View source →Test assertion primitives plus a shrinking-aware property runner.
Assertions raise an Erlang error with a descriptive atom on
failure (:assertion_failed, :not_equal, etc.). The
property-based helpers pair with Std.Gen generators.
Examples
mod MyTest
use Std.Test
fn test_sanity() -> Atom =
assert_eq(1 + 1, 2)
# Property: reversing a list twice is the identity.
use Std.Test
use Std.Gen
use Std.List
let prop = fn(xs: List(Int)) -> Bool =
reverse(reverse(xs)) == xs
forall_default(fn(_) -> list_int(10, 0, 100), prop)
# => :ok
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn assert(condition: Bool) -> Atom
Assert
conditionistrue; raises:assertion_failedon false. -
# fn assert_eq(a: T, b: T) -> Atom
Assert
a == b; raises:not_equalon mismatch. -
# fn assert_gt(a: T, b: T) -> Atom
Assert
a > b; raises:not_greaterotherwise. -
# fn assert_lt(a: T, b: T) -> Atom
Assert
a < b; raises:not_lessotherwise. -
# fn assert_ne(a: T, b: T) -> Atom
Assert
a != b; raises:unexpectedly_equalwhen they match. -
# fn forall(gen: (Atom) -> T, property: (T) -> Bool, runs: Int) -> Atom
Run
propertyagainstrunsrandom samples drawn fromgen. Returns:okwhen every sample satisfies the property, or raises:property_failedon the first counterexample.genis a zero-argument function (e.g.fn(_) -> Std.Gen.int_in(0, 100)) that returns a fresh value on every call. -
# fn forall_default(gen: (Atom) -> T, property: (T) -> Bool) -> Atom
Convenience wrapper that uses 100 runs by default.
-
# fn forall_shrunk(gen: (Atom) -> T, property: (T) -> Bool, runs: Int) -> T extern
Run
propertyagainstrunsrandom samples. On the first failure, shrink the counterexample usingStd.Gen.shrink/1until no smaller value also fails; raise:property_failed_with_shrunkcarrying the minimised value. -
# fn forall_shrunk_default(gen: (Atom) -> T, property: (T) -> Bool) -> T
Same as
forall_shrunk/3but with a 100-run default.