import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import { slideLabel } from './slideLabel'; // A position within a carousel: 1 to 20 slides, index within range const position = fc .integer({ min: 1, max: 20 }) .chain((count) => fc .integer({ min: 0, max: count - 1 }) .map((index) => ({ index, count })), ); describe('slideLabel', () => { it('counts from one', () => { expect(slideLabel(0, 2)).toBe('Review 1 van 2'); expect(slideLabel(1, 2)).toBe('Review 2 van 2'); }); it('gives back its numbers (round-trip)', () => { fc.assert( fc.property(position, ({ index, count }) => { const [, n, m] = /^Review (\d+) van (\d+)$/.exec(slideLabel(index, count)) ?? []; expect(Number(n)).toBe(index + 1); expect(Number(m)).toBe(count); }), ); }); it('always reads "Review n van m" with 1 <= n <= m (invariant)', () => { fc.assert( fc.property(position, ({ index, count }) => { const match = /^Review (\d+) van (\d+)$/.exec( slideLabel(index, count), ); expect(match).not.toBeNull(); const [n, m] = [Number(match?.[1]), Number(match?.[2])]; expect(n >= 1 && n <= m).toBe(true); }), ); }); });