UNPKG

@ginden/blinkstick-v2

Version:
42 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const morph_many_1 = require("./morph-many"); const tsafe_1 = require("tsafe"); function collapseRgb([r, g, b]) { (0, tsafe_1.assert)(r === g); (0, tsafe_1.assert)(g === b); return r; } (0, vitest_1.describe)('morphMany', () => { (0, vitest_1.it)('yields correct number of frames and colors for custom steps', () => { const tuples = [ [0, 0, 0], [200, 200, 200], [100, 100, 100], ]; const frames = Array.from((0, morph_many_1.morphMany)(tuples, 1000, 10)); (0, vitest_1.expect)(frames.map((f) => collapseRgb(f.rgb))).toEqual([ 0, 50, 100, 150, 200, 200, 175, 150, 125, 100, ]); for (const frame of frames) { (0, vitest_1.expect)(frame.duration).toBe(100); } }); (0, vitest_1.it)('takes as much time as it should', () => { const tuples = [ [0, 0, 0], [255, 0, 0], [0, 255, 0], [0, 0, 255], [255, 255, 0], [255, 0, 255], [0, 255, 255], ]; const frames = Array.from((0, morph_many_1.morphMany)(tuples, 5000)); const totalDuration = frames.reduce((acc, frame) => acc + frame.duration, 0); (0, vitest_1.expect)(totalDuration).below(5000 * 1.05); (0, vitest_1.expect)(totalDuration).above(5000 * 0.95); }); }); //# sourceMappingURL=morph-many.spec.js.map