import { describe, expect, it } from 'vitest'; import * as Easing from './tween_easing.js'; const SAMPLE_POINTS = [0, 0.1, 0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1]; const EXPECTED: Record = { backIn: [ -0, -0.014314220000000002, -0.06413656250000001, -0.09935168000000003, -0.08769750000000004, -0.02902752000000009, 0.1825903124999999, 0.5911720199999999, 0.9999999999999998, ], backInOut: [ -0, -0.037518552000000004, -0.09968184375, 0.0899257920000001, 0.5, 0.9100742079999999, 1.09968184375, 1.0375185519999999, 1, ], backOut: [ 2.220446049250313e-16, 0.4088279800000001, 0.8174096875000001, 1.02902752, 1.0876975, 1.09935168, 1.0641365625, 1.01431422, 1, ], bounceIn: [ 0, 0.01187500000000008, 0.02734375, 0.22750000000000004, 0.234375, 0.09000000000000019, 0.52734375, 0.9243750000000001, 1, ], bounceInOut: [0, 0.030000000000000027, 0.1171875, 0.34875000000000006, 0.5, 0.6512499999999999, 0.8828125, 0.97, 1], bounceOut: [ 0, 0.07562500000000001, 0.47265625, 0.9099999999999998, 0.765625, 0.7725, 0.97265625, 0.9881249999999999, 1, ], circularIn: [ 0, 0.005012562893380035, 0.031754163448145745, 0.08348486100883201, 0.1339745962155614, 0.19999999999999996, 0.3385621722338523, 0.5641101056459328, 1, ], circularInOut: [ -0, 0.010102051443364402, 0.0669872981077807, 0.20000000000000007, 0.5, 0.7999999999999999, 0.9330127018922193, 0.9898979485566356, 1, ], circularOut: [ 0, 0.4358898943540673, 0.6614378277661477, 0.8, 0.8660254037844386, 0.916515138991168, 0.9682458365518543, 0.99498743710662, 1, ], cubicIn: [0, 0.0010000000000000002, 0.015625, 0.06400000000000002, 0.125, 0.216, 0.421875, 0.7290000000000001, 1], cubicInOut: [0, 0.004000000000000001, 0.0625, 0.25600000000000006, 0.5, 0.744, 0.9375, 0.996, 1], cubicOut: [0, 0.2709999999999999, 0.578125, 0.784, 0.875, 0.9359999999999999, 0.984375, 0.999, 1], elasticIn: [ 0, 1.1959441397923372e-18, 0.0039062499999999952, -0.015625, 1.1481063742006436e-17, 0.0625, -0.12500000000000003, 6.123233995736767e-17, 1, ], elasticInOut: [0, 0.001953125, 5.740531871003218e-18, -0.12500000000000003, 0.5, 1.125, 1, 0.998046875, 1], elasticOut: [0, 1, 1.125, 0.9375, 1, 1.015625, 0.99609375, 1, 1], exponentialIn: [ 0, 0.0019531249999999998, 0.005524271728019903, 0.015625000000000003, 0.03125, 0.06249999999999999, 0.1767766952966369, 0.5000000000000001, 1, ], exponentialInOut: [0, 0.0019531249999999993, 0.015625, 0.12500000000000003, 0.5, 0.875, 0.984375, 0.998046875, 1], exponentialOut: [0, 0.5, 0.8232233047033631, 0.9375, 0.96875, 0.984375, 0.99447572827198, 0.998046875, 1], linearNone: [0, 0.1, 0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1], quadraticIn: [0, 0.010000000000000002, 0.0625, 0.16000000000000003, 0.25, 0.36, 0.5625, 0.81, 1], quadraticInOut: [0, 0.020000000000000004, 0.125, 0.32000000000000006, 0.5, 0.6799999999999999, 0.875, 0.98, 1], quadraticOut: [0, 0.19, 0.4375, 0.6400000000000001, 0.75, 0.84, 0.9375, 0.9900000000000001, 1], quarticIn: [ 0, 0.00010000000000000003, 0.00390625, 0.025600000000000008, 0.0625, 0.1296, 0.31640625, 0.6561000000000001, 1, ], quarticInOut: [0, 0.0008000000000000003, 0.03125, 0.20480000000000007, 0.5, 0.7951999999999999, 0.96875, 0.9992, 1], quarticOut: [0, 0.3438999999999999, 0.68359375, 0.8704000000000001, 0.9375, 0.9744, 0.99609375, 0.9999, 1], quinticIn: [ 0, 0.000010000000000000004, 0.0009765625, 0.010240000000000004, 0.03125, 0.07776, 0.2373046875, 0.5904900000000002, 1, ], quinticInOut: [ 0, 0.00016000000000000007, 0.015625, 0.16384000000000007, 0.5, 0.8361599999999999, 0.984375, 0.99984, 1, ], quinticOut: [0, 0.4095099999999998, 0.7626953125, 0.92224, 0.96875, 0.98976, 0.9990234375, 0.99999, 1], sinusoidalIn: [ 0, 0.01231165940486223, 0.07612046748871326, 0.19098300562505255, 0.2928932188134524, 0.41221474770752686, 0.6173165676349102, 0.843565534959769, 1, ], sinusoidalInOut: [ 0, 0.024471741852423234, 0.1464466094067262, 0.3454915028125263, 0.49999999999999994, 0.6545084971874737, 0.8535533905932737, 0.9755282581475768, 1, ], sinusoidalOut: [ 0, 0.15643446504023087, 0.3826834323650898, 0.5877852522924731, 0.7071067811865475, 0.8090169943749475, 0.9238795325112867, 0.9876883405951378, 1, ], }; describe('tween_easing', (): void => { it.each(Object.keys(EXPECTED))('%s matches its reference curve', (name): void => { const fn = (Easing as unknown as Record number>)[name]!; const actual = SAMPLE_POINTS.map((k): number => fn(k)); for (const [index, value] of actual.entries()) { expect(value).toBeCloseTo(EXPECTED[name]![index]!, 12); } }); it.each(Object.keys(EXPECTED))('%s is anchored at both ends', (name): void => { const fn = (Easing as unknown as Record number>)[name]!; expect(fn(0)).toBeCloseTo(0, 12); expect(fn(1)).toBeCloseTo(1, 12); }); it.each(Object.keys(EXPECTED))('%s does not mutate beyond its return value', (name): void => { const fn = (Easing as unknown as Record number>)[name]!; for (const k of SAMPLE_POINTS) { expect(fn(k)).toBe(fn(k)); } }); });