const { tuzCompress } = require("../tuz.js"); const { execFileSync } = require("child_process"); let rnd = 12345; const rand = () => (rnd = (rnd * 1103515245 + 12345) & 0x7fffffff) & 0xff; const cases = []; for (const leds of [44, 88, 176]) { cases.push(Array.from({ length: leds * 3 }, (_, i) => [255, 0, 128][i % 3])); cases.push(Array.from({ length: leds * 3 }, (_, i) => (i * 7) & 0xff)); cases.push(Array.from({ length: leds * 3 }, rand)); cases.push(Array.from({ length: leds * 3 }, (_, i) => (Math.floor(i / 30) * 40) & 0xff)); } for (let t = 0; t < 200; t++) { const n = 1 + (rand() * 7) % 700; const alph = 1 + rand() % 6; cases.push(Array.from({ length: n }, () => rand() % alph * 50)); } let ok = 0; for (const c of cases) { const code = Buffer.from(tuzCompress(c)); const out = execFileSync(require("path").join(__dirname, "..", "tuzd.exe"), [String(c.length)], { input: code }); if (Buffer.compare(out, Buffer.from(c)) !== 0) { console.log("MISMATCH len", c.length); process.exit(1); } ok++; } const solid = tuzCompress(Array.from({ length: 132 }, (_, i) => [128, 0, 255][i % 3])); console.log(`${ok}/${cases.length} round-trips ok; solid 44 LEDs -> ${solid.length} bytes`);