uCBQN/test/cells.bqn

218 lines
9.0 KiB
BQN
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.

# build/build replxx singeli native g debug f=-DEACH_FILLS f=-DTEST_CELL_FILLS && build/build replxx singeli native g debug heapverify f=-DTEST_CELL_FILLS OUTPUT=BQNh && ./BQN test/cells.bqn path/to/mlochbaum/BQN/bqn.js ./BQNh
# (replace bqn.js path with "reuse" to use the previous result (requires the test set to not have changed))
{𝕊: •Out "Usage: ./nonHeapverifyCBQN test/cells.bqn path/to/bqn.js heapverifyCBQN" •Exit 0} 2>•args
a0 •args
bqnjshCBQN •wdpath•file.At¨ •args
bqnjsFile •file.At "generated/cells_bqnjsOut.bqn"
hCBQNFile •file.At "generated/cells_hCBQNOut.bqn"
validFile •file.At "generated/cells_valid.bqn"
cbqni {"internal"<•listsys? •BQN"•internal"; @}
bqntype {cbqni@? 2; ¬cbqni.HasFill +˜0<0} # 0: full CBQN; 1: heapverify CBQN; 2: bqn.js
SHRun {
f•BQN"•SH"
coe F 𝕩
g•BQN"•term.OutRaw‿•term.ErrRaw {𝕎•ToUTF8𝕩}¨ ⊢" G oe
c0? •Exit c; @
}
GetTests { 𝕊:
tests
AddTests {tests 𝕩 @}
Prod { (<) <´ 𝕩}
FOk { wFgx: # filter out tests that'd immediately error due to bad shapes, or would
g (@g)g¯1
r =¨wx
s ¨wx
k 0r-0(+r×0>) 13g
# •Show k
ok ´ (´k) ¨ s
# {𝕊: ! w 0∘(F⎉g)⎊1 x}⍟¬ ok
ok k00
}¨/
# generating random numerical arrays:
# )r N←{⟨⟩:"1";•Repr⊑⍟(1=≠)𝕩} ⋄ J←{(⊣∾𝕨∾⊢)´𝕩} ⋄ •Out '⟨'∾'⟩'∾˜','J ("⥊"J≢⋈○N⥊)¨ 15↑ ⍷ {𝕊: ((1+•rand.Range 4)•rand.Range 4)•rand.Range 10}¨ ↕100
# xs ↩ ⟨0,↕0⟩ ∾
{ 𝕊: # F⎉k x
fs <,,,,,«,»,,×˝,¨,1˙,,'a'˙,'𝕨',"ab"2˙,,<"ab"1,23,231
xs
1, <2,
23, 23424, 11114,
0, 02"", 400, 023450,
11212'a', 22"abcd", 23,
ks @, ¯∞, ¯1, 0, 101, 2, 3, 4, 5,
AddTests Prod fs, ks, xs
} 1
{ 𝕊: # w ⋈⎉k x
xs 0, 22"a"1 {𝕩×´𝕩}¨ 1, 23, 20, 234, 2234, 34
ks ¯∞, ¯1, 0, 1, 2, 3, 4, 01, ¯∞21, , 0, 0, 1, 1, 2, 2
AddTests Prod xs, , ks, xs
} 1
{ 𝕊: # w ⊏⎉k x / w ⊑⎉k x
ws 0, 1, 2, 3, ¯1, ¯2, <1
xs 22"a"1"b""cd", 333'a'+27, 36 {𝕩×´𝕩}¨ 23, 20, 234, 2234, 34
ks 0, 1, 2, 3, 4, 01, 02
AddTests FOk Prod ws, , ks, xs
AddTests FOk Prod 0100¯100, , 012, xs0,<4
} 1
{ 𝕊: # w ≡⎉k x
xs 0, 23@+6 {𝕩×´𝕩}¨ 1, 23, 03, 203, 423, 2423, 31
ks ¯∞, ¯1, 0, 1, 2, 3, 4, 01, 21
AddTests FOk Prod xs, , ks, xs
xs2 23175, [¯81¯81¯81, 000]{𝕩-˜𝕩+23'¯'}¨ 0100100000
AddTests FOk Prod xs2, , ks, xs2
} 1
{ 𝕊: # w ⍉⎉k x
ws 0, 1, 2, 3, 4, ¯1, 10
xs 222"a"1"b", 333'a'+27, 36 {𝕩×´𝕩}¨ 23, 20, 234, 2234, 34, 32122
ks 0, 1, 2, 3, 4, 5, 01, 02
AddTests FOk Prod ws, , ks, xs
} 1
{ 𝕊: # w »⎉k x / w «⎉k x
ws 0, 1, 'a', "ab", <"h"2
xs 222"a"1"b", 333'a'+27, 36 {𝕩×´𝕩}¨ 23, 20, 234, 2234, 34, 32122
ks 0, 1, 2, 3, 4, @, 01, 02
AddTests FOk Prod ws, «», ks, xs
} 1
{ 𝕊: # w ↑⎉k x / w ↓⎉k x
ws 0,1,2,¯1,¯2,10,11
xs 222"a"1"b", 333'a'+27, 36 {𝕩×´𝕩}¨ 23, 02, 20, 234, 2234, 34, 32122
ks 0, 1, 2, 3, 4, @, 01, 02, 1¯1
AddTests FOk Prod ws, , ks, xs
} 1
{ 𝕊: # w -⎉k x
xs {𝕩×´𝕩}¨ 234, 23, 34, 2, 3, 4, 2234, 32122
ks 0, 1, 2, 3, 4, ¯1, ¯2, 01, 02, 10, 20, 21, 12
AddTests FOk Prod xs, -, ks, xs
AddTests Prod xs, -, , xs # test regular leading axis behavior
} 1
tests
}
getFill {bqntype2? cbqni•ns.Has"hasfill"? {cbqni.HasFill 𝕩? 10𝕩; '!'}; {1 '!' 0𝕩}}
Info {𝕩, GetFill 𝕩}
RunTests {
fkx: (Info F{k@? 𝔽˘; 𝔽k})"err" x;
wfkx: w (Info F{k@? 𝔽˘; 𝔽k})"err" x
}¨
{
"0"a0? # bqn.js
•Out(bqntype2) "Warning: doesn't seem like the first argument is bqn.js!"
res RunTests GetTests@
bqnjsFile •FChars •Repr res
;
"1"a0? # heapverify
•Out(bqntype1) "Warning: doesn't seem like the second argument is CBQN with heapverify!"
tests GetTests@
valid '0'-˜•FChars validFile
ok valid2
HTests { 𝕊:
okTests ok/tests
hasFill 0=ok/valid
cbqni.Temp 2 f1 RunTests okTests /˜ hasFill
cbqni.Temp 1 f0 RunTests okTests /˜ ¬hasFill
cbqni.Temp 0
(hasFill) f0f1
}
hCBQNFile •FChars •Repr HTests(ok/) "err"¨ tests
;
# base
•Out(bqntype0) "Warning: doesn't seem like the running binary is CBQN without heapverify!"
tests GetTests@
•Out "Running ", •Repr tests, " tests on base CBQN.."
cfefo <˘>{cbqni.Temp@ (cbqni.Temp@) RunTests 𝕩}¨ tests
validFile •FChars '0'+ 2 cfe + 2×"err"¨ fo # 2: errored; 1: invalid fill; 0: valid fill
{ 𝕊:
•Out "Calling bqn.js.."
•file.Remove•file.Exists bqnjsFile
SHRun bqnjs, •file.At "cells.bqn", "0", ""
{•file.Exists bqnjsFile?@; •Out "bqn.js didn't produce the result file!" •Exit 1}
} "reuse"a0
•file.Remove•file.Exists hCBQNFile
•Out "Calling heapverify build.."
SHRun hCBQN, •file.At "cells.bqn", "1", ""
•Out "Comparing.."
bo •Import bqnjsFile
ho •Import hCBQNFile
hCount +´ "err"¨ bo
badH0 hBadFill0 hSuperset0
badB0 bBadFill0 bSuperset0
hBadEmpty0
hBadButBase0
FRepr {0𝕩? •Repr 𝕩; '!'fGetFill 𝕩? •Repr𝕩, "⥊", "<"(0f) •Repr f; •Repr 𝕩}
FTest { testexpgot:
! expgot
{Fkx¯3𝕩 {3𝕩?""; "("") "˜FRepr𝕩}𝕩 , •Repr f, {k@?"˘";"⎉"•Repr k}, " ", FRepr x} test
": "
{
exp"err"? "expected error, but got "•Repr got;
got"err"? "expected result, but got error";
{𝕨"; "𝕩}´ @¨/ "result""result fill" {m𝕊eg: {eg? @; "expected ",m," to be ",FRepr e,", got ",FRepr g}}¨ <˘>exp,got
}
}
{ 𝕊 tfbh:
{
bf?@;
bf? badB+1 •Out "base: incrorrect result: ",FTest tbf;
'!'1b? bSuperset+1;
bBadFill+1 •Out "base: bad fill: ",FTest tbf
}
{
bh?@; {´0=¨ (¯3t)¯1t? hBadEmpty+1;@}
fh? hBadButBase+1;
bh? badH+1 •Out "heapverify: incrorrect result: ",FTest tbh;
'!'1b? hSuperset+1;
hBadFill+ 1 •Out "heapverify: bad fill: ",FTest tbh
# ´0=≠∘⥊¨ (¯3↓t)∾¯1↑t? hBadEmpty+↩1;
# badH+↩1 ⋄ •Out ∾⟨"heapverify: incrorrect result: ",FTest t‿b‿h⟩
}
}¨ <˘>tests, fo, bo, ho
•Out
"Base: ",
•Repr tests, " tests: "
•Repr badB, " wrong results, "
•Repr bBadFill, " wrong fills, "
•Repr bSuperset, " superset fills"
hBadTot hBadFill
•Out
"Heapverify: "
•Repr hCount, " tests: "
•Repr hBadButBase, " wrong results equal to base, "
•Repr badH, " wrong results, "
•Repr hBadFill, " wrong fills, "
•Repr hSuperset, " superset fills; "
•Repr hBadEmpty, " wrong results had empty input(s)"
•Exit(´0badHbadB) 1
•Out "Passed!"
}