import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import { backToTopThreshold } from './backToTopThreshold'; describe('backToTopThreshold', () => { it('is 60% van de viewporthoogte', () => { expect(backToTopThreshold(1000)).toBe(600); }); it('geeft 0 bij ongeldige hoogtes', () => { for (const h of [0, -10, NaN, Infinity, -Infinity]) { expect(backToTopThreshold(h)).toBe(0); } }); it('ligt altijd tussen 0 en de hoogte (invariant)', () => { fc.assert( fc.property(fc.double({ min: 0, max: 1e7, noNaN: true }), (h) => { const t = backToTopThreshold(h); return t >= 0 && t <= h; }), ); }); it('stijgt mee met de hoogte bij eindige waarden (monotoon)', () => { const finite = fc.double({ noNaN: true, noDefaultInfinity: true }); fc.assert( fc.property(finite, finite, (a, b) => { const [lo, hi] = a <= b ? [a, b] : [b, a]; return backToTopThreshold(lo) <= backToTopThreshold(hi); }), ); }); it('volgt het model 0.6 × max(0, h) (oracle)', () => { fc.assert( fc.property(fc.double(), (h) => { const model = Number.isFinite(h) ? 0.6 * Math.max(0, h) : 0; expect(backToTopThreshold(h)).toBe(model); }), ); }); });