56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { durationMax, durationRows } from './durations';
|
|
import { Reading } from './measures';
|
|
|
|
const reading = (score?: number, n = 0, low?: number, high?: number): Reading => ({
|
|
populations: { 'measure-observation': n },
|
|
score,
|
|
low,
|
|
high,
|
|
strata: {},
|
|
});
|
|
|
|
describe('durationRows', () => {
|
|
const reads: Record<string, Reading> = {
|
|
A: reading(0, 3, 0, 1),
|
|
B: reading(6, 20, 4, 8),
|
|
C: reading(undefined, 0),
|
|
};
|
|
const rows = durationRows(
|
|
[
|
|
{ label: 'zero', measure: 'A' },
|
|
{ label: 'value', measure: 'B' },
|
|
{ label: 'nothing measured', measure: 'C' },
|
|
{ label: 'no report', measure: 'D' },
|
|
{ label: 'not in the catalog', measure: 'E' },
|
|
{ label: 'no measure' },
|
|
],
|
|
(m) => reads[m],
|
|
(m) => m !== 'E',
|
|
);
|
|
|
|
it('keeps a real zero as a value', () => {
|
|
expect(rows[0]).toEqual({
|
|
label: 'zero',
|
|
status: 'value',
|
|
median: 0,
|
|
observations: 3,
|
|
low: 0,
|
|
high: 1,
|
|
});
|
|
});
|
|
it('tells no measurements from an unpublished measure', () => {
|
|
expect(rows.map((r) => r.status)).toEqual([
|
|
'value',
|
|
'value',
|
|
'empty',
|
|
'empty',
|
|
'unpublished',
|
|
'unpublished',
|
|
]);
|
|
});
|
|
it('scales from zero to the largest median or third quartile', () => {
|
|
expect(durationMax(rows)).toBe(8);
|
|
expect(durationMax([])).toBe(0);
|
|
});
|
|
});
|