Files
rose-ash/lib/apl/tests/pipeline.sx
giles aaabe370d6
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m29s
apl: bracket indexing A[I] → (I⌷A) (+7 tests, 415/415)
Parser: maybe-bracket helper wraps any value followed by [expr]
into (:dyad (:fn-glyph ⌷) idx val).  Wired into :name and :lparen
branches of collect-segments-loop.

apl-run "(10 20 30)[2]" → 20
apl-run "A ← 100 200 300 ⋄ A[2]" → 200
apl-run "(⍳5)[3] × 7" → 21

Multi-axis A[I;J] deferred — needs semicolon-split parsing.
2026-05-07 14:07:05 +00:00

181 lines
4.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
; End-to-end pipeline tests: source string → tokenize → parse → eval-ast → array.
; Verifies the full stack as a single function call (apl-run).
(define mkrv (fn (arr) (get arr :ravel)))
(define mksh (fn (arr) (get arr :shape)))
; ---------- scalars ----------
(apl-test "apl-run \"42\" → scalar 42" (mkrv (apl-run "42")) (list 42))
(apl-test "apl-run \"¯7\" → scalar -7" (mkrv (apl-run "¯7")) (list -7))
; ---------- strands ----------
(apl-test
"apl-run \"1 2 3\" → vector"
(mkrv (apl-run "1 2 3"))
(list 1 2 3))
(apl-test "apl-run \"1 2 3\" shape" (mksh (apl-run "1 2 3")) (list 3))
; ---------- dyadic arithmetic ----------
(apl-test "apl-run \"2 + 3\" → 5" (mkrv (apl-run "2 + 3")) (list 5))
(apl-run "2 × 3 + 4") ; right-to-left
(apl-test
"apl-run \"2 × 3 + 4\" → 14 (right-to-left)"
(mkrv (apl-run "2 × 3 + 4"))
(list 14))
(apl-test
"apl-run \"1 2 3 + 4 5 6\" → 5 7 9"
(mkrv (apl-run "1 2 3 + 4 5 6"))
(list 5 7 9))
(apl-test
"apl-run \"3 × 1 2 3 4\" → scalar broadcast"
(mkrv (apl-run "3 × 1 2 3 4"))
(list 3 6 9 12))
; ---------- monadic primitives ----------
(apl-test
"apl-run \"5\" → 1..5"
(mkrv (apl-run "5"))
(list 1 2 3 4 5))
(apl-test
"apl-run \"-3\" → -3 (monadic negate)"
(mkrv (apl-run "-3"))
(list -3))
(apl-test
"apl-run \"⌈/ 1 3 9 5 7\" → 9 (max-reduce)"
(mkrv (apl-run "⌈/ 1 3 9 5 7"))
(list 9))
(apl-test
"apl-run \"⌊/ 4 7 2 9 1 3\" → 1 (min-reduce)"
(mkrv (apl-run "⌊/ 4 7 2 9 1 3"))
(list 1))
; ---------- operators ----------
(apl-test "apl-run \"+/5\" → 15" (mkrv (apl-run "+/5")) (list 15))
(apl-test "apl-run \"×/5\" → 120" (mkrv (apl-run "×/5")) (list 120))
(apl-test
"apl-run \"⌈/3 1 4 1 5 9 2\" → 9"
(mkrv (apl-run "⌈/3 1 4 1 5 9 2"))
(list 9))
(apl-test
"apl-run \"+\\\\5\" → triangular numbers"
(mkrv (apl-run "+\\5"))
(list 1 3 6 10 15))
; ---------- outer / inner products ----------
(apl-test
"apl-run \"1 2 3 ∘.× 1 2 3\" → mult table values"
(mkrv (apl-run "1 2 3 ∘.× 1 2 3"))
(list 1 2 3 2 4 6 3 6 9))
(apl-test
"apl-run \"1 2 3 +.× 4 5 6\" → dot product 32"
(mkrv (apl-run "1 2 3 +.× 4 5 6"))
(list 32))
; ---------- shape ----------
(apl-test
"apl-run \" 1 2 3 4 5\" → 5"
(mkrv (apl-run " 1 2 3 4 5"))
(list 5))
(apl-test "apl-run \"10\" → 10" (mkrv (apl-run "10")) (list 10))
; ---------- comparison ----------
(apl-test "apl-run \"3 < 5\" → 1" (mkrv (apl-run "3 < 5")) (list 1))
(apl-test "apl-run \"5 = 5\" → 1" (mkrv (apl-run "5 = 5")) (list 1))
(apl-test
"apl-run \"1 2 3 = 1 0 3\" → 1 0 1"
(mkrv (apl-run "1 2 3 = 1 0 3"))
(list 1 0 1))
; ---------- famous one-liners ----------
(apl-test
"apl-run \"+/(10)\" → sum 1..10 = 55"
(mkrv (apl-run "+/(10)"))
(list 55))
(apl-test
"apl-run \"×/10\" → 10! = 3628800"
(mkrv (apl-run "×/10"))
(list 3628800))
(apl-test "apl-run \"⎕IO\" → 1" (mkrv (apl-run "⎕IO")) (list 1))
(apl-test "apl-run \"⎕ML\" → 1" (mkrv (apl-run "⎕ML")) (list 1))
(apl-test "apl-run \"⎕FR\" → 1248" (mkrv (apl-run "⎕FR")) (list 1248))
(apl-test "apl-run \"⎕TS\" shape (7)" (mksh (apl-run "⎕TS")) (list 7))
(apl-test "apl-run \"⎕FMT 42\" → \"42\"" (apl-run "⎕FMT 42") "42")
(apl-test
"apl-run \"⎕FMT 1 2 3\" → \"1 2 3\""
(apl-run "⎕FMT 1 2 3")
"1 2 3")
(apl-test
"apl-run \"⎕FMT 5\" → \"1 2 3 4 5\""
(apl-run "⎕FMT 5")
"1 2 3 4 5")
(apl-test "apl-run \"⎕IO + 4\" → 5" (mkrv (apl-run "⎕IO + 4")) (list 5))
(apl-test
"apl-run \"(10 20 30 40 50)[3]\" → 30"
(mkrv (apl-run "(10 20 30 40 50)[3]"))
(list 30))
(apl-test
"apl-run \"(10)[5]\" → 5"
(mkrv (apl-run "(10)[5]"))
(list 5))
(apl-test
"apl-run \"A ← 100 200 300 ⋄ A[2]\" → 200"
(mkrv (apl-run "A ← 100 200 300 ⋄ A[2]"))
(list 200))
(apl-test
"apl-run \"V ← 10 ⋄ V[3]\" → 3"
(mkrv (apl-run "V ← 10 ⋄ V[3]"))
(list 3))
(apl-test
"apl-run \"(10 20 30)[1]\" → 10 (1-indexed)"
(mkrv (apl-run "(10 20 30)[1]"))
(list 10))
(apl-test
"apl-run \"V ← 10 20 30 40 50 ⋄ V[3] + 1\" → 31"
(mkrv (apl-run "V ← 10 20 30 40 50 ⋄ V[3] + 1"))
(list 31))
(apl-test
"apl-run \"(5)[3] × 7\" → 21"
(mkrv (apl-run "(5)[3] × 7"))
(list 21))