UNPKG

als-statistics

Version:

Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co

31 lines (27 loc) 965 B
import test from 'node:test'; import assert from 'node:assert/strict'; import { makeRng } from './_rng.js'; test('rng: deterministic by seed', () => { const A = makeRng('seed-1'); const B = makeRng('seed-1'); const a = Array.from({length:100}, () => A.rand()); const b = Array.from({length:100}, () => B.rand()); assert.deepEqual(a, b); }); test('rng: range is [0,1) and never 1', () => { const R = makeRng('edge-range'); for (let i=0;i<2000;i++) { const x = R.rand(); assert.ok(x >= 0 && x < 1, `x in [0,1): ${x}`); } }); test('rng: normal has mean ~ mu and sd ~ sigma (rough)', () => { const R = makeRng('norm-check'); const mu = 3.0, sd = 2.0; const arr = R.normal(mu, sd, 5000); const mean = arr.reduce((s,x)=>s+x,0)/arr.length; const variance = arr.reduce((s,x)=>s+(x-mean)*(x-mean),0)/(arr.length-1); const sdev = Math.sqrt(variance); assert.ok(Math.abs(mean - mu) < 0.1); assert.ok(Math.abs(sdev - sd) < 0.15); });