Skip to main content

Testing

Quantus has two kinds of tests:

  1. cargo test: 518 tests that run in a few seconds. Run them before every commit.
  2. The generated test set in test/: 103,000 cases run by a separate program, for broad coverage of the engine. A full run takes about 4 minutes, so run it when you change the engine's behaviour, not on every commit.

The frontend (desktop/src/) has no tests of its own; npm run typecheck is its only check. The renderer's calls into the engine are covered by the Tauri IPC tests below.

Running​

cargo test --workspace # everything below, about 10 s plus build time
cargo test -p quantus-core # only the engine
cargo test -p quantus-desktop # only the Tauri commands
cargo test -p quantus-core --test golden # one integration test file
cargo test -p quantus-core binomial # every test whose name contains "binomial"
cargo test -p quantus-core --test golden -- --nocapture # show println! output

cd desktop && npm run typecheck # TypeScript of the renderer

The number crates are built with opt-level = 3 even in debug builds (see the root Cargo.toml); without that, the integral cases run several times slower.

No single test should take longer than a second. Today tests/golden.rs breaks that rule (about 5 s, see plans.md); everything else finishes in under 0.2 s per file.

Unit tests (270)​

#[cfg(test)] mod tests blocks inside the source files. They test one module at a time and live next to the code they test, so the file you change is also where its tests are.

WhereTestsWhat
crates/quantus-core/src/analysis/80Analysis mode: expression tree, conversion from and to LaTeX, evaluation, simplifier, exact radicals and trig values, derivatives with working, intervals, polynomial division, equation solving, domains, limits and asymptotes, antiderivatives, input, tangent, area and value table, plot sampling, the time budget
crates/quantus-core/src/electro/36Circuit solver, wire resistance, reverse solving, material table
crates/quantus-core/src/num.rs15Exact numbers, rounding, powers, π and roots
crates/quantus-core/src/quantity.rs11PhysicalQuantity: arithmetic, conversion, dimension errors
crates/quantus-core/src/api.rs13The JSON shape the app receives (CalculationResponse, AnalysisResponse and the analysis tasks)
crates/quantus-core/src/eval/21Calculator steps and their detail levels, evaluator, substitution, numeric root scan
crates/quantus-core/src/latex/28Lexer, number formats, serializer, exact forms (\frac{\sqrt{2}}{2}, \frac{\pi}{2})
crates/quantus-core/src/units/17Dimensions, unit lookup, conversions
crates/quantus-core/src/ (rest)29Sessions, settings, error messages, message language, algebra pipeline, rational roots, steps merged and filtered by detail level
desktop/src-tauri/src/tests.rs20The Tauri commands through Tauri's own IPC layer with a mock runtime, as the renderer's invoke reaches them: evaluation, variables, error positions, settings and circuit files, the menu, the analysis commands at a set precision and with their errors

Integration tests (248)​

crates/quantus-core/tests/*.rs. Each file is its own test binary and uses only the public API of quantus-core.

Golden tests: parity with the old Kotlin engine​

The engine was ported from Kotlin. Before the Kotlin code was removed, its tests and the behaviour of the libraries it used (Symja, Indriya) were dumped to JSON in crates/quantus-core/tests/golden/. These files replay those dumps, so the Rust engine is checked against what the old program did.

FileDataWhat
golden.rsevaluate.json, sessions.json254 stateless calculations (result, LaTeX, unit, value, warnings, errors) and session scenarios with variables
latex_golden.rsroundtrip.json, parse_errors.jsonLaTeX parse/serialise round trips, and parse errors with their position
quantity_golden.rsquantity_cases.json81 PhysicalQuantity operations
units_oracle.rsunits_symbols.json, units_format.jsonEvery one- to three-character unit symbol (188,499 candidates) against Indriya: known or not, dimension, factor, offset, printed form; and 79 formatted units
electro.rselectro.jsonThe circuit calculator's JSON interface: request in, the fields of the response that must match

To add a case, add a line to the JSON file; the runner picks it up. golden.rs, latex_golden.rs and quantity_golden.rs check every case and fail once at the end, listing each failing case with how long it took (tests/common/mod.rs).

Algebra​

The symbolic simplification of rational expressions, built milestone by milestone:

FileTestsWhat
algebra_milestone1.rs10Polynomials: monomial order, arithmetic, division with remainder, content, GCD and LCM
algebra_milestone2.rs11Finding the denominators of an expression, for domain restrictions
algebra_milestone3.rs14Binomial formulas, exact roots, factoring
algebra_milestone4.rs22Nested fractions, common denominators, expansion
algebra_milestone5.rs53The full simplification pipeline, checking that input and output are equivalent, that step texts name what the step changes, and the working each detail level shows (design/step-detail.md), chaining at every level
algebra_milestone6.rs4Wiring into parser, serializer, calculator and API
algebra_reference_integration.rs5One reference expression, 3 / ((x + 3)/(x - 2)) + ((x - 102)/(x - 4))/(x + 3), end to end
algebra_simplification.rs39The 14 categories of simplification the engine has to handle
algebra_binomial_direction.rs8When results are written as a binomial and when they are expanded

Other​

FileTestsWhat
analysis.rs43The analysis mode end to end: each section's result and the marked points for every case of design/analysis-mode.md §17, each expected antiderivative differentiated back, periodic families, constant functions, boundary points, German texts, the pq formula, input forms and errors, every solution having its step, no steps without a change, a time check, and the working each detail level adds
complex.rs10Complex results in imaginary mode
settings.rs12Each user setting switches its reading or writing rule; the calculator's working by detail level

The generated test set (103,000 cases)​

test/ holds a large set of generated cases across arithmetic, functions, equations, derivatives, integrals, limits, algebra, physics with units, complex numbers and syntax errors. Every expected value is computed by the Python generator, independently of the engine.

cargo run --release -p quantus-core --example run_cases # all cases, ~4 min
cargo run --release -p quantus-core --example run_cases -- --filter physics --fail-only
python3 test/generator/generate.py --check # regenerate test/cases

The runner writes test/results/summary.md and test/results/failures.jsonl. Commit both after a full run, so the repository records the last result. Case format, pass criteria, runner options and the latest numbers are in test/README.md.

test/algebra-simplification-cases.md is a table of 2,500 hand-checked algebra cases. It is not run directly; it defines the conventions the generator's algebra cases follow.

Before committing​

cargo test --workspace && (cd desktop && npm run typecheck)