// What the formula settings say about the usual participation (relecture of a576b68): // the measured median, or twice C, even when the scale brings it back within its bounds. import { describe, expect, it } from 'vitest'; import { usualShown } from '../../src/lib/participation'; import type { ParticipationInfo } from '../../src/lib/types'; const base: ParticipationInfo = { ratio: 0.3, source: 'median', sample: 5, median: 3, bounded: false, voters: 3, minSample: 5, windowDays: 365, everyHours: 24, bounds: [0.01, 0.5], measuredAt: null, }; describe('usual participation as shown', () => { it('is the scale itself when nothing was bounded', () => { expect(usualShown(base, 10, 1)).toEqual({ voters: 3, ratio: 0.3 }); }); it('is the real median when the scale raised it to its floor', () => { const p = { ...base, median: 1, ratio: 0.01, voters: 57, bounded: true }; expect(usualShown(p, 5745, 50)).toEqual({ voters: 1, ratio: 1 / 5745 }); }); it('is twice C for the reference, even when the scale lowered it to its ceiling', () => { const p = { ...base, source: 'reference' as const, median: null, sample: 0, ratio: 0.5, voters: 1, bounded: true }; expect(usualShown(p, 2, 1)).toEqual({ voters: 2, ratio: 1 }); }); it('rounds a median between two numbers of voters, never its share', () => { const p = { ...base, median: 2.5, ratio: 0.01, voters: 57, bounded: true }; expect(usualShown(p, 5745, 50).voters).toBe(3); // Relecture of 71819f9: the share is that of the median itself — 2,5 voters out of 4 is // 62,5 %, not 3 out of 4 (75 %). const q = { ...base, median: 2.5, ratio: 0.5, voters: 2, bounded: true }; expect(usualShown(q, 4, 1)).toEqual({ voters: 3, ratio: 0.625 }); }); it('takes the share of twice C as it is, whatever the rounding', () => { const p = { ...base, source: 'reference' as const, median: null, sample: 0, ratio: 0.5, voters: 2, bounded: true }; expect(usualShown(p, 3, 0.75)).toEqual({ voters: 2, ratio: 0.5 }); }); });