CloudLab CI/CD / 门禁 doctor (push) Failing after 38s
CloudLab CI/CD / 单元测试 (push) Skipped
CloudLab CI/CD / 归档完整性 (push) Skipped
CloudLab CI/CD / 构建站点与归档 (push) Skipped
CloudLab CI/CD / 部署到 lab.hdtime.space(rsync) (push) Skipped
CloudLab CI/CD / 构建镜像并推送 Gitea 容器仓库 (push) Skipped
CloudLab CI/CD / 容器部署到 lab.hdtime.space (push) Skipped
CloudLab CI/CD / 发布版本(Tag) (push) Skipped
Freeze the real-execution control plane, runner, manifests, validation cases and tests under cloudlab-platform; preserve the IDE/static web source under cloudlab-web. Generated material library and runtime state are intentionally excluded.
80 lines
2.9 KiB
JavaScript
80 lines
2.9 KiB
JavaScript
const assert = require('assert');
|
|
const E = require('../app/compare-data-engine.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed++; console.log('ok ' + name); }
|
|
|
|
test('preset matrix is 3x3 and uses curated datasets', () => {
|
|
assert.strictEqual(E.PRESETS.length, 9);
|
|
assert.strictEqual(E.defaultMatrix().length, 9);
|
|
const ids = E.defaultMatrix().map(c => c.dataset);
|
|
assert.ok(ids.includes('molecule'));
|
|
assert.ok(ids.includes('de'));
|
|
assert.ok(ids.includes('expression'));
|
|
assert.ok(ids.includes('bistability'));
|
|
assert.ok(ids.includes('variant'));
|
|
});
|
|
|
|
test('CSV parser handles BOM, quotes, commas and newlines', () => {
|
|
const t = E.parse('\uFEFFx,y,note\n1,2,"a,b"\n3,4,"line1\nline2"\n', 'CSV');
|
|
assert.deepStrictEqual(t.headers, ['x', 'y', 'note']);
|
|
assert.strictEqual(t.rows.length, 2);
|
|
assert.strictEqual(t.rows[0][2], 'a,b');
|
|
assert.strictEqual(t.rows[1][2], 'line1\nline2');
|
|
assert.strictEqual(t.numeric.length, 2);
|
|
});
|
|
|
|
test('numeric columns need at least two valid values', () => {
|
|
const t = E.parse('a,b,c\n1,,x\n2,3,y\n,3,z\n', 'CSV');
|
|
assert.deepStrictEqual(t.numeric.map(n => n.name), ['a', 'b']);
|
|
});
|
|
|
|
test('perfect linear relationship has r=1 and exact OLS', () => {
|
|
const t = E.parse('x,y\n1,2\n2,4\n3,6\n', 'CSV');
|
|
const a = E.analyze(t, 'x', 'y');
|
|
assert.strictEqual(a.n, 3);
|
|
assert.strictEqual(a.skipped, 0);
|
|
assert.ok(Math.abs(a.r - 1) < 1e-12);
|
|
assert.ok(Math.abs(a.slope - 2) < 1e-12);
|
|
assert.ok(Math.abs(a.intercept) < 1e-12);
|
|
assert.strictEqual(a.x.median, 2);
|
|
assert.strictEqual(a.y.mean, 4);
|
|
});
|
|
|
|
test('pairwise missing values are skipped and counted', () => {
|
|
const t = E.parse('x,y\n1,2\n2,\n,3\n4,8\n', 'CSV');
|
|
const a = E.analyze(t, 'x', 'y');
|
|
assert.strictEqual(a.n, 2);
|
|
assert.strictEqual(a.skipped, 2);
|
|
assert.ok(Math.abs(a.slope - 2) < 1e-12);
|
|
});
|
|
|
|
test('zero variance yields undefined correlation and slope', () => {
|
|
const t = E.parse('x,y\n1,2\n1,4\n1,6\n', 'CSV');
|
|
const a = E.analyze(t, 'x', 'y');
|
|
assert.strictEqual(a.r, null);
|
|
assert.strictEqual(a.slope, null);
|
|
assert.strictEqual(a.intercept, null);
|
|
});
|
|
|
|
test('sampling is deterministic and keeps endpoints', () => {
|
|
const pts = Array.from({ length: 1000 }, (_, i) => [i, i * 2]);
|
|
const s = E.samplePoints(pts, 100);
|
|
assert.strictEqual(s.length, 100);
|
|
assert.deepStrictEqual(s[0], [0, 0]);
|
|
assert.deepStrictEqual(s[99], [999, 1998]);
|
|
assert.deepStrictEqual(E.samplePoints(pts, 100), s);
|
|
});
|
|
|
|
test('serialization and restore keep nine cell configs', () => {
|
|
const m = E.defaultMatrix();
|
|
m[3] = { id: 'B1', name: 'custom', dataset: 'de', x: 'log2FC', y: 'padj' };
|
|
const restored = E.restore(E.serialize(m));
|
|
assert.strictEqual(restored.length, 9);
|
|
assert.strictEqual(restored[3].dataset, 'de');
|
|
assert.strictEqual(restored[3].x, 'log2FC');
|
|
assert.strictEqual(restored[3].y, 'padj');
|
|
});
|
|
|
|
console.log('\n' + passed + ' DATA compare engine tests passed');
|