UNPKG

@ginden/blinkstick-v2

Version:
38 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const index_1 = require("../../index"); const index_2 = require("../../index"); const iterate_1 = require("./iterate"); (0, vitest_1.describe)(index_1.wave.name, () => { (0, vitest_1.it)('throws if ledCount <= 0', () => { (0, vitest_1.expect)(() => (0, index_1.wave)([], { ledCount: 0, lagMs: 100 })).toThrowError('ledCount must be greater than 0'); }); (0, vitest_1.it)('throws if lagMs < 0', () => { (0, vitest_1.expect)(() => (0, index_1.wave)([], { ledCount: 1, lagMs: -1 })).toThrowError('lagMs must be greater than or equal to 0'); }); const frameDurations = Array.from({ length: 3 }, () => (50 + Math.random() * 1000) | 0).sort((a, b) => a - b); const lags = Array.from({ length: 3 }, () => (10 + Math.random() * Math.random() * 300) | 0).sort((a, b) => a - b); for (const ledCount of [2, 4, 8, 16]) { for (const frameDuration of frameDurations) { for (const lagMs of lags) (0, vitest_1.it)(`Correctly applies wave effect (ledCount=${ledCount}, frameDuration=${frameDuration}, lagMs=${lagMs})`, async () => { const animation = [ new index_2.SimpleFrame([255, 0, 0], frameDuration), new index_2.SimpleFrame([0, 0, 0], frameDuration), ]; const options = { ledCount, lagMs, fillWith: [0, 0, 0] }; const frames = await (0, iterate_1.asyncCollect)((0, index_1.wave)(animation, options)); for (const f of frames) { (0, vitest_1.expect)(f).toBeInstanceOf(index_1.ComplexFrame); (0, vitest_1.expect)(f.colors).toHaveLength(ledCount); } const totalDuration = frames.reduce((acc, frame) => acc + frame.duration, 0); // 200 ms for the animation + but X th animation frame starts with delay of (x-1) * 50 ms (0, vitest_1.expect)(totalDuration).toEqual(2 * frameDuration + lagMs * (ledCount - 1)); (0, vitest_1.expect)(frames[0].colors).toEqual([[255, 0, 0], ...Array(ledCount - 1).fill([0, 0, 0])]); }); } } }); //# sourceMappingURL=wave.spec.js.map