Files
WebApp/src/app/gobernanza/figures.spec.ts
T

78 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { interpretabilityFigures } from './figures';
describe('governance figures', () => {
it('draws a survival report as curves with bands and the model points', () => {
const [found] = interpretabilityFigures({
kind: 'curves',
curves: [
{ name: 'Kaplan-Meier', months: [0, 6], survival: [1, 0.9], low: [1, 0.8], high: [1, 1] },
],
predicted: { name: 'Modelo', months: [6], survival: [0.92], low: [0.85], high: [0.97] },
});
expect(found.figure.data.length).toBe(3); // band, curve, model points
expect((found.figure.data[2] as any).error_y.array[0]).toBeCloseTo(0.05);
});
it("draws each survival scenario after the cohort's curves, titled with its deaths", () => {
const scenario = {
escenario: 'HER2+ · ≥60 años · estadio III–IV (Alto)',
n: 1142,
fallecidos: 308,
horizons_months: [6, 12, 18],
km: { months: [0, 12], S: [1, 0.8], low: [1, 0.75], high: [1, 0.85] },
weibull: { t: [0, 12], S: [1, 0.8] },
weibull_fractional: { t: [0, 12], S: [1, 0.79] },
points: { COMB: { S: [0.86, 0.8, 0.74], low: [0.85, 0.78, 0.72], high: [0.88, 0.82, 0.76] } },
};
const found = interpretabilityFigures({
kind: 'curves',
curves: [{ name: 'Kaplan-Meier', months: [0], survival: [1], low: [1], high: [1] }],
predicted: { name: 'Modelo', months: [6], survival: [0.9], low: [0.8], high: [0.95] },
escenarios: [scenario],
});
expect(found.length).toBe(2);
expect(found[1].title).toContain('fallecidos = 308');
expect(found[1].figure.data.length).toBe(5); // band, KM, Weibull, fractional, points
expect((found[1].figure.data[4] as any).x).toEqual([6, 12, 18]);
});
it('draws a recurrence scenario: KM band, both Weibulls and the model points', () => {
const [found] = interpretabilityFigures({
kind: 'scenarios',
recurrencia: {
horizons_months: [12, 36],
escenarios: [
{
cohorte_nombre: 'METABRIC',
escenario: 'RE+',
n: 10,
recaidas: 3,
km: { months: [0, 12], S: [1, 0.9], low: [1, 0.8], high: [1, 1] },
weibull: { t: [0, 12], S: [1, 0.9] },
weibull_fractional: { t: [0, 12], S: [1, 0.91] },
points: { COMB: { S: [0.95, 0.8], low: [0.9, 0.7], high: [0.99, 0.9] } },
},
],
},
});
expect(found.figure.data.length).toBe(5); // band, KM, Weibull, fractional, points
});
it('draws an age curve with its centile band', () => {
const [found] = interpretabilityFigures({
kind: 'age_curves',
curves: {
value: {
kind: 'curves',
curve: { age_months: [16, 36], p5: [1, 2], median: [2, 3], p95: [3, 4] },
},
},
});
expect(found.figure.data.length).toBe(2);
});
it('draws nothing for a report it does not know', () => {
expect(interpretabilityFigures({ kind: 'other' })).toEqual([]);
});
});