The Cantor interpreter ships with two complementary layers of tests: Python unit tests that verify the mathematical correctness of the pairing functions in isolation, and end-to-end program tests that run realDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/felipenugo/cantor-interpreter/llms.txt
Use this file to discover all available pages before exploring further.
.cantor files through the CLI and compare their output against expected results. Both layers are wired into make targets so they can be run individually or together.
Python unit tests
The filetests/python/test_cantor_stdlib.py contains unit tests for every function exported by src/cantor_stdlib.py. These tests exercise the pairing math directly in Python, without invoking the ANTLR parser or the interpreter at all. They are the fastest way to confirm that the foundational numeric encoding is sound.
The tests cover:
pi/unpiround-trip — encodes and decodes pairs, including the reference examplepi(47, 32) == 3192.- List encoding / decoding — verifies
pi_from_listandunpi_listacross empty lists, singletons, and multi-element lists. - Input encoding — checks
encode_input_text("1 3 2") == 188and edge cases such as empty input and non-natural input raisingValueError. k_1— asserts the constant-one function returns1for any input.identity— confirmsidentity(v) == vand that the"id"key inBUILTIN_FUNCTIONSmaps to the same function.add— verifiesadd(pi(3, 4)) == 7and similar pairs.mul— checks multiplication via encoded pairs.diff— checks truncated subtractionmax(0, x - y)via encoded pairs.fst/snd— decodes the first and second component of every encoded pair.
Cantor program tests
End-to-end tests live undertests/programs/. Each test is a group of three files that share the same stem:
.cantor— the Cantor source program to execute..inp— whitespace-separated natural numbers that are fed to the program via stdin..out— the single line of expected stdout output.
.cantor file that does not have a matching .inp and .out counterpart is treated as an import-only dependency (e.g., relacionals.cantor) and is silently skipped by the test runner.
The test runner (scripts/run_tests.py) discovers tests by recursively scanning tests/programs/ for .cantor files, then looks for the matching .inp and .out files beside each one. For every matched triple, it invokes the real CLI:
.inp piped to stdin, and compares the captured stdout with the contents of .out.
Running the program tests
make test-programs depends on the all target, so it automatically rebuilds the ANTLR-generated parser files before running the tests. If you run the script directly, make sure make has been run first.Output format
Each test prints one line:OK phase/name (three spaces) if stdout matched the expectation, or FAIL phase/name (one space) followed by the expected and actual values plus any stderr output.
0 when all tests pass and 1 when any test fails.
Test phases
Tests are organized into phase directories that correspond to language feature groups:| Phase | Directory | What is tested |
|---|---|---|
| 1 | phase1-core | Built-ins, comp, pair |
| 2 | phase2-imports | import directive |
| 3 | phase3-extended | compair, extended mode |
| 4 | phase4-minimization | mu operator |
| 5 | phase5-conditionals | Conditional functions |
| 5 | phase5-primrec | Primitive recursion |
Make targets
| Target | What it does |
|---|---|
make test | Runs both test-python and test-programs |
make test-python | Runs only the Python unit tests |
make test-programs | Builds the parser first, then runs the Cantor program tests |
Adding a new test
Create the .cantor source file
Write your Cantor program and save it under the appropriate phase directory, for example
tests/programs/phase1-core/my_test.cantor. Make sure the file begins with a main directive that selects the function to evaluate.Create the .inp input file
Create For a program expecting a pair, write two numbers on the same line:
tests/programs/phase1-core/my_test.inp containing the whitespace-separated natural numbers to feed as stdin. For a program expecting a single input, write just one number:Create the .out expected output file
Create
tests/programs/phase1-core/my_test.out containing the exact output your program should produce. The test runner strips leading and trailing whitespace before comparing, so a single number on one line is sufficient: