UNPKG

@ginden/blinkstick-v2

Version:
58 lines 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const morph_complex_1 = require("./morph-complex"); const simple_frame_1 = require("../frame/simple-frame"); const iterate_1 = require("../helpers/iterate"); const complex_frame_1 = require("../frame/complex-frame"); (0, vitest_1.describe)('morphComplex', () => { const blackFrame = simple_frame_1.SimpleFrame.colorAndDuration('black', 100); const whiteFrame = simple_frame_1.SimpleFrame.colorAndDuration('white', 100); (0, vitest_1.it)('throws if steps <= 0', () => { (0, vitest_1.expect)(() => (0, morph_complex_1.morphComplex)([blackFrame], [whiteFrame], 100, 0)).toThrowError(); }); (0, vitest_1.it)('yields correct frames and colors for SimpleFrames', async () => { const frames = await (0, iterate_1.asyncCollect)((0, morph_complex_1.morphComplex)([blackFrame], [whiteFrame], 100, 5)); // This one passes (0, vitest_1.expect)(frames.map((f) => f.rgb[0])).toEqual([0, 42, 85, 127, 170, 212, 255]); // This one fails with frames.length = 9 (0, vitest_1.expect)(frames).toHaveLength(7); }); (0, vitest_1.it)(`yields correct number of frames and colors for ComplexFrames`, async () => { const complexFrame1 = new complex_frame_1.ComplexFrame([ [0, 0, 0], [240, 0, 0], ], 100); const complexFrame2 = new complex_frame_1.ComplexFrame([ [240, 0, 0], [0, 0, 0], ], 100); const frames = await (0, iterate_1.asyncCollect)((0, morph_complex_1.morphComplex)([complexFrame1], [complexFrame2], 100, 1)); (0, vitest_1.expect)(frames).toHaveLength(3); }); }); (0, vitest_1.describe)(morph_complex_1.morphBetweenComplexFrames.name, () => { (0, vitest_1.it)('morphs between two complex frames', () => { const complexFrame1 = new complex_frame_1.ComplexFrame([ [0, 0, 0], [240, 0, 0], ], 100); const complexFrame2 = new complex_frame_1.ComplexFrame([ [240, 0, 0], [0, 0, 0], ], 100); const frames = [...(0, morph_complex_1.morphBetweenComplexFrames)(complexFrame1, complexFrame2, 100, 2)]; (0, vitest_1.expect)(frames).toHaveLength(2); (0, vitest_1.expect)(frames[0].colors).toEqual([ [80, 0, 0], [160, 0, 0], ]); (0, vitest_1.expect)(frames[0].duration).toEqual(50); (0, vitest_1.expect)(frames[1].colors).toEqual([ [160, 0, 0], [80, 0, 0], ]); (0, vitest_1.expect)(frames[1].duration).toEqual(50); }); }); //# sourceMappingURL=morph-complex.spec.js.map