diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-09 10:58:58 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-09 10:58:58 -0400 |
| commit | 24df71f0cce04aa9b3f80630b95bb29a7ade7639 (patch) | |
| tree | 66dcd98d3fee1c7231bb24e5bd5429b965b6fbd8 | |
| parent | 1738b258c94d521104d3e79af85dca444b3a3171 (diff) | |
Add a simple testing framework
| -rwxr-xr-x | c.bqn | 3 | ||||
| -rw-r--r-- | test/cases.bqn | 5 | ||||
| -rwxr-xr-x | test/t.js | 19 |
3 files changed, 25 insertions, 2 deletions
@@ -59,6 +59,5 @@ Gen←{ Compile←{ body←GenFn∘Parse 𝕩 rcp←"x" GenFn∘Parse "1÷x" - (1↓∾)(","∾⥊∘⍕)¨ Gen ⟨⟨0‿1,1‿1⟩/¨¨f64 ⋄ ⥊<"fn" ⋄ ⟨body,rcp⟩⟩ + Gen ⟨⟨0‿1,1‿1⟩/¨¨f64 ⋄ ⥊<"fn" ⋄ ⟨body,rcp⟩⟩ } -•←Compile "b←3⋄d←(b×b)-4×2×1⋄((-b)+√d)÷2×2" diff --git a/test/cases.bqn b/test/cases.bqn new file mode 100644 index 00000000..438a435a --- /dev/null +++ b/test/cases.bqn @@ -0,0 +1,5 @@ +2 % 1+1 +-2 % 1⌊-2 +-1 % -2⌊1 +0 % s←√5⋄⌊9×|5-s×s +-0.5 % b←3⋄d←(b×b)-4×2×1⋄((-b)+√d)÷2×2 diff --git a/test/t.js b/test/t.js new file mode 100755 index 00000000..50554a5e --- /dev/null +++ b/test/t.js @@ -0,0 +1,19 @@ +//usr/bin/env node "$0" $@;exit $? +const bqn=require(require('os').homedir+'/bin/bqn') + , load=f=>require('fs').readFileSync(__dirname+'/'+f,'utf8') + , runWasm=w=>new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.from(w))) + .exports.fn() + +const t=load('cases.bqn').split('\n').filter(x=>x).map(x=>x.split(' % ')) + , test=t.map(e=>'"'+e[1]+'"').join('\n') + , expt=t.map(e=>+e[0]) + , rslt=bqn(load('../c.bqn','utf8').concat('Compile¨⟨'+test+'⟩')) + .a.map((a,i)=>runWasm(a.a)) + , pass=rslt.map((r,i)=>r===expt[i]) + , fail=pass.map((p,i)=>p?-1:i).filter(i=>i>=0) +console.log( + fail.length + ? fail.map(i=>'"'+test[i]+'": expected '+expt[i]+' but received '+rslt[i]) + : "All passed!" +) +process.exit(+(fail.length>0)) |
