Open and answer this issue on GitHub.
tests, decision, solver · opened 2026-11-07 · updated 2026-11-22 · 0 comments
A test with parameters says something about every value of its parameters, not about one example:
fn square(x: i32) -> i64 { return (x as i64) * (x as i64) }
test "a square is not negative" (x: i32) {
assert(square(x) >= 0)
}
Other languages run such a test as a property test: a generator draws random values (QuickCheck, Hypothesis, Rust’s proptest), maybe tries some edge cases first, and the test passes if no drawn value fails. That is a sample. For i32 it may try a thousand of four billion values, and for two parameters the space is practically endless. A pass says “nothing found”, not “it holds”.
Nikaia already has a prover that shows an assert holds for every value of a function’s parameters (ADR-269, ADR-270, ADR-361). The question is whether a test with parameters should first go to that prover, and only be sampled where the prover cannot decide. Then the whole combinatorics is covered by a proof instead of being tried.
The owner asked in a session of #1053 (2026-11-07) whether tests could be “proved”, in the sense that all possibilities were covered: a generator that in other languages must try the whole combinatorics, settled in Nikaia by a mathematical proof. Nothing is blocked on the answer today. It decides what Part III §14.3 means before anyone builds it.
docs/specification/30-nikaia-tooling.md) describes test "name" (u: User) { … }: the test runner generates random inputs, with an impl Generator (arbitrary(), edge_cases()) for a type whose values need a shape. No ADR stands behind this section; ADR-269 D1 only knows test "name" { … } without parameters.assert. The options below would add to or change D11 for that case.forall. None is needed here: a parameter the prover knows nothing about already stands for every value, as with a function’s parameters today.On nikaia 0.1.0 of 2026-11-07 a test with parameters does not parse:
$ nikaia check p.nika # p.nika = the example above, plus fn main
error: Expected `{` here, but found `(`.
--> p.nika:3:31
3 | test "square is not negative" (x: i32) {
| ^
No generator, no fuzzer, no Generator trait exists in std. So nothing built has to be changed. Only the specification text would.
| Tool | What a parameterized test is | Covers all values? |
|---|---|---|
| QuickCheck, Hypothesis, proptest | random generation, shrinking of a failing case | no, a sample |
| SmallCheck (Haskell) | all values up to a size, exhaustively | only up to the bound |
| Dafny, F* lemmas, Lean theorems | a lemma with parameters, proved for all | yes, but a failed proof is an error, not a fallback |
| Liquid Haskell, SPARK | contracts proved; tests stay separate | yes, for contracts |
| Kani (Rust), CBMC | kani::any() inputs, bounded model checking |
yes, within loop bounds |
Kani is the closest: a test-like harness whose inputs are symbolic, so a pass covers all of them. No mainstream language falls back from proof to sampling inside the same test. That combination would be Nikaia’s own.
A. Do nothing: §14.3 as written, sampling only.
B. Prove first, sample only what stays unknown. nikaia test hands a test with parameters to the prover like a function body, with its parameters free:
nikaia.proofs like any other (ADR-270 D19), so --locked re-checks it without searching.age = -1 at once, found by the model rather than by chance.unknown (loops without an invariant found, strings, budget spent): the runner samples as §14.3 describes, and the report says the test was sampled, not proved.
arbitrary() written with random_range(0, 100) is code, not a domain. See the sub-question below.C. Prove only; a test with parameters that is not proved fails.
D. Sample only, then prove what the samples suggest (properties mined from runs, then proved as contracts of the function under test).
assert at the top of the test, read as the test’s precondition, the way ADR-269 D5 reads one in a function: test "t" (age: i32) { assert(age >= 0 && age < 150) … }. Values outside are not inputs; the generator in the unknown case draws from inside. No new syntax.User whose rule says age >= 0 brings it with it.Generator::arbitrary() stays for the sampling fallback only, and is not read by the prover.Recommended: 1 and 2 for the prover, 3 for the fallback.
B, with domains as 1 and 2 above. It keeps §14.3’s sampling as the fallback, so no test becomes worse than in other languages. Where the prover succeeds, it turns “tried many values” into “holds for all values”. That is the point of having a prover in the language. It needs no new syntax and no forall in the logic.
What it needs, once decided:
ready issue with a To build list.Risk, honestly: the prover’s reach is integers, indexes and lengths today. For tests over strings or nested structures, most results will be “unknown → sampled” for a long time. Option B is then no worse than A, but the gain shows only where the prover is strong. A second risk: a refuted test whose counterexample does not fail when run means a prover fault, and it must be reported as one, never silently passed.
Found while #1053. Related: #640 (ADR-361, invariants from outside programs and test runs).
Generated by Claude Code