'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const Easing = require('../src/easing.js'); const Planet = require('../src/planet.js'); describe('Click-tween defaults (KWin Click Tween)', () => { it('matches Tim\'s default scale, durations and Qt easing parameters', () => { const c = Easing.CLICK_TWEEN; assert.equal(c.pressScale, 0.8); assert.equal(c.releaseScale, 1.0); assert.equal(c.pressDuration, 0.150); assert.equal(c.releaseDuration, 0.720); assert.equal(c.backOvershoot, 1.70158); assert.equal(c.elasticPeriod, 0.3); assert.equal(c.elasticAmplitude, 1.0); assert.equal(c.pressEase, Easing.easeOutBack); assert.equal(c.releaseEase, Easing.easeOutElastic); }); it('easeOutBack starts at 0, ends at 1, and overshoots past 1 mid-way', () => { assert.ok(Math.abs(Easing.easeOutBack(0)) < 1e-12); assert.ok(Math.abs(Easing.easeOutBack(1) - 1) < 1e-12); let max = 0; for (let i = 0; i <= 100; i++) { const v = Easing.easeOutBack(i / 100); if (v > max) { max = v; } } assert.ok(max > 1.01, 'OutBack overshoots, max=' + max); // Qt / Penner default 1.70158 peaks around 1.1. assert.ok(max < 1.2, 'overshoot is the Qt default, max=' + max); }); it('easeOutElastic ends at 1 and oscillates around the end value', () => { assert.equal(Easing.easeOutElastic(0), 0); assert.equal(Easing.easeOutElastic(1), 1); const mid = Easing.easeOutElastic(0.3); // Decaying sine: not monotonic; some samples exceed 1. let above = false; let below = false; for (let i = 1; i < 40; i++) { const v = Easing.easeOutElastic(i / 40); if (v > 1.01) { above = true; } if (v < 0.99 && i > 10) { below = true; } } assert.ok(above, 'elastic overshoots above 1'); assert.ok(below, 'elastic undershoots as it decays'); assert.ok(typeof mid === 'number'); }); it('tween from 1.0 to 0.8 with easeOutBack overshoots below 0.8 then settles', () => { const c = Easing.CLICK_TWEEN; assert.ok(Math.abs(Easing.tween(1, 0.8, 0, c.pressEase) - 1) < 1e-12); assert.ok(Math.abs(Easing.tween(1, 0.8, 1, c.pressEase) - 0.8) < 1e-12); let min = 1; for (let i = 0; i <= 100; i++) { const v = Easing.tween(1, 0.8, i / 100, c.pressEase); if (v < min) { min = v; } } assert.ok(min < 0.8 - 0.005, 'press overshoots below 0.8, min=' + min); }); }); describe('Planet apex-ease and bounce parameters', () => { it('derives faster ease and bounce from lower fallTime (low air resistance)', () => { const terra = Planet.defaultPlanet(); assert.ok(Math.abs(terra.apexEaseTime - 0.15 * 3) < 1e-12); assert.ok(Math.abs(terra.bounceDuration - 0.12 * 3) < 1e-12); assert.equal(terra.bounceSquash, 0.16); assert.ok(Math.abs(terra.fallAccel - terra.fallSpeed / terra.apexEaseTime) < 1e-9); }); }); describe('Swap tween (t1121)', () => { it('easeOutCubic is 0 at 0, 1 at 1, and 0.875 at 0.5', () => { assert.equal(Easing.easeOutCubic(0), 0); assert.equal(Easing.easeOutCubic(1), 1); assert.ok(Math.abs(Easing.easeOutCubic(0.5) - 0.875) < 1e-12); assert.ok(Easing.easeOutCubic(0.25) > 0.25, 'front-loaded (fast finish)'); }); it('SWAP_TWEEN lasts 80–120 ms and uses easeOutCubic', () => { const s = Easing.SWAP_TWEEN; assert.ok(s.duration >= 0.08 && s.duration <= 0.12, 'duration=' + s.duration); assert.equal(s.ease, Easing.easeOutCubic); }); });