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

87 lines (75 loc) 3.52 kB
import { describe, it } from 'node:test' import assert from 'node:assert' import { extractMetrics } from '../../lib/table/simple-table/extract-metric.js' import Column from '../../lib/column/index.js' import Table from '../../lib/table/index.js'; describe('extractMetrics', () => { it('should extract a simple nested metric', () => { const col = { a: { b: { c: 42 } } }; const result = extractMetrics({ col }, ['a.b.c']) assert.deepStrictEqual(result, { col: { 'a.b.c': 42 } }); }); it('should return undefined for a non-existent metric', () => { const col = { a: { b: {} } }; assert.strictEqual(extractMetrics({ col }, ['a.b.c'])[0], undefined); }); it('should handle undefined metric', () => { const col = { a: 42 }; const result = extractMetrics({ col }, ['b']); assert.deepStrictEqual(result, { col: { b: undefined } }); }); it('should convert numeric arrays to Column with nested', () => { const col = { values: [1, 2, 3, 4] }; const result = extractMetrics({ col }, ['values.sum']); assert.deepStrictEqual(result, { col: { 'values.sum': 10 } }); }); it('should handle empty array in extractMetrics', () => { const col = { values: [] }; const result = extractMetrics({ col }, ['values']); assert.deepStrictEqual(result, { col: { values: [] } }); }); it('should handle empty array with zero length', () => { const col = { values: [] }; const result = extractMetrics({ col }, ['values']); assert.deepStrictEqual(result, { col: { values: [] } }); }); it('nested descriptive', () => { const table = new Table({ test: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] }, 'TestTable'); const descriptives = table.descriptive('confidenceInterval.high', 'zScores.mean'); assert.deepStrictEqual(descriptives, { test: { 'confidenceInterval.high': 76.65700117744836, 'zScores.mean': -1.1102230246251565e-16 } }) }); it('should convert numeric arrays to Column', () => { const col = { values: [1, 2, 3, 4] }; const result = extractMetrics({ col }, ['values']); // assert.ok(result.col.values instanceof Column); assert.deepStrictEqual(result.col.values, [1, 2, 3, 4]); }); // Помощь: объектная метрика — frequencies; скаляр — mean. it('extractMetrics: object-only метрики → ранний return htmlResult', () => { const columns = { A: new Column([1,1,2,3,3], 'A'), B: new Column([0,0,0,1,2], 'B'), }; const res = extractMetrics(columns, ['frequencies']); // только объектная метрика const html = res.htmlTable; assert.equal(typeof html, 'string'); assert.ok(html.includes('for A')); assert.ok(html.includes('for B')); }); it('extractMetrics: смешанный кейс (object + scalar)', () => { const columns = { A: new Column([1,2,3,4], 'A'), B: new Column([2,2,3,5], 'B'), }; const res = extractMetrics(columns, ['frequencies', 'mean']); const html = res.htmlTable; assert.equal(typeof html, 'string'); // должен быть блок по объектной метрике и итоговая таблица по scalar-метрикам assert.ok(html.toLowerCase().includes('descriptive statistics')); }); });