consistency tutorial

The goal of this page is to show maintainers how to run the cross-package consistency tests and how to add a new law when a change touches more than one numeric package.

I want toUse
run the whole suitethe quick start command
run one test--filter
add a law that spans packagesa white-box test
decide whether a test belongs herethe placement rule

Quick start

There is nothing to install or import: the package is part of the repository’s test suite. Run it from the repository root (the wrapper keeps the build directory clean):

sh tools/run_moon_clean_exec.sh test -p Luna-Flow/floating-tools/consistency --target native

A passing run ends with passed: N, failed: 0. The suite is also part of just pr, which runs every native test of the module.

Everyday tasks

Run one test

sh tools/run_moon_clean_exec.sh test -p Luna-Flow/floating-tools/consistency \
  --filter "decimal quantize*"

Add a cross-package law

Write a white-box test in core_wbtest.mbt (arithmetic laws) or api_audit_wbtest.mbt (observable API behaviour). State the law against an exact oracle whenever possible:

///|
test "binary addition of small dyadics is exact" {
  let a = @binary.Binary::from_int(3)
  let b = @binary.Binary::from_int(5)
  let sum = @semantic.SemanticScalar::from_binary(a + b)
  let exact = @semantic.SemanticScalar::from_binary(
    @binary.Binary::from_int(8),
  )
  assert_true(sum == exact)
}

Use official decTest rows as fixed witnesses when you test GDA cohort or flag rules, and quote the row id in the test name.

Decide where a test belongs

A law about one package goes into that package’s own tests. A test belongs here when it needs two or more packages, or internal helpers from outside their package, or an oracle such as semantic exact rationals.

Going further

  • The conformance corpora (verification) check each core against external references; this suite checks the cores against each other and against exact arithmetic.
  • internal tutorial shows the helpers several tests exercise.

Common pitfalls

  • Run from a workspace. The package imports sibling Luna-Flow modules; use the repository wrapper or a workspace that resolves them.
  • Keep tests deterministic. Use fixed seeds and explicit contexts; no test may depend on timing or the target’s Double formatting.

Next steps