Files
WebApp/src/app/paciente/survival-combination.spec.ts
T

50 lines
1.9 KiB
TypeScript

import { combinationOf, noCurveText, survivalFigure } from './survival-combination';
describe('combinationOf', () => {
const values = { age_group: '<30', cytology: 'NA', hpv: 'positive' };
const report = { km_combinaciones: [{ valores: values, n: 9, fallecidos: 6 }] };
it('takes only the entry with all her values, a missing one as NA', () => {
expect(combinationOf(report, { age_group: '<30', cytology: null, hpv: 'positive' })?.n).toBe(9);
expect(combinationOf(report, { age_group: '<30', cytology: null, hpv: 'negative' })).toBe(
undefined,
);
expect(combinationOf(report, { age_group: '<30' })).toBe(undefined);
expect(combinationOf({}, values)).toBe(undefined);
});
it('tells an old report apart from a combination with too few deaths', () => {
expect(noCurveText({}, undefined)).toContain('no publica esta curva');
expect(
noCurveText(
{ ...report, min_fallecidos_escenario: 5 },
{ valores: values, n: 9, fallecidos: 2 },
),
).toContain('n = 9, fallecidos = 2; mínimo requerido: 5');
});
it('draws every fit the report has, and the Kaplan-Meier alone in an older report', () => {
const km = { months: [0, 1], S: [1, 0.9], low: [1, 0.8], high: [1, 0.95] };
const old = { valores: values, n: 9, fallecidos: 6, km };
expect(survivalFigure(old).data.map((t) => (t as { name?: string }).name)).toContain(
'Kaplan-Meier',
);
const fit = { t: [0, 1], S: [1, 0.9] };
const full = {
...old,
weibull: fit,
weibull_fractional: fit,
points: { COMB: { S: [0.9] } },
horizons_months: [12],
};
const names = survivalFigure(full).data.map((t) => (t as { name?: string }).name);
expect(names).toEqual(
expect.arrayContaining([
'Weibull',
'Weibull fraccional',
'LR + HBN combinado (IC 95 % bootstrap)',
]),
);
});
});