Testing

Testing — a small unit-testing vocabulary for Aeon. In Aeon a *test* is just a `Bool`-returning function marked with `@property`: the `--test` runner evaluates it and a `True` result is a pass. A function with arguments is a *property* (inputs are generated automatically from the argument types); a function with no arguments is a *unit test* (one concrete case). This library provides readable assertion combinators — every one returns `Bool` — so unit tests and property-based tests share the same vocabulary and the same runner. open Testing open Image # Unit test: one concrete case. `@property(1)` evaluates it exactly once. @property(1) def test_mk_dimensions : Bool = img = Image.mk 4 3 (Color.mk 255 0 0); assertEqual (Image.width img) 4; # Property: dimensions are generated; the assertion must hold for all of them. @property def prop_mk_width (w : {v:Int | v > 0 && v < 64}) : Bool = assertEqual (Image.width (Image.mk w 8 (Color.mk 0 0 0))) w; Run with: aeon --test yourfile.ae Notes ----- * Assertions are plain `Bool` values, so you compose them with the built-in `&&` / `||` / `!`, or with the `allOf*` helpers below to group several checks into one test. * Because an assertion is just a `Bool`, the same helpers work inside the `@example(...)` decorator (machine-checked documentation) as well. ── Boolean assertions ─────────────────────────────────────────────────── Passes when the condition holds. Use it to wrap any boolean expression that this library has no dedicated assertion for (e.g. `assertThat (mem x s)`). Assertion parameters use multiplicity ``n`` (polymorphic identity scaling) so observing a value computed from a linear resource — e.g. ``assertEqual (sum arr) 14`` — does not artificially scale ``arr`` to ``ω``.
Imports
open Math;
Table of Contents

Functions

assertThat

Passes when the condition holds. Use it to wrap any boolean expression that this library has no dedicated assertion for (e.g. `assertThat (mem x s)`). Assertion parameters use multiplicity ``n`` (polymorphic identity scaling) so observing a value computed from a linear resource — e.g. ``assertEqual (sum arr) 14`` — does not artificially scale ``arr`` to ``ω``.
def assertThat (n condition : Bool) : Bool

assertTrue

Passes when the condition holds (alias of `assertThat`, reads well on a raw
def assertTrue (n condition : Bool) : Bool

assertFalse

Passes when the condition is false.
def assertFalse (n condition : Bool) : Bool

assertEqual

Passes when `actual` equals `expected`.
def assertEqual (n actual : a) (n expected : a) : Bool

assertNotEqual

Passes when `actual` differs from `expected`.
def assertNotEqual (n actual : a) (n expected : a) : Bool

assertLess

Passes when `actual < bound`.
def assertLess (n actual : a) (n bound : a) : Bool

assertLessEqual

Passes when `actual <= bound`.
def assertLessEqual (n actual : a) (n bound : a) : Bool

assertGreater

Passes when `actual > bound`.
def assertGreater (n actual : a) (n bound : a) : Bool

assertGreaterEqual

Passes when `actual >= bound`.
def assertGreaterEqual (n actual : a) (n bound : a) : Bool

assertClose

Passes when `actual` and `expected` are within `eps` of each other. Use this instead of `assertEqual` for any value produced by floating-point arithmetic.
def assertClose (n actual : Float) (n expected : Float) (n eps : Float | eps ≥ 0.0) : Bool

both

Passes when both checks pass.
def both (n a : Bool) (n b : Bool) : Bool

allOf3

Passes when all three checks pass.
def allOf3 (n a : Bool) (n b : Bool) (n c : Bool) : Bool

allOf4

Passes when all four checks pass.
def allOf4 (n a : Bool) (n b : Bool) (n c : Bool) (n d : Bool) : Bool

allOf5

Passes when all five checks pass.
def allOf5 (n a : Bool) (n b : Bool) (n c : Bool) (n d : Bool) (n e : Bool) : Bool