Download tests/test-engine.js from Hugdrigo/causalscope-experiment-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/Hugdrigo/causalscope-experiment-lab/resolve/main/tests/test-engine.js
- Command line
-
hf download hf://spaces/Hugdrigo/causalscope-experiment-lab/tests/test-engine.js
-
curl -L -o test-engine.js https://huggingface.co/spaces/Hugdrigo/causalscope-experiment-lab/resolve/main/tests/test-engine.js
1.55 kB
| ; | |
| const assert=require('node:assert/strict'); | |
| const core=require('../engine.js'); | |
| const near=(a,b,eps=1e-6)=>assert.ok(Math.abs(a-b)<eps,`${a} not within ${eps} of ${b}`); | |
| near(core.normCDF(0),.5,2e-7); | |
| near(core.normCDF(1.96),.97500210485178,2e-7); | |
| near(core.normInv(.975),1.95996398454,1e-6); | |
| let [lo,hi]=core.wilson(50,100);near(lo,.4038315304,1e-6);near(hi,.5961684696,1e-6); | |
| let x=core.evaluate({nA:1000,kA:100,nB:1000,kB:120}); | |
| near(x.pA,.1);near(x.pB,.12);near(x.delta,.02);near(x.relative,.2);assert.ok(x.ci[0]<.02&&x.ci[1]>.02);assert.equal(x.allocationWarning,false); | |
| assert.ok(x.pValue>.05,'This modest effect is not detected at alpha=.05'); | |
| x=core.evaluate({nA:10000,kA:1000,nB:10000,kB:1300});assert.ok(x.pValue<.00001);assert.equal(x.detected,true); | |
| x=core.evaluate({nA:1000,kA:100,nB:2000,kB:230});assert.equal(x.allocationWarning,true); | |
| x=core.evaluate({nA:10,kA:0,nB:10,kB:0});assert.equal(x.pValue,1);assert.equal(x.sparse,true); | |
| let p=core.sampleSize(.06,.10,.05,.80);assert.ok(p.perArm>20000&&p.perArm<30000);assert.equal(p.total,2*p.perArm); | |
| assert.throws(()=>core.evaluate({nA:10,kA:11,nB:9,kB:3}));assert.throws(()=>core.sampleSize(.99,.5)); | |
| const sim1=core.simulate({nA:1000,kA:60,nB:1000,kB:80},100,202620); | |
| const sim2=core.simulate({nA:1000,kA:60,nB:1000,kB:80},100,202620); | |
| assert.deepEqual(sim1,sim2,'Same seed reproduces the same simulation');assert.equal(sim1.deltas.length,100); | |
| assert.ok(sim1.p05<=sim1.p50&&sim1.p50<=sim1.p95); | |
| console.log('PASS: 17 core statistical and reproducibility assertions'); | |